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

Function netconn_alloc

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

* Create a new netconn (of a specific type) that has a callback function. * The corresponding pcb is NOT created! * * @param t the type of 'connection' to create (@see enum netconn_type) * @param callback a function to call on status changes (RX available, TX'ed) * @return a newly allocated struct netconn or * NULL on memory error */

Source from the content-addressed store, hash-verified

702 * NULL on memory error
703 */
704struct netconn *
705netconn_alloc(enum netconn_type t, netconn_callback callback)
706{
707 struct netconn *conn;
708 int size;
709 u8_t init_flags = 0;
710
711 conn = (struct netconn *)memp_malloc(MEMP_NETCONN);
712 if (conn == NULL) {
713 return NULL;
714 }
715
716 conn->pending_err = ERR_OK;
717 conn->type = t;
718 conn->pcb.tcp = NULL;
719
720 /* If all sizes are the same, every compiler should optimize this switch to nothing */
721 switch (NETCONNTYPE_GROUP(t)) {
722#if LWIP_RAW
723 case NETCONN_RAW:
724 size = DEFAULT_RAW_RECVMBOX_SIZE;
725 break;
726#endif /* LWIP_RAW */
727#if LWIP_UDP
728 case NETCONN_UDP:
729 size = DEFAULT_UDP_RECVMBOX_SIZE;
730#if LWIP_NETBUF_RECVINFO
731 init_flags |= NETCONN_FLAG_PKTINFO;
732#endif /* LWIP_NETBUF_RECVINFO */
733 break;
734#endif /* LWIP_UDP */
735#if LWIP_TCP
736 case NETCONN_TCP:
737 size = DEFAULT_TCP_RECVMBOX_SIZE;
738 break;
739#endif /* LWIP_TCP */
740 default:
741 LWIP_ASSERT("netconn_alloc: undefined netconn_type", 0);
742 goto free_and_return;
743 }
744
745 if (sys_mbox_new(&conn->recvmbox, size) != ERR_OK) {
746 goto free_and_return;
747 }
748#if !LWIP_NETCONN_SEM_PER_THREAD
749 if (sys_sem_new(&conn->op_completed, 0) != ERR_OK) {
750 sys_mbox_free(&conn->recvmbox);
751 goto free_and_return;
752 }
753#endif
754
755#if LWIP_TCP
756 sys_mbox_set_invalid(&conn->acceptmbox);
757#endif
758 conn->state = NETCONN_NONE;
759#if LWIP_SOCKET
760 /* initialize socket to -1 since 0 is a valid socket */
761 conn->socket = -1;

Callers 2

accept_functionFunction · 0.70

Calls 5

sys_mbox_newFunction · 0.50
sys_sem_newFunction · 0.50
sys_mbox_freeFunction · 0.50
sys_mbox_set_invalidFunction · 0.50
memp_freeFunction · 0.50

Tested by

no test coverage detected