/* 断开回调:标记为未连接。是否自动重连交由上层决定 */
static void ln_ws_on_close(int client)
{
- (void)client;
printf("WebSocketClientConstructor [LN][WS] ln_ws_on_close %d\r\n",client);
// 在断开回调触发时,将关闭状态设置为成功
if(g_ws_close_status==WS_CLOSE_NOT_EXECUTED)
{
// int ret = WebSocketClientClose(g_ws_client_fd);
-
+
}
g_ws_client_fd=-1;
}
}
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) {
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;