From 2cc0ae61a9d4a68f4d2a90bd3abfb116ac7ef911 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Sun, 28 Dec 2025 12:33:42 +0800 Subject: [PATCH] =?utf8?q?=E5=9B=9E=E9=80=80=20socket=20id=20close?= =?utf8?q?=E9=94=99=E8=AF=AF=E9=80=A0=E6=88=90=E8=B5=84=E6=BA=90=E6=96=87?= =?utf8?q?=E4=BB=B6=E9=94=99=E8=AF=AF=E5=85=B3=E9=97=AD=E7=9A=84=E4=BF=AE?= =?utf8?q?=E5=A4=8D=E3=80=82=E5=BD=93=E4=B8=8B=E7=89=88=E6=9C=AC=E4=B8=8D?= =?utf8?q?=E9=80=82=E7=94=A8=E8=BF=99=E4=B8=AApatch?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fs/vfs/nuttx_fs/vfs/operation/fs_close.c | 39 ++++++++++++------- .../src/include/lwip/lwipopts_default.h | 6 ++- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/code/sdk/middleware/utils/fs/vfs/nuttx_fs/vfs/operation/fs_close.c b/code/sdk/middleware/utils/fs/vfs/nuttx_fs/vfs/operation/fs_close.c index 1cc0e6707..a261b93a9 100644 --- a/code/sdk/middleware/utils/fs/vfs/nuttx_fs/vfs/operation/fs_close.c +++ b/code/sdk/middleware/utils/fs/vfs/nuttx_fs/vfs/operation/fs_close.c @@ -78,32 +78,43 @@ * Assumptions: * ****************************************************************************/ -extern int lwip_close(int s); + int close(int fd) { int errcode; int ret; /* Did we get a valid file descriptor? */ - +// printf("CONFIG_NFILE_DESCRIPTORS %d\n", CONFIG_NFILE_DESCRIPTORS); +// printf("CONFIG_NSOCKET_DESCRIPTORS %d\n", CONFIG_NSOCKET_DESCRIPTORS); +// printf("fd %d\n", fd); if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) { /* Close a socket descriptor */ -#ifndef SUPPORT_RECOVERY_DISPLAY -// #if 1 - if (1) + +#if defined(CONFIG_NET_LWIP_SACK) + +#if defined(WEBSOCKET_CLOSE_FIX) + extern int lwip_close(int s); + if(1) + { + ret = lwip_close(fd); +#else + if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) + { + ret = closesocket(fd); +#endif + if (ret < 0) { - ret = lwip_close(fd); - if (ret < 0) - { - errcode = -ret; - goto errout; - } - - return ret; + errcode = -ret; + goto errout; } - else + + return ret; + } + else #endif + { { errcode = EBADF; goto errout; diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h index 13eae916c..e497221a0 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h @@ -243,6 +243,8 @@ extern "C" { #define SIO_UART_FLOW_CTRL UART_FLOW_CTRL_NONE #endif +#define CONFIG_NET_LWIP_SACK 0 //Selective Acknowledgment(选择性确认) 重传指定的包 +#define WEBSOCKET_CLOSE_FIX 0 //解决关闭socket时,导致其他文件被错误关闭问题。 0:不修复 1:修复 暂时还不能使用,代码逻辑先预留。应该在新的1201以后的patch上的库估计才能有用。 #define LWIP_HTTPC_HAVE_FILE_IO 1 /* @@ -426,7 +428,7 @@ extern "C" { #if defined (LOSCFG_CONFIG_MQTT) #ifndef CONFIG_NFILE_DESCRIPTORS -#define CONFIG_NFILE_DESCRIPTORS 128 +#define CONFIG_NFILE_DESCRIPTORS 1 //128 #endif #endif @@ -704,7 +706,7 @@ extern "C" { #endif #ifndef DEFAULT_LWIP_NUM_SOCKETS -#define DEFAULT_LWIP_NUM_SOCKETS 12 +#define DEFAULT_LWIP_NUM_SOCKETS 12 //最大支持12个socket 在socket创建时有效 #endif /* DEFAULT_LWIP_NUM_SOCKETS */ #ifndef MEMP_NUM_PBUF -- 2.17.1