修改ln ws关闭逻辑
authorhcj <1224667075@qq.com>
Sun, 21 Sep 2025 08:21:16 +0000 (16:21 +0800)
committerhcj <1224667075@qq.com>
Sun, 21 Sep 2025 08:21:16 +0000 (16:21 +0800)
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index da7d709..9d05eeb 100644 (file)
@@ -136,7 +136,6 @@ static void ln_ws_on_error(int client, struct WebSocketErrorResult error)
 /* 断开回调:标记为未连接。是否自动重连交由上层决定 */
 static void ln_ws_on_close(int client)
 {
-    (void)client;
     printf("WebSocketClientConstructor [LN][WS] ln_ws_on_close %d\r\n",client);
     
     // 在断开回调触发时,将关闭状态设置为成功
@@ -151,7 +150,7 @@ static void ln_ws_on_close(int client)
         if(g_ws_close_status==WS_CLOSE_NOT_EXECUTED)
         {
             // int ret = WebSocketClientClose(g_ws_client_fd);
-       
+        
         }
         g_ws_client_fd=-1;
     }
@@ -240,7 +239,22 @@ static void ln_ws_main_thread(void *arg)
         }
         
         if (g_ws_connected == WS_STATE_DISCONNECTED) {
+            if (g_ws_client_fd >= 0) {
+            {
+                if(g_ws_close_status== WS_CLOSE_NOT_EXECUTED)
+                {
+                    printf("[LN][WS] WebSocketClientClose WS_CLOSE_NOT_EXECUTED\n");
+                    ln_ws_close_with_status(g_ws_client_fd);
+                    g_ws_client_fd=-1;
+                    printf("[LN][WS] WebSocketClientClose WS_CLOSE_NOT_EXECUTED end\n");
+
+                }
+            }
+            }
+
             if (g_ws_client_fd < 0) {
+
+               
                 printf("[LN][WS] 开始创建WebSocket客户端...\n");
                 g_ws_client_fd = WebSocketClientConstructor(ln_ws_on_open, ln_ws_on_message, ln_ws_on_error, ln_ws_on_close);
                 if (g_ws_client_fd < 0) {
@@ -865,15 +879,15 @@ int ln_ws_enter_sleep(void)
     printf("[LN][WS] Entering sleep mode\n");
     
     if (!g_ws_running) {
-        printf("[LN][WS] WebSocket service not running, cannot enter sleep\n");
-        return -1;
+    printf("[LN][WS] WebSocket service not running, cannot enter sleep\n");
+    return -1;
     }
     
     // 如果当前有连接,先断开
     if (g_ws_client_fd >= 0) {
         printf("[LN][WS] Disconnecting before entering sleep mode\n");
         ln_ws_close_with_status(g_ws_client_fd);
-    }
+            }
     
     // 设置状态为休眠
     g_ws_connected = WS_STATE_SLEEP;