From: Guus Sliepen Date: Wed, 25 Sep 2019 19:47:44 +0000 (+0200) Subject: Update mesh->loop.now right after select() returns. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=6406d4d35d5b5d56e9359f00fe38e25686f93821;p=meshlink Update mesh->loop.now right after select() returns. It can be that select() waits for a few seconds before an event or timeout arives. We didn't update mesh->loop.now before calling any of the callback functions, which meant they could use a time a few seconds in the past. In particular, the last_ping_time of connections could be set to a value such that they would immediately be considered timed out. --- diff --git a/src/event.c b/src/event.c index b58c6b6b..245e39ec 100644 --- a/src/event.c +++ b/src/event.c @@ -218,6 +218,7 @@ bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex) { fd_set readable; fd_set writable; + while(loop->running) { gettimeofday(&loop->now, NULL); struct timeval diff, it, *tv = NULL; @@ -267,6 +268,8 @@ bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex) { pthread_mutex_lock(mutex); } + gettimeofday(&loop->now, NULL); + if(n < 0) { if(sockwouldblock(errno)) { continue;