} \
} ";
- printf("uapi_start_tts : %s\r\n",jsonString);
+ printf("uapi_stop_tts : %s\r\n",jsonString);
if (send_websocket_message(tts_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
{
tts_server_deinit();
// 清理AI系统资源
- ai_cleanup_resources();
+ // ai_cleanup_resources();
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AI task deinitialized successfully");
// 资源清理函数
void ai_cleanup_resources(void) {
- AI_LOCK();
+ // AI_LOCK();
// 首先关闭所有WebSocket连接
// if (chat_client) {
// ws_queues_deinit_all();
// 清理互斥锁
- if (g_ai_mutex) {
- osMutexDelete(g_ai_mutex);
- g_ai_mutex = NULL;
- }
+ // if (g_ai_mutex) {
+ // osMutexDelete(g_ai_mutex);
+ // g_ai_mutex = NULL;
+ // }
// 清理定时器
// if (g_timer_time_sync) {
// 重置内存使用统计
g_ai_memory_usage = 0;
- AI_UNLOCK();
+ // AI_UNLOCK();
// 最后清理TCP管理器
// tcp_simple_manager_deinit();
/* 给一些时间让TCP完成四次挥手 */
for (int i = 0; i < 50; i++) { /* 最多等待500ms */
- sys_msleep(10);
+ msleep(10);
/* 检查连接是否已经关闭 */
int error = 0;
select_result = select(max_fd + 1, &read_fds, &write_fds, &except_fds, &timeout);
} else {
/* 没有活跃连接,短暂休眠 */
- sys_msleep(100);
+ msleep(100);
continue;
}
continue;
} else {
printf("select错误: %d, 继续运行\n", errno);
- sys_msleep(100);
+ msleep(100);
continue;
}
}
if (FD_ISSET(conn->sockfd, &write_fds) && conn->send_queue_count > 0) {
/* 处理发送队列 */
process_send_queue(conn);
+/* 重置写入失败计数和最后写入时间 */
+ conn->write_fail_count = 0;
+ conn->last_write_attempt = sys_now();
}
else
{
if( conn->send_queue_count > 0)
{
printf("process_send_queue tcp_manager_io_thread send_queue_count:%d sockfd:%d\n",conn->send_queue_count,conn->sockfd);
+
+ /* 检查写入超时 - 长时间无法写入时断开连接 */
+ uint32_t current_time = sys_now();
+ if (conn->last_write_attempt > 0)
+ {
+ uint32_t time_since_last_write = current_time - conn->last_write_attempt;
+
+ if (time_since_last_write > TCP_WRITE_TIMEOUT_MS && conn->send_queue_count>10) {
+ printf("[TCPM_ERR] 写入超时,断开连接: handle=%p, sockfd=%d, 超时时间=%u ms\n",
+ conn->handle, conn->sockfd, time_since_last_write);
+
+ /* 标记连接为错误状态,后续会清理 */
+ conn->state = TCP_STATE_ERROR;
+ conn->write_fail_count++;
+
+ /* 如果连续写入失败次数过多,强制断开连接 */
+ }
+ else {
+ /* 更新写入尝试时间,避免重复检查 */
+ // conn->last_write_attempt = current_time;
+ }
+ }
+ else {
+ /* 首次检测到无法写入,记录时间 */
+ if(conn->last_write_attempt!=0)
+ conn->last_write_attempt = current_time;
+ }
}
}
/* 防止CPU占用过高 */
if (total_connections == 0) {
- sys_msleep(50);
+ msleep(50);
}
}
g_connections[i].send_queue_count = 0;
g_connections[i].retry_count = 0;
g_connections[i].retry_pending = false;
+ g_connections[i].last_write_attempt = 0;
+ g_connections[i].write_fail_count = 0;
+
+
}
/* 初始化DNS状态数组 */
/* 等待线程结束 */
if (g_io_thread != (sys_thread_t)-1) {
- sys_msleep(1000); /* 等待1秒 */
+ msleep(1000); /* 等待1秒 */
}
/* 关闭所有连接 */
conn->send_queue_count = 0;
conn->retry_count = 0;
conn->retry_pending = false;
+ conn->last_write_attempt = 0;
+ conn->write_fail_count = 0;
/* 复制主机名 */
strncpy(conn->remote_ip, host, sizeof(conn->remote_ip) - 1);
return -1;
}
/* 短暂等待后重试 */
- sys_msleep(5); // 增加等待时间到5ms
+ msleep(5); // 增加等待时间到5ms
continue;
} else if (errno == EINPROGRESS) {
/* 连接正在进行中,等待连接完成 */
return -1;
}
/* 等待连接完成 */
- sys_msleep(10); // 等待10ms
+ msleep(10); // 等待10ms
continue;
} else {
printf("tcp_send_and_wait_response: send失败, errno=%d (%s)\n",
conn->send_queue_count = 0;
conn->retry_count = 0;
conn->retry_pending = false;
+ conn->last_write_attempt = 0;
+ conn->write_fail_count = 0;
/* 复制主机名 */
strncpy(conn->remote_ip, host, sizeof(conn->remote_ip) - 1);
#define TCP_MANAGER_RECV_QUEUE_SIZE 16 /* 接收队列大小 */
#define TCP_MANAGER_CMD_QUEUE_SIZE 32 /* 命令队列大小 */
#define TCP_MANAGER_RECV_BUFFER_SIZE 1024 /* 接收缓冲区大小 */
-#define TCP_MANAGER_THREAD_STACK_SIZE 4096 /* 线程栈大小 */
+#define TCP_MANAGER_THREAD_STACK_SIZE (1024*8) /* 线程栈大小 */
#define TCP_MANAGER_THREAD_PRIORITY 5 /* 线程优先级 */
/* 调试等级定义 */
#define TCPM_DBG(fmt, ...) do { if(tcp_get_debug_level() >= TCP_DEBUG_LEVEL_DEBUG) printf("[TCPM_DBG] " fmt "\n", ##__VA_ARGS__); } while(0)
/* 连接参数定义 */
-#define TCP_CONNECT_TIMEOUT_MS 10000
-#define TCP_DNS_TIMEOUT_MS 8000
+#define TCP_CONNECT_TIMEOUT_MS 10000 /* 连接超时时间 (毫秒) */
+#define TCP_DNS_TIMEOUT_MS 8000 /* DNS解析超时时间 (毫秒) */
+#define TCP_WRITE_TIMEOUT_MS 3000 /* 写入超时时间 (毫秒) - 长时间无法写入时断开连接 */
#define TCP_SEND_QUEUE_SIZE 32
#define TCP_SEND_BUFFER_SIZE 2048
#define TCP_CONNECT_RETRY_COUNT 3
uint8_t retry_count;
uint32_t last_retry_time;
bool retry_pending;
+
+ /* 写入超时相关字段 */
+ uint32_t last_write_attempt; /* 最后一次写入尝试时间 */
+ uint32_t write_fail_count; /* 连续写入失败次数 */
} tcp_connection_info_t;
/* 管理器统计信息 */
if (!isDragging_) {
if ((MATH_ABS(dragLen_.x) >= DRAG_LIMIT_X) || (MATH_ABS(dragLen_.y) >= DRAG_LIMIT_Y)) {
- printf("=====PointerInputDevice::DispatchDragStartEvent absx(%d) limitx(%d) absy(%d) limity(%d) \r\n",
- MATH_ABS(dragLen_.x),DRAG_LIMIT_X,
- MATH_ABS(dragLen_.y),DRAG_LIMIT_Y);
+ // printf("=====PointerInputDevice::DispatchDragStartEvent absx(%d) limitx(%d) absy(%d) limity(%d) \r\n",
+ // MATH_ABS(dragLen_.x),DRAG_LIMIT_X,
+ // MATH_ABS(dragLen_.y),DRAG_LIMIT_Y);
if ((touchableView_ != nullptr) && !cancelSent_) {
DispatchCancelEvent();