From 5a850813c7f5e55e9cbe42206c061d43991baa53 Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Thu, 27 Sep 2018 09:17:32 +0800 Subject: [PATCH] fix(lwip): Fix UDP sync no clear cache when close socket. --- .../lwip/apps/multi-threads/sockets_mt.c | 4 +++ components/lwip/lwip/src/api/sockets.c | 6 +++++ .../lwip/port/esp8266/freertos/udp_sync.c | 26 ++++++++++++++++++- .../lwip/port/esp8266/include/udp_sync.h | 5 ++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/components/lwip/apps/multi-threads/sockets_mt.c b/components/lwip/apps/multi-threads/sockets_mt.c index 0724956a..abf8c611 100644 --- a/components/lwip/apps/multi-threads/sockets_mt.c +++ b/components/lwip/apps/multi-threads/sockets_mt.c @@ -757,6 +757,10 @@ int lwip_close(int s) { int ret; +#if ESP_UDP && LWIP_NETIF_TX_SINGLE_PBUF + udp_sync_close(s); +#endif + _sock_set_open(s, 0); lwip_sync_mt(s, SHUT_RDWR); diff --git a/components/lwip/lwip/src/api/sockets.c b/components/lwip/lwip/src/api/sockets.c index b7632489..25398343 100644 --- a/components/lwip/lwip/src/api/sockets.c +++ b/components/lwip/lwip/src/api/sockets.c @@ -629,6 +629,12 @@ lwip_close(int s) lwip_socket_drop_registered_memberships(s); #endif /* LWIP_IGMP */ +#ifndef SOCKETS_MT +#if ESP_UDP && LWIP_NETIF_TX_SINGLE_PBUF + udp_sync_close(s); +#endif +#endif + err = netconn_delete(sock->conn); if (err != ERR_OK) { sock_set_errno(sock, err_to_errno(err)); diff --git a/components/lwip/port/esp8266/freertos/udp_sync.c b/components/lwip/port/esp8266/freertos/udp_sync.c index 4a4039f3..ba4ba1e6 100644 --- a/components/lwip/port/esp8266/freertos/udp_sync.c +++ b/components/lwip/port/esp8266/freertos/udp_sync.c @@ -195,7 +195,31 @@ void udp_sync_trigger(void) if (!s_udp_sync_num) return ; - tcpip_callback_with_block((tcpip_callback_fn)udp_sync_trigger_null, NULL, 0); + tcpip_callback_with_block(udp_sync_trigger_null, NULL, 0); +} + +/* + * @brief close and clear the udp sync + */ +static void udp_sync_do_close(void *p) +{ + int s = (int)p; + + if (s_udp_sync[s].msg) { + ESP_LOGD(TAG, "UDP sync close socket %d", s); + s_udp_sync[s].msg = NULL; + s_udp_sync[s].retry = 0; + s_udp_sync[s].ret = ERR_OK; + s_udp_sync_num--; + } +} + +/** + * @brief close the udp sync before close the socket + */ +void udp_sync_close(int s) +{ + tcpip_callback_with_block(udp_sync_do_close, (void *)s, 1); } #endif /* ESP_UDP */ diff --git a/components/lwip/port/esp8266/include/udp_sync.h b/components/lwip/port/esp8266/include/udp_sync.h index 055361e3..a29a3586 100644 --- a/components/lwip/port/esp8266/include/udp_sync.h +++ b/components/lwip/port/esp8266/include/udp_sync.h @@ -57,6 +57,11 @@ void udp_sync_proc(void); */ void udp_sync_trigger(void); +/** + * @brief close the udp sync before close the socket + */ +void udp_sync_close(int s); + #ifdef __cplusplus } #endif