api_msg: Support sock close from another thread

Add support for closing the socket from another thread
while is blocked on connection.

Ref IDF-4794
This commit is contained in:
xueyunfei
2019-12-04 16:35:49 +08:00
committed by David Cermak
parent 5f246f5f78
commit 0a9dad958e
2 changed files with 14 additions and 0 deletions
+11
View File
@@ -875,6 +875,9 @@ netconn_drain(struct netconn *conn)
/* Only tcp pcbs have an acceptmbox, so no need to check conn->type */
/* pcb might be set to NULL already by err_tcp() */
/* drain recvmbox */
#if ESP_LWIP
newconn->flags |= NETCONN_FLAG_MBOXINVALID;
#endif /* ESP_LWIP */
netconn_drain(newconn);
if (newconn->pcb.tcp != NULL) {
tcp_abort(newconn->pcb.tcp);
@@ -1120,6 +1123,9 @@ lwip_netconn_do_delconn(void *m)
enum netconn_state state = msg->conn->state;
LWIP_ASSERT("netconn state error", /* this only happens for TCP netconns */
(state == NETCONN_NONE) || (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP));
#if ESP_LWIP
msg->err = ERR_OK;
#endif
#if LWIP_NETCONN_FULLDUPLEX
/* In full duplex mode, blocking write/connect is aborted with ERR_CLSD */
if (state != NETCONN_NONE) {
@@ -1132,6 +1138,9 @@ lwip_netconn_do_delconn(void *m)
msg->conn->current_msg->err = ERR_CLSD;
msg->conn->current_msg = NULL;
msg->conn->state = NETCONN_NONE;
#if ESP_LWIP
msg->err = ERR_INPROGRESS;
#endif
sys_sem_signal(op_completed_sem);
}
}
@@ -1146,9 +1155,11 @@ lwip_netconn_do_delconn(void *m)
} else
#endif /* LWIP_NETCONN_FULLDUPLEX */
{
#if !ESP_LWIP
LWIP_ASSERT("blocking connect in progress",
(state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn));
msg->err = ERR_OK;
#endif /* ESP_LWIP */
#if LWIP_NETCONN_FULLDUPLEX
/* Mark mboxes invalid */
netconn_mark_mbox_invalid(msg->conn);
+3
View File
@@ -83,4 +83,7 @@
/* Check lwip_stats.mem.illegal instead of asserting */
#define LWIP_MEM_ILLEGAL_FREE(msg) /* to nothing */
/* Enable Espressif specific options */
#define ESP_LWIP 1
#endif /* LWIP_HDR_LWIPOPTS_H */