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
-
Running the
![image](https://private-user-images.githubusercontent.com/945271/318082097-974fe9ad-88c8-45a6-9282-9088c936442c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjcxNDgsIm5iZiI6MTczOTQ2Njg0OCwicGF0aCI6Ii85NDUyNzEvMzE4MDgyMDk3LTk3NGZlOWFkLTg4YzgtNDVhNi05MjgyLTkwODhjOTM2NDQyYy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QxNzE0MDhaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05OGE5MDE0NGFjZTRmNWEwOTBiYjdjNzU5MDY1NzQxNDhmODIzNzA0MTUzZGY0MjIxYjBjNmZhZDgwMTcwNDc2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.UPWzjYqIvGUtj9qtk_cHCmd55iCc1tYFKBBYbxk1M7g)
unit_test.exe
program for_WIN32
I noted there were nodiff: xxx
printed 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