From 6406d4d35d5b5d56e9359f00fe38e25686f93821 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 25 Sep 2019 21:47:44 +0200 Subject: [PATCH] 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. --- src/event.c | 3 +++ 1 file changed, 3 insertions(+) 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; -- 2.39.2