diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c index d733f99..a5bf261 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c @@ -794,39 +794,25 @@ static void json_sensor_callback(const uint8_t *pkg, uint16_t len) *===========================================================================*/ void tcp_json_restart(void) { - PRINT("JSON: === auto-restart (count=%d) ===\n", g_json_restart_count); + PRINT("JSON: === restart (count=%d) ===\n", g_json_restart_count); - /* 1. 关闭数据 socket 和监听 socket */ + /* + * WCHNET 限制: listen socket 关闭后无法在同端口立即重建 (ERR_ISCONN). + * 因此只关数据 socket 断开客户端, listen socket 保持不变. + */ if (g_json_socket_listen != 0xFF) { WCHNET_SocketClose(g_json_socket_listen + 1, TCP_CLOSE_NORMAL); - WCHNET_SocketClose(g_json_socket_listen, TCP_CLOSE_NORMAL); - g_json_socket_listen = 0xFF; } - /* 1.5 WCHNET 资源回收 — SocketClose 是异步的, 需跑一轮 MainTask */ - { - uint8_t _retry; - for (_retry = 0; _retry < 5; _retry++) { - WCHNET_MainTask(); - if (WCHNET_QueryGlobalInt()) { - WCHNET_HandleGlobalInt(); - } - Delay_Ms(10); - } - } - - /* 2. 重置状态 */ + /* 重置应用层状态 — listen socket 继续监听 */ g_json_auth_state = JSON_STATE_WAIT_AUTH; g_json_pwd_retry = 0; g_json_recv_len = 0; g_json_last_comm_ts = 0; g_json_last_connect_ts = 0; - g_json_auth_timer = 0; + g_json_auth_timer = mstick(); // 从此刻重新计时 g_json_lockout_timer = 0; g_json_pending.active = 0; - - /* 3. 重新创建 socket 并监听 */ - tcp_json_srv_init(); } #define TCP_JSON_SRV_INIT_MAX_RETRY 3