fix: abort client close to avoid time-wait reconnect block
This commit is contained in:
+27
-2
@@ -5,6 +5,8 @@
|
||||
#include "queue.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/tcpip.h"
|
||||
|
||||
#include "app_runtime.h"
|
||||
#include "config.h"
|
||||
@@ -14,6 +16,30 @@
|
||||
|
||||
#define TCP_CLIENT_CONNECT_TIMEOUT_MS 5000
|
||||
|
||||
static void tcp_client_abort_and_delete(struct netconn *conn, uint8_t link_index)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
pcb = conn->pcb.tcp;
|
||||
if (pcb != NULL) {
|
||||
LOCK_TCPIP_CORE();
|
||||
pcb = conn->pcb.tcp;
|
||||
if (pcb != NULL) {
|
||||
tcp_abort(pcb);
|
||||
conn->pcb.tcp = NULL;
|
||||
conn->state = NETCONN_NONE;
|
||||
debug_log_printf("[CLI] idx=%u abort-close\r\n", (unsigned int)link_index);
|
||||
}
|
||||
UNLOCK_TCPIP_CORE();
|
||||
}
|
||||
|
||||
netconn_delete(conn);
|
||||
}
|
||||
|
||||
static err_t tcp_client_worker(struct netconn *conn, uint8_t link_index)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
@@ -140,8 +166,7 @@ static void tcp_client_task(uint8_t link_index)
|
||||
}
|
||||
}
|
||||
|
||||
netconn_close(conn);
|
||||
netconn_delete(conn);
|
||||
tcp_client_abort_and_delete(conn, link_index);
|
||||
vTaskDelay(pdMS_TO_TICKS(delay_ms));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user