From 0857022bc45e419fb889d8eb707f46215f3f61cd Mon Sep 17 00:00:00 2001 From: Michael van der Werve Date: Thu, 10 Jan 2019 15:59:57 +0100 Subject: [PATCH] ev_timer_again should be called after next has been reset --- include/amqpcpp/libev.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/amqpcpp/libev.h b/include/amqpcpp/libev.h index 452d948..56663da 100644 --- a/include/amqpcpp/libev.h +++ b/include/amqpcpp/libev.h @@ -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); } }