From 37c98dd8936480f986e85565458face99871846f Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Thu, 22 Oct 2026 13:49:21 -0300 Subject: [PATCH] mg_delay_ms() survives mg_millis() restarting on some 32-bit platforms --- mongoose.c | 5 +++-- src/util.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 349bd737..cb13611d 100644 --- a/mongoose.c +++ b/mongoose.c @@ -29399,8 +29399,9 @@ uint64_t mg_ntohll(uint64_t net) { } void mg_delayms(unsigned int ms) { - uint64_t to = mg_millis() + ms + 1; - while (mg_millis() < to) (void) 0; + uint64_t now, to = mg_millis() + ms + 1; + while ((now = mg_millis()) < to) + if (now + ms + 1 < to) to = now + ms + 1; } #if MG_ENABLE_CUSTOM_CALLOC diff --git a/src/util.c b/src/util.c index d4ebe153..8871f228 100644 --- a/src/util.c +++ b/src/util.c @@ -261,8 +261,9 @@ uint64_t mg_ntohll(uint64_t net) { } void mg_delayms(unsigned int ms) { - uint64_t to = mg_millis() + ms + 1; - while (mg_millis() < to) (void) 0; + uint64_t now, to = mg_millis() + ms + 1; + while ((now = mg_millis()) < to) + if (now + ms + 1 < to) to = now + ms + 1; } #if MG_ENABLE_CUSTOM_CALLOC