From ae7fe5b689204ec1964e10cf93e960bb540867ac Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sun, 21 Sep 2025 16:21:16 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9ln=20ws=E5=85=B3=E9=97=AD?= =?utf8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../zhihui/leiniao/imsl_ln/ln_api_websocket.c | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c index da7d7094b..9d05eeb62 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c @@ -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; -- 2.17.1