From 4bea67311588c6c992870ac58006deed8e41e979 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Mon, 6 Oct 2025 09:06:43 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8Dtcp=E6=B5=8B=E8=AF=95=E6=97=B6?= =?utf8?q?=E9=97=B4=E5=81=9C=E6=AD=A2=E8=BF=87=E6=97=A9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c b/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c index 0f62ad9cd..482482e1e 100644 --- a/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c +++ b/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c @@ -28,6 +28,7 @@ /* 使用嵌入式环境的简化定义 */ #include "osal_mutex.h" #include "osal_task.h" + #include "osal_timer.h" /* 用于osal_get_jiffies() */ /* 简化的兼容性定义 */ #define TCP_MUTEX_INIT(mutex) osal_mutex_init(&(mutex)) @@ -793,28 +794,16 @@ static void tcp_test_stats_timer_callback(void *arg) /** * @brief 获取当前时间(毫秒) - 导出函数 + * + * 修复说明:监控线程使用osal_msleep(真实时间),工作线程也必须使用真实时间, + * 否则会导致时间不同步,300秒测试可能只跑80多秒就被监控线程停止。 */ uint32_t tcp_test_get_time_ms(void) { #ifdef USE_LWIP_SOCKET - /* 在lwIP环境中尝试使用真实的时间函数 */ - #ifdef OSAL_TIME_AVAILABLE - /* 如果OSAL时间函数可用,使用它 */ - return osal_get_jiffies(); - #else - /* 否则使用简化的时间模拟 */ - static uint32_t start_time = 0; - static uint32_t last_time = 0; - - if (start_time == 0) { - start_time = 1000; /* 从1秒开始 */ - last_time = start_time; - } - - /* 每次调用增加约1-10ms的随机时间 */ - last_time += (rand() % 10 + 1); - return last_time; - #endif + /* 在lwIP环境中直接使用OSAL时间函数 */ + /* osal_get_jiffies()返回系统启动以来的毫秒数,是真实时间 */ + return osal_get_jiffies(); #else /* 在POSIX环境中使用标准gettimeofday */ struct timeval tv; -- 2.17.1