gettimeofday() for MSVC #2674
                  
                    
                      gvanem
                    
                  
                
                  started this conversation in
                Feature requests
              
            Replies: 2 comments 2 replies
-
| PS. I did a similar patch for the SNTP example: --- a/examples/sntp-time-sync/main.c 2024-01-13 14:54:39
+++ b/examples/sntp-time-sync/main.c 2024-03-29 17:01:37
@@ -22,11 +22,21 @@
   return t;
 }
+#if (MG_ARCH == MG_ARCH_WIN32)
+  int mg_gettimeofday(struct timeval *tv, void *tz);
+  #define gettimeofday(tv, tz) mg_gettimeofday (tv, tz)
+#endif
+
+
 // SNTP client callback
 static void sfn(struct mg_connection *c, int ev, void *ev_data) {
   if (ev == MG_EV_SNTP_TIME) {
     int64_t t = *(int64_t *) ev_data;
-    MG_INFO(("Got SNTP time: %lld ms from epoch", t));
+    struct timeval tv = {0, 0};
+    gettimeofday(&tv, 0);
+    int64_t ms     = (int64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
+    int64_t t_diff = ms > t ? ms - t : t - ms;
+    MG_INFO(("Got SNTP time: %lld ms from epoch (diff: %lld)", t, t_diff));
     s_boot_timestamp = (time_t) ((t - mg_millis()) / 1000);
   } else if (ev == MG_EV_CLOSE) {
     s_sntp_conn = NULL;Showing:  | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| 
 Current state of things is: 
 So...  | 
Beta Was this translation helpful? Give feedback.
                  
                    2 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Running the

unit_test.exeprogram for_WIN32I noted there were nodiff: xxxprinted for the local vs. SNTP time.I have the D4 (Dimension 4) program running here which keep my PC's time rather accurate. History of last week:
So I'm interested in SNTP. With the little patch below, I now got this:
Patch:
So my request is for a
mg_gettimeofday()supporting both Windows and POSIX. How about it?Beta Was this translation helpful? Give feedback.
All reactions