MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / accept_function

Function accept_function

components/net/lwip/lwip-2.1.2/src/api/api_msg.c:532–599  ·  view source on GitHub ↗

* Accept callback function for TCP netconns. * Allocates a new netconn and posts that to conn->acceptmbox. * * @see tcp.h (struct tcp_pcb_listen.accept) for parameters and return value */

Source from the content-addressed store, hash-verified

530 * @see tcp.h (struct tcp_pcb_listen.accept) for parameters and return value
531 */
532static err_t
533accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
534{
535 struct netconn *newconn;
536 struct netconn *conn = (struct netconn *)arg;
537
538 if (conn == NULL) {
539 return ERR_VAL;
540 }
541 if (!NETCONN_MBOX_VALID(conn, &conn->acceptmbox)) {
542 LWIP_DEBUGF(API_MSG_DEBUG, ("accept_function: acceptmbox already deleted\n"));
543 return ERR_VAL;
544 }
545
546 if (newpcb == NULL) {
547 /* out-of-pcbs during connect: pass on this error to the application */
548 if (sys_mbox_trypost(&conn->acceptmbox, lwip_netconn_err_to_msg(ERR_ABRT)) == ERR_OK) {
549 /* Register event with callback */
550 API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
551 }
552 return ERR_VAL;
553 }
554 LWIP_ASSERT("expect newpcb == NULL or err == ERR_OK", err == ERR_OK);
555 LWIP_UNUSED_ARG(err); /* for LWIP_NOASSERT */
556
557 LWIP_DEBUGF(API_MSG_DEBUG, ("accept_function: newpcb->state: %s\n", tcp_debug_state_str(newpcb->state)));
558
559 /* We have to set the callback here even though
560 * the new socket is unknown. newconn->socket is marked as -1. */
561 newconn = netconn_alloc(conn->type, conn->callback);
562 if (newconn == NULL) {
563 /* outof netconns: pass on this error to the application */
564 if (sys_mbox_trypost(&conn->acceptmbox, lwip_netconn_err_to_msg(ERR_ABRT)) == ERR_OK) {
565 /* Register event with callback */
566 API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
567 }
568 return ERR_MEM;
569 }
570 newconn->pcb.tcp = newpcb;
571 setup_tcp(newconn);
572
573 /* handle backlog counter */
574 tcp_backlog_delayed(newpcb);
575
576 if (sys_mbox_trypost(&conn->acceptmbox, newconn) != ERR_OK) {
577 /* When returning != ERR_OK, the pcb is aborted in tcp_process(),
578 so do nothing here! */
579 /* remove all references to this netconn from the pcb */
580 struct tcp_pcb *pcb = newconn->pcb.tcp;
581 tcp_arg(pcb, NULL);
582 tcp_recv(pcb, NULL);
583 tcp_sent(pcb, NULL);
584 tcp_poll(pcb, NULL, 0);
585 tcp_err(pcb, NULL);
586 /* remove reference from to the pcb from this netconn */
587 newconn->pcb.tcp = NULL;
588 /* no need to drain since we know the recvmbox is empty. */
589 sys_mbox_free(&newconn->recvmbox);

Callers

nothing calls this directly

Calls 14

lwip_netconn_err_to_msgFunction · 0.85
netconn_allocFunction · 0.70
setup_tcpFunction · 0.70
netconn_freeFunction · 0.70
sys_mbox_trypostFunction · 0.50
tcp_debug_state_strFunction · 0.50
tcp_backlog_delayedFunction · 0.50
tcp_argFunction · 0.50
tcp_recvFunction · 0.50
tcp_sentFunction · 0.50
tcp_pollFunction · 0.50
tcp_errFunction · 0.50

Tested by

no test coverage detected