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

Function netconn_drain

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

* Delete rcvmbox and acceptmbox of a netconn and free the left-over data in * these mboxes * * @param conn the netconn to free * @bytes_drained bytes drained from recvmbox * @accepts_drained pending connections drained from acceptmbox */

Source from the content-addressed store, hash-verified

824 * @accepts_drained pending connections drained from acceptmbox
825 */
826static void
827netconn_drain(struct netconn *conn)
828{
829 void *mem;
830
831 /* This runs when mbox and netconn are marked as closed,
832 so we don't need to lock against rx packets */
833#if LWIP_NETCONN_FULLDUPLEX
834 LWIP_ASSERT("netconn marked closed", conn->flags & NETCONN_FLAG_MBOXINVALID);
835#endif /* LWIP_NETCONN_FULLDUPLEX */
836
837 /* Delete and drain the recvmbox. */
838 if (sys_mbox_valid(&conn->recvmbox)) {
839 while (sys_mbox_tryfetch(&conn->recvmbox, &mem) != SYS_MBOX_EMPTY) {
840#if LWIP_NETCONN_FULLDUPLEX
841 if (!lwip_netconn_is_deallocated_msg(mem))
842#endif /* LWIP_NETCONN_FULLDUPLEX */
843 {
844#if LWIP_TCP
845 if (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP) {
846 err_t err;
847 if (!lwip_netconn_is_err_msg(mem, &err)) {
848 pbuf_free((struct pbuf *)mem);
849 }
850 } else
851#endif /* LWIP_TCP */
852 {
853 netbuf_delete((struct netbuf *)mem);
854 }
855 }
856 }
857 sys_mbox_free(&conn->recvmbox);
858 sys_mbox_set_invalid(&conn->recvmbox);
859 }
860
861 /* Delete and drain the acceptmbox. */
862#if LWIP_TCP
863 if (sys_mbox_valid(&conn->acceptmbox)) {
864 while (sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) {
865#if LWIP_NETCONN_FULLDUPLEX
866 if (!lwip_netconn_is_deallocated_msg(mem))
867#endif /* LWIP_NETCONN_FULLDUPLEX */
868 {
869 err_t err;
870 if (!lwip_netconn_is_err_msg(mem, &err)) {
871 struct netconn *newconn = (struct netconn *)mem;
872 /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */
873 /* pcb might be set to NULL already by err_tcp() */
874 /* drain recvmbox */
875 netconn_drain(newconn);
876 if (newconn->pcb.tcp != NULL) {
877 tcp_abort(newconn->pcb.tcp);
878 newconn->pcb.tcp = NULL;
879 }
880 netconn_free(newconn);
881 }
882 }
883 }

Callers 3

netconn_freeFunction · 0.70
lwip_netconn_do_delconnFunction · 0.70
api_msg.cFile · 0.70

Calls 9

sys_mbox_validFunction · 0.85
lwip_netconn_is_err_msgFunction · 0.85
netbuf_deleteFunction · 0.70
netconn_freeFunction · 0.70
pbuf_freeFunction · 0.50
sys_mbox_freeFunction · 0.50
sys_mbox_set_invalidFunction · 0.50
tcp_abortFunction · 0.50

Tested by

no test coverage detected