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