diff --git a/src/core/timers.c b/src/core/timers.c index c8ead4e7..23f8296b 100644 --- a/src/core/timers.c +++ b/src/core/timers.c @@ -326,16 +326,26 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) #endif /* LWIP_DEBUG_TIMERNAMES */ { struct sys_timeo *timeout, *t; + u32_t now, diff; timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT); if (timeout == NULL) { LWIP_ASSERT("sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL); return; } + + now = sys_now(); + if (next_timeout == NULL) { + diff = 0; + timeouts_last_time = now; + } else { + diff = now - timeouts_last_time; + } + timeout->next = NULL; timeout->h = handler; timeout->arg = arg; - timeout->time = msecs; + timeout->time = msecs + diff; #if LWIP_DEBUG_TIMERNAMES timeout->handler_name = handler_name; LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n", @@ -437,7 +447,7 @@ sys_check_timeouts(void) if (tmptimeout && (tmptimeout->time <= diff)) { /* timeout has expired */ had_one = 1; - timeouts_last_time = now; + timeouts_last_time += tmptimeout->time; diff -= tmptimeout->time; next_timeout = tmptimeout->next; handler = tmptimeout->h;