/* Shut down the UDP and network stuff */ bool netShutdown(NetPath *netPath) { struct ip_addr multicastAaddr; DBG("netShutdown\n"); /* leave multicast group */ multicastAaddr.addr = netPath->multicastAddr; igmp_leavegroup(IP_ADDR_ANY, &multicastAaddr); /* Disconnect and close the Event UDP interface */ if (netPath->eventPcb) { udp_disconnect(netPath->eventPcb); udp_remove(netPath->eventPcb); netPath->eventPcb = NULL; } /* Disconnect and close the General UDP interface */ if (netPath->generalPcb) { udp_disconnect(netPath->generalPcb); udp_remove(netPath->generalPcb); netPath->generalPcb = NULL; } /* Clear the network addresses. */ netPath->multicastAddr = 0; netPath->unicastAddr = 0; /* Return a success code. */ return TRUE; }
/* shut down the UDP stuff */ Boolean netShutdown(NetPath *netPath) { /* Disconnect and close the Event UDP interface */ if(netPath->eventPcb) { udp_disconnect(netPath->eventPcb); udp_remove(netPath->eventPcb); } /* Disconnect and close the General UDP interface */ if(netPath->generalPcb) { udp_disconnect(netPath->generalPcb); udp_remove(netPath->generalPcb); } /* Free up the Event and General Tx PBUFs. */ if(netPath->eventTxBuf) { pbuf_free(netPath->eventTxBuf); } if(netPath->generalTxBuf) { pbuf_free(netPath->generalTxBuf); } /* Clear the network addresses. */ netPath->multicastAddr = 0; netPath->unicastAddr = 0; /* Return a success code. */ return TRUE; }
/** * New proxied UDP conversation created. * Global callback for udp_proxy_accept(). */ static void pxudp_pcb_accept(void *arg, struct udp_pcb *newpcb, struct pbuf *p, ip_addr_t *addr, u16_t port) { struct pxudp *pxudp; ipX_addr_t dst_addr; int mapping; int sdom; SOCKET sock; LWIP_ASSERT1(newpcb != NULL); LWIP_ASSERT1(p != NULL); LWIP_UNUSED_ARG(arg); pxudp = pxudp_allocate(); if (pxudp == NULL) { DPRINTF(("pxudp_allocate: failed\n")); udp_remove(newpcb); pbuf_free(p); return; } sdom = PCB_ISIPV6(newpcb) ? PF_INET6 : PF_INET; mapping = pxremap_outbound_ipX(PCB_ISIPV6(newpcb), &dst_addr, &newpcb->local_ip); #if 0 /* XXX: DNS IPv6->IPv4 remapping hack */ if (mapping == PXREMAP_MAPPED && newpcb->local_port == 53 && PCB_ISIPV6(newpcb)) { /* * "Remap" DNS over IPv6 to IPv4 since Ubuntu dnsmasq does not * listen on IPv6. */ sdom = PF_INET; ipX_addr_set_loopback(0, &dst_addr); } #endif /* DNS IPv6->IPv4 remapping hack */ sock = proxy_connected_socket(sdom, SOCK_DGRAM, &dst_addr, newpcb->local_port); if (sock == INVALID_SOCKET) { udp_remove(newpcb); pbuf_free(p); return; } pxudp->sock = sock; pxudp->pcb = newpcb; udp_recv(newpcb, pxudp_pcb_recv, pxudp); pxudp->pmhdl.callback = pxudp_pmgr_pump; pxudp_chan_send(POLLMGR_CHAN_PXUDP_ADD, pxudp); /* dispatch directly instead of calling pxudp_pcb_recv() */ pxudp_pcb_forward_outbound(pxudp, p, addr, port); }
err_t mdns_responder_init(const struct mdns_service *services, int num_services, const char *txt_records[]) { err_t ret; memset(&mdns_state, 0, sizeof(mdns_state)); mdns_state.netif = &gs_net_if; setup_hostnames(&mdns_state, &gs_net_if); setup_txt_records(&mdns_state, txt_records); mdns_state.services = services; mdns_state.num_services = num_services; struct ip_addr ipgroup; IP4_ADDR(&ipgroup, 224, 0, 0, 251); mdns_state.sendpcb = udp_new(); if (mdns_state.sendpcb == NULL) return ERR_MEM; struct udp_pcb *pcb = udp_new(); if (pcb == NULL) { udp_remove(mdns_state.sendpcb); return ERR_MEM; } if ((ret = igmp_joingroup(IP_ADDR_ANY, &ipgroup)) != ERR_OK) return ret; ip_set_option(pcb, SOF_REUSEADDR); ip_set_option(mdns_state.sendpcb, SOF_REUSEADDR); if ((ret = udp_bind(pcb, IP_ADDR_ANY, MDNS_PORT)) != ERR_OK) goto error_exit; udp_recv(pcb, recv, &mdns_state); if ((ret = udp_bind(mdns_state.sendpcb, 0, MDNS_PORT)) != ERR_OK) goto error_exit; if ((ret = udp_connect(mdns_state.sendpcb, &ipgroup, MDNS_PORT)) != ERR_OK) goto error_exit; return ERR_OK; error_exit: udp_remove(pcb); udp_remove(mdns_state.sendpcb); return ret; }
void ESP8266NetBIOS::end() { if(_pcb != NULL) { udp_remove(_pcb); _pcb = NULL; } }
/****************************************************************************** * FunctionName : udp_test_port_init * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR udp_test_port_init(uint16 portn) { struct udp_pcb *pcb; #if DEBUGSOO > 0 os_printf("\nUDP Test port %d init... ", portn); #endif pcb = udp_new(); if(pcb != NULL) { err_t err = udp_bind(pcb, IP_ADDR_ANY, portn); if(err != ERR_OK) { #if DEBUGSOO > 0 os_printf("Error bind\n"); #endif udp_remove(pcb); return; }; udp_recv(pcb, udp_test_port_recv, pcb); } else { #if DEBUGSOO > 0 os_printf("Error mem\n"); #endif } #if DEBUGSOO > 0 os_printf("Ok\n"); #endif }
/** * @brief Initialize the server application. * @param None * @retval None */ void udp_echoserver_init(void) { struct udp_pcb *upcb; err_t err; /* Create a new UDP control block */ upcb = udp_new(); if (upcb) { /* Bind the upcb to the UDP_PORT port */ /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */ err = udp_bind(upcb, IP_ADDR_ANY, UDP_SERVER_PORT); if(err == ERR_OK) { /* Set a receive callback for the upcb */ udp_recv(upcb, udp_echoserver_receive_callback, NULL); } else { udp_remove(upcb); } } }
int init_transport(struct ip_addr server) { struct pbuf *pbuf; udp_cnx = udp_new(); udp_recv(udp_cnx, time_recv, (void*) L4_Myself().raw); udp_bind(udp_cnx, IP_ADDR_ANY, NFS_LOCAL_PORT); udp_connect(udp_cnx, &server, 37 /* Time port */); do { pbuf = pbuf_alloc(PBUF_TRANSPORT, UDP_PAYLOAD, PBUF_RAM); udp_send(udp_cnx, pbuf); sos_usleep(100); pbuf_free(pbuf); } while (time_of_day == 0); udp_remove(udp_cnx); cur_xid = time_of_day * 10000; /* Generate a randomish xid */ udp_cnx = udp_new(); udp_recv(udp_cnx, my_recv, NULL); udp_connect(udp_cnx, &server, 0); udp_bind(udp_cnx, IP_ADDR_ANY, NFS_LOCAL_PORT); return 0; }
void mg_if_destroy_conn(struct mg_connection *nc) { int i; if (nc->sock != INVALID_SOCKET) { struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock; if (!(nc->flags & MG_F_UDP)) { struct tcp_pcb *tpcb = cs->pcb.tcp; if (tpcb != NULL) { tcp_arg(tpcb, NULL); DBG(("%p tcp_close %p", nc, tpcb)); tcp_arg(tpcb, NULL); tcp_close(tpcb); } while (cs->rx_chain != NULL) { struct pbuf *seg = cs->rx_chain; cs->rx_chain = pbuf_dechain(cs->rx_chain); pbuf_free(seg); } } else { struct udp_pcb *upcb = cs->pcb.udp; if (upcb != NULL) { DBG(("%p udp_remove %p", nc, upcb)); udp_remove(upcb); } } memset(cs, 0, sizeof(*cs)); free(cs); nc->sock = INVALID_SOCKET; } /* Walk the queue and null-out further signals for this conn. */ for (i = 0; i < MG_TASK_QUEUE_LEN; i++) { if ((struct mg_connection *) s_mg_task_queue[i].par == nc) { s_mg_task_queue[i].sig = MG_SIG_TOMBSTONE; } } }
// Lua: client/server/socket:close() int net_close( lua_State *L ) { lnet_userdata *ud = net_get_udata(L); if (!ud) return luaL_error(L, "invalid user data"); if (ud->pcb) { switch (ud->type) { case TYPE_TCP_CLIENT: if (ERR_OK != tcp_close(ud->tcp_pcb)) { tcp_arg(ud->tcp_pcb, NULL); tcp_abort(ud->tcp_pcb); } ud->tcp_pcb = NULL; break; case TYPE_TCP_SERVER: tcp_close(ud->tcp_pcb); ud->tcp_pcb = NULL; break; case TYPE_UDP_SOCKET: udp_remove(ud->udp_pcb); ud->udp_pcb = NULL; break; } } else { return luaL_error(L, "not connected"); } if (ud->type == TYPE_TCP_SERVER || (ud->pcb == NULL && ud->client.wait_dns == 0)) { lua_gc(L, LUA_GCSTOP, 0); luaL_unref(L, LUA_REGISTRYINDEX, ud->self_ref); ud->self_ref = LUA_NOREF; lua_gc(L, LUA_GCRESTART, 0); } return 0; }
/** * Clean up and free the ttcp structure */ static void ard_tcp_destroy(struct ttcp* ttcp) { err_t err = ERR_OK; DUMP_TCP_STATE(ttcp); if (getSock(ttcp)==-1) WARN("ttcp already deallocated!\n"); if (ttcp->tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); //TEMPORAQARY //err = tcp_close(ttcp->tpcb); INFO_TCP("Closing tpcb: state:0x%x err:%d\n", ttcp->tpcb->state, err); } if (ttcp->lpcb) { tcp_arg(ttcp->lpcb, NULL); tcp_accept(ttcp->lpcb, NULL); err = tcp_close(ttcp->lpcb); INFO_TCP("Closing lpcb: state:0x%x err:%d\n", ttcp->lpcb->state, err); } if (ttcp->upcb) { udp_disconnect(ttcp->upcb); udp_remove(ttcp->upcb); } if (ttcp->payload) free(ttcp->payload); free(ttcp); }
err_t simple_discovery_init(struct netif *netif) { err_t ret; struct udp_pcb *pcb = udp_new(); if (pcb == NULL) return ERR_MEM; #if LWIP_IGMP struct ip_addr ipgroup; IP4_ADDR(&ipgroup, 224, 0, 0, 178); if ((ret = igmp_joingroup(IP_ADDR_ANY, &ipgroup)) != ERR_OK) goto error_exit; #endif if ((ret = udp_bind(pcb, IP_ADDR_ANY, SIMPLE_DISCOVERY_PORT)) != ERR_OK) goto error_exit; udp_recv(pcb, recv, netif); return ERR_OK; error_exit: udp_remove(pcb); return ret; }
/** @ingroup tftp * Deinitialize ("turn off") TFTP client/server. */ void tftp_cleanup(void) { LWIP_ASSERT("Cleanup called on non-initialized TFTP", tftp_state.upcb != NULL); udp_remove(tftp_state.upcb); close_handle(); memset(&tftp_state, 0, sizeof(tftp_state)); }
/** * Initialize TFTP client/server. * @param mode TFTP mode (client/server) * @param ctx TFTP callback struct */ err_t tftp_init_common(u8_t mode, const struct tftp_context *ctx) { err_t ret; /* LWIP_ASSERT_CORE_LOCKED(); is checked by udp_new() */ struct udp_pcb *pcb = udp_new_ip_type(IPADDR_TYPE_ANY); if (pcb == NULL) { return ERR_MEM; } ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT); if (ret != ERR_OK) { udp_remove(pcb); return ret; } tftp_state.handle = NULL; tftp_state.port = 0; tftp_state.ctx = ctx; tftp_state.timer = 0; tftp_state.last_data = NULL; tftp_state.upcb = pcb; tftp_state.tftp_mode = mode; udp_recv(pcb, recv, NULL); return ERR_OK; }
err_t tftp_init(const struct tftp_context *ctx) { err_t ret; struct udp_pcb *pcb = udp_new(); if (pcb == NULL) return ERR_MEM; if ((ret = udp_bind(pcb, IP_ADDR_ANY, TFTP_PORT)) != ERR_OK) goto error_exit; tftp_state.handle = NULL; tftp_state.port = 0; tftp_state.ctx = ctx; tftp_state.timer = 0; tftp_state.last_data = NULL; udp_recv(pcb, recv, &tftp_state); return ERR_OK; error_exit: udp_remove(pcb); return ret; }
/** * Clean up and free the ttcp structure */ static void ard_tcp_abort(struct ttcp* ttcp) { INFO_TCP("Abort ttcb:%p tpcb:%p lpcb:%p\n", ttcp, ttcp->tpcb, ttcp->lpcb); if (ttcp->tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); tcp_abort(ttcp->tpcb); } if (ttcp->lpcb) { tcp_arg(ttcp->lpcb, NULL); tcp_accept(ttcp->lpcb, NULL); tcp_abort(ttcp->lpcb); } if (ttcp->upcb) { udp_disconnect(ttcp->upcb); udp_remove(ttcp->upcb); } if (ttcp->payload) free(ttcp->payload); free(ttcp); }
/** @ingroup tftp * Initialize TFTP server. * @param ctx TFTP callback struct */ err_t tftp_init(const struct tftp_context *ctx) { err_t ret; struct udp_pcb *pcb = udp_new_ip_type(IPADDR_TYPE_ANY); if (pcb == NULL) { return ERR_MEM; } ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT); if (ret != ERR_OK) { udp_remove(pcb); return ret; } tftp_state.handle = NULL; tftp_state.port = 0; tftp_state.ctx = ctx; tftp_state.timer = 0; tftp_state.last_data = NULL; tftp_state.upcb = pcb; udp_recv(pcb, recv, NULL); return ERR_OK; }
STATIC mp_obj_t lwip_socket_close(mp_obj_t self_in) { lwip_socket_obj_t *socket = self_in; bool socket_is_listener = false; if (socket->pcb.tcp == NULL) { return mp_const_none; } switch (socket->type) { case MOD_NETWORK_SOCK_STREAM: { if (socket->pcb.tcp->state == LISTEN) { socket_is_listener = true; } if (tcp_close(socket->pcb.tcp) != ERR_OK) { tcp_abort(socket->pcb.tcp); } break; } case MOD_NETWORK_SOCK_DGRAM: udp_remove(socket->pcb.udp); break; //case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break; } socket->pcb.tcp = NULL; socket->state = _ERR_BADF; if (socket->incoming.pbuf != NULL) { if (!socket_is_listener) { pbuf_free(socket->incoming.pbuf); } else { tcp_abort(socket->incoming.connection); } socket->incoming.pbuf = NULL; } return mp_const_none; }
int udp_echo_server_init(void) { int r; uint16_t bind_port = 7; //don't use htons() (don't know why...) //create a new UDP PCB struct udp_pcb *pcb = udp_new(); //UDP connection data if (pcb == NULL) { return ERR_MEM; } //bind it to every IP of every interface and define a specific port to //bind to r = udp_bind(pcb, IP_ADDR_ANY, bind_port); if(r != ERR_OK) { udp_remove(pcb); return(r); } printf("udp_echo_server_init(): bound.\n"); //install a callback for received datagrams udp_recv(pcb, echo_recv_handler, 0 /*client data, arg in callback*/); printf("installed receive callback.\n"); struct pbuf * test_pbuf = pbuf_alloc(PBUF_RAW, 256, PBUF_RAM); memcpy(test_pbuf->payload, "DDDDDDDDDUUUUUUUUU", 16); netif_default->linkoutput(netif_default, test_pbuf); return (0); }
/** * Clean up and free the ttcp structure */ static void ttcp_destroy(struct ttcp* ttcp) { if (ttcp->tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); tcp_close(ttcp->tpcb); } if (ttcp->lpcb) { tcp_arg(ttcp->lpcb, NULL); tcp_accept(ttcp->lpcb, NULL); tcp_close(ttcp->lpcb); } if (ttcp->upcb) { udp_disconnect(ttcp->upcb); udp_remove(ttcp->upcb); } if (ttcp->payload) free(ttcp->payload); timer_cancel_timeout(ttcp->tid); free(ttcp); }
void ICACHE_FLASH_ATTR dhcps_start(struct ip_info *info) { struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01); if(apnetif->dhcps_pcb != NULL) { udp_remove(apnetif->dhcps_pcb); } pcb_dhcps = udp_new(); if (pcb_dhcps == NULL || info ==NULL) { os_printf("dhcps_start(): could not obtain pcb\n"); } apnetif->dhcps_pcb = pcb_dhcps; IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255); server_address = info->ip; wifi_softap_init_dhcps_lease(server_address.addr); client_address_plus.addr = dhcps_lease.start_ip.addr; udp_bind(pcb_dhcps, IP_ADDR_ANY, DHCPS_SERVER_PORT); udp_recv(pcb_dhcps, handle_dhcp, NULL); #if DHCPS_DEBUG os_printf("dhcps:dhcps_start->udp_recv function Set a receive callback handle_dhcp for UDP_PCB pcb_dhcps\n"); #endif }
STATIC mp_obj_t lwip_socket_close(mp_obj_t self_in) { lwip_socket_obj_t *socket = self_in; bool socket_is_listener = false; if (socket->pcb == NULL) { return mp_const_none; } switch (socket->type) { case MOD_NETWORK_SOCK_STREAM: { if (((struct tcp_pcb*)socket->pcb)->state == LISTEN) { socket_is_listener = true; } if (tcp_close((struct tcp_pcb*)socket->pcb) != ERR_OK) { tcp_abort((struct tcp_pcb*)socket->pcb); } break; } case MOD_NETWORK_SOCK_DGRAM: udp_remove((struct udp_pcb*)socket->pcb); break; //case MOD_NETWORK_SOCK_RAW: raw_remove((struct raw_pcb*)socket->pcb); break; } socket->pcb = NULL; socket->connected = -16; // EBADF if (socket->incoming != NULL) { if (!socket_is_listener) { pbuf_free((struct pbuf*)socket->incoming); } else { tcp_abort((struct tcp_pcb*)socket->incoming); } socket->incoming = NULL; } return mp_const_none; }
void ICACHE_FLASH_ATTR dhcps_stop(void) { struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01); udp_disconnect(pcb_dhcps); dhcps_lease_flag = true; if(apnetif->dhcps_pcb != NULL) { udp_remove(apnetif->dhcps_pcb); apnetif->dhcps_pcb = NULL; } //udp_remove(pcb_dhcps); list_node *pnode = NULL; list_node *pback_node = NULL; pnode = plist; while (pnode != NULL) { pback_node = pnode; pnode = pback_node->pnext; node_remove_from_list(&plist, pback_node); os_free(pback_node->pnode); pback_node->pnode = NULL; os_free(pback_node); pback_node = NULL; } }
/****************************************************************************** * FunctionName : espconn_udp_server * Description : Initialize the server: set up a PCB and bind it to the port * Parameters : pespconn -- the espconn used to build server * Returns : none *******************************************************************************/ sint8 ICACHE_FLASH_ATTR espconn_udp_server(struct espconn *pespconn) { struct udp_pcb *upcb = NULL; espconn_msg *pserver = NULL; upcb = udp_new(); if (upcb == NULL) { return ESPCONN_MEM; } else { pserver = (espconn_msg *)os_zalloc(sizeof(espconn_msg)); if (pserver == NULL) { udp_remove(upcb); return ESPCONN_MEM; } pserver->pcommon.pcb = upcb; pserver->pespconn = pespconn; espconn_list_creat(&plink_active, pserver); udp_bind(upcb, IP_ADDR_ANY, pserver->pespconn->proto.udp->local_port); udp_recv(upcb, espconn_udp_recv, (void *)pserver); return ESPCONN_OK; } }
/**@brief Creates port as requested in p_port. * * @details Creates port as requested in p_port. * * @param[in] index Index to the m_port_table where entry of the port created is to be made. * @param[in] p_port Port information to be created. * * @retval NRF_SUCCESS Indicates if port was created successfully, else an an error code * indicating reason for failure. */ static uint32_t port_create(uint32_t index, coap_port_t * p_port) { err_t err = NRF_ERROR_NO_MEM; ip6_addr_t any_addr; struct udp_pcb * p_socket = m_port_table[index].p_socket; ip6_addr_set_any(&any_addr); //Request new socket creation. p_socket = udp_new(); if (NULL != p_socket) { // Bind the socket to the local port. err = udp_bind(p_socket, &any_addr, p_port->port_number); if (err == ERR_OK) { //Register data receive callback. udp_recv(p_socket, udp_recv_data_handler, &m_port_table[index]); //All procedure with respect to port creation succeeded, make entry in the table. m_port_table[index].port_number = p_port->port_number; m_port_table[index].p_socket = p_socket; } else { //Not all procedures succeeded with allocated socket, hence free it. err = NRF_ERROR_INVALID_PARAM; udp_remove(p_socket); } } return err; }
/* * FIXME: currently we associate a connection with a thread (and an * upcall thread), which is restrictive. */ net_connection_t net_create_udp_connection(spdid_t spdid, long evt_id) { struct udp_pcb *up; struct intern_connection *ic; net_connection_t ret; up = udp_new(); if (NULL == up) { prints("Could not allocate udp connection"); ret = -ENOMEM; goto err; } ic = net_conn_alloc(UDP, cos_get_thd_id(), evt_id); if (NULL == ic) { prints("Could not allocate internal connection"); ret = -ENOMEM; goto udp_err; } ic->spdid = spdid; ic->conn.up = up; udp_recv(up, cos_net_lwip_udp_recv, (void*)ic); return net_conn_get_opaque(ic); udp_err: udp_remove(up); err: return ret; }
/* * 函数名:updd_Send * 描述 :发送udp数据包 * 输入 :无 * 输出 : 无 * 调用 :外部调用 */ void udpd_Send(void) { struct udp_pcb *UdpPcb; struct ip_addr ipaddr; struct pbuf *p; err_t err = ERR_Mine; //测试用 p = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM); p->payload=(void *)UDPData; UdpPcb = udp_new(); udp_bind(UdpPcb,IP_ADDR_ANY,6000); /* 绑定本地IP 地址 */ IP4_ADDR(&ipaddr,192,168,1,122); err = udp_connect(UdpPcb,&ipaddr,6001); /* 连接远程主机 */ if(err == ERR_OK) { err = ERR_Mine; //测试用 err = udp_send(UdpPcb, p); } udp_disconnect(UdpPcb); pbuf_free(p); udp_remove(UdpPcb); }
/** * Delete the pcb inside a netconn. * Called from netconn_delete. * * @param msg the api_msg_msg pointing to the connection */ void lwip_netconn_do_delconn(struct api_msg_msg *msg) { /* @todo TCP: abort running write/connect? */ if ((msg->conn->state != NETCONN_NONE) && (msg->conn->state != NETCONN_LISTEN) && (msg->conn->state != NETCONN_CONNECT)) { /* this only happens for TCP netconns */ LWIP_ASSERT("NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP", NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP); msg->err = ERR_INPROGRESS; } else { LWIP_ASSERT("blocking connect in progress", (msg->conn->state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn)); /* Drain and delete mboxes */ netconn_drain(msg->conn); if (msg->conn->pcb.tcp != NULL) { switch (NETCONNTYPE_GROUP(msg->conn->type)) { #if LWIP_RAW case NETCONN_RAW: raw_remove(msg->conn->pcb.raw); break; #endif /* LWIP_RAW */ #if LWIP_UDP case NETCONN_UDP: msg->conn->pcb.udp->recv_arg = NULL; udp_remove(msg->conn->pcb.udp); break; #endif /* LWIP_UDP */ #if LWIP_TCP case NETCONN_TCP: LWIP_ASSERT("already writing or closing", msg->conn->current_msg == NULL && msg->conn->write_offset == 0); msg->conn->state = NETCONN_CLOSE; msg->msg.sd.shut = NETCONN_SHUT_RDWR; msg->conn->current_msg = msg; lwip_netconn_do_close_internal(msg->conn); /* API_EVENT is called inside lwip_netconn_do_close_internal, before releasing the application thread, so we can return at this point! */ return; #endif /* LWIP_TCP */ default: break; } msg->conn->pcb.tcp = NULL; } /* tcp netconns don't come here! */ /* @todo: this lets select make the socket readable and writable, which is wrong! errfd instead? */ API_EVENT(msg->conn, NETCONN_EVT_RCVPLUS, 0); API_EVENT(msg->conn, NETCONN_EVT_SENDPLUS, 0); } if (sys_sem_valid(&msg->conn->op_completed)) { sys_sem_signal(&msg->conn->op_completed); } }
/** * Stop this module. */ void sntp_stop(void) { if (sntp_pcb != NULL) { sys_untimeout(sntp_request, NULL); udp_remove(sntp_pcb); sntp_pcb = NULL; } }
static void udp_close_cb(void *ctx_p) { struct socket_t *socket_p = ctx_p; udp_recv(socket_p->pcb_p, NULL, NULL); udp_remove(socket_p->pcb_p); resume_thrd(socket_p->input.cb.thrd_p, 0); }