回退 socket id close错误造成资源文件错误关闭的修复。当下版本不适用这个patch 2984/1 2984/head 2985/target/1
author孙春阳 <snickersun@163.com>
Sun, 28 Dec 2025 04:33:42 +0000 (12:33 +0800)
committer孙春阳 <snickersun@163.com>
Sun, 28 Dec 2025 04:33:42 +0000 (12:33 +0800)
code/sdk/middleware/utils/fs/vfs/nuttx_fs/vfs/operation/fs_close.c
code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/include/lwip/lwipopts_default.h

index 1cc0e67..a261b93 100644 (file)
  * 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;
index 13eae91..e497221 100644 (file)
@@ -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