Merge pull request #277 from CopernicaMarketingSoftware/heartbeat-timer

ev_timer_again should be called after next has been set to a new value
This commit is contained in:
Emiel Bruijntjes 2019-01-10 16:59:13 +01:00 committed by GitHub
commit 22076c34ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 14 deletions

View File

@ -235,6 +235,9 @@ private:
}
else
{
// was the server idle for a too long period of time?
if (now >= _expire) return (void) _connection->close();
// the connection is alive, and heartbeats are needed, should we send a new one?
if (now >= _next)
{
@ -245,20 +248,11 @@ private:
_next += std::max(_interval / 2, 1);
}
// was the server idle for a too longer period of time?
if (now >= _expire)
{
// close the connection with immediate effect (this will destruct the connection)
_connection->close(true);
}
else
{
// find the earliest thing that expires
_timer.repeat = std::min(_next, _expire) - now;
// restart the timer
ev_timer_again(_loop, &_timer);
}
// reset the timer to trigger again later
_timer.repeat = std::min(_next, _expire) - now;
// restart the timer
ev_timer_again(_loop, &_timer);
}
}