diff --git a/src/core/timeouts.c b/src/core/timeouts.c index 91657eb7..7baf69d2 100644 --- a/src/core/timeouts.c +++ b/src/core/timeouts.c @@ -347,8 +347,11 @@ sys_untimeout(sys_timeout_handler handler, void *arg) * handler functions when timeouts expire. * * Must be called periodically from your main loop. + * + * @return the time left before the next timeout is due. If no timeouts are + * enqueued, returns 0xffffffff */ -void +u32_t sys_check_timeouts(void) { u32_t now; @@ -367,11 +370,13 @@ sys_check_timeouts(void) tmptimeout = next_timeout; if (tmptimeout == NULL) { - return; + return SYS_TIMEOUTS_SLEEPTIME_INFINITE; } if (TIME_LESS_THAN(now, tmptimeout->time)) { - return; + u32_t ret = (u32_t)(tmptimeout->time - now); + LWIP_ASSERT("invalid sleeptime", ret <= LWIP_MAX_TIMEOUT); + return ret; } /* Timeout has expired */ diff --git a/src/include/lwip/timeouts.h b/src/include/lwip/timeouts.h index b601f9eb..234f1b31 100644 --- a/src/include/lwip/timeouts.h +++ b/src/include/lwip/timeouts.h @@ -111,7 +111,7 @@ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg); void sys_untimeout(sys_timeout_handler handler, void *arg); void sys_restart_timeouts(void); -void sys_check_timeouts(void); +u32_t sys_check_timeouts(void); u32_t sys_timeouts_sleeptime(void); #if LWIP_TESTMODE