Parcourir la source

fix bug of check timeout

qiyongzhong0 il y a 4 ans
Parent
commit
225150874f
1 fichiers modifiés avec 3 ajouts et 2 suppressions
  1. 3 2
      ntp/ntp.c

+ 3 - 2
ntp/ntp.c

@@ -22,6 +22,7 @@
  * 2020-07-21     Chenxuan     C++ support
  * 2020-07-21     Chenxuan     C++ support
  * 2021-05-09     Meco Man     remove timezone function
  * 2021-05-09     Meco Man     remove timezone function
  * 2021-07-22     Meco Man     implement workqueue for NTP sync
  * 2021-07-22     Meco Man     implement workqueue for NTP sync
+ * 2021-08-02     qiyongzhong  fix bug of check timeout
  */
  */
 
 
 #include <rtthread.h>
 #include <rtthread.h>
@@ -288,7 +289,7 @@ time_t ntp_get_time(const char *host_name)
     }
     }
 
 
     start = rt_tick_get();
     start = rt_tick_get();
-    while (rt_tick_get() <= start + NTP_GET_TIMEOUT * RT_TICK_PER_SECOND)
+    while (rt_tick_get() - start < NTP_GET_TIMEOUT * RT_TICK_PER_SECOND)
     {
     {
         for (i = 0; i < server_num; i++)
         for (i = 0; i < server_num; i++)
         {
         {
@@ -309,7 +310,7 @@ time_t ntp_get_time(const char *host_name)
 
 
 __exit:
 __exit:
 
 
-    if (rt_tick_get() <= start + NTP_GET_TIMEOUT * RT_TICK_PER_SECOND)
+    if (rt_tick_get() - start < NTP_GET_TIMEOUT * RT_TICK_PER_SECOND)
     {
     {
         /* These two fields contain the time-stamp seconds as the packet left the NTP server.
         /* These two fields contain the time-stamp seconds as the packet left the NTP server.
            The number of seconds correspond to the seconds passed since 1900.
            The number of seconds correspond to the seconds passed since 1900.