]> git.meshlink.io Git - meshlink/commitdiff
Update mesh->loop.now right after select() returns.
authorGuus Sliepen <guus@meshlink.io>
Wed, 25 Sep 2019 19:47:44 +0000 (21:47 +0200)
committerGuus Sliepen <guus@meshlink.io>
Wed, 25 Sep 2019 19:47:44 +0000 (21:47 +0200)
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

index b58c6b6bc11e81ffd6cf03d045a254857542ebe8..245e39ecb45f34a62d848071a7b251880a821e6d 100644 (file)
@@ -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;