@@ -381,6 +381,8 @@ bool TcpChannel::setKeepAlive(bool enable, const Seconds& interval, const Second
381381
382382 if (!enable)
383383 {
384+ LOG (LS_INFO) << " Keep alive disabled" ;
385+
384386 keep_alive_counter_.clear ();
385387
386388 if (keep_alive_timer_)
@@ -391,6 +393,9 @@ bool TcpChannel::setKeepAlive(bool enable, const Seconds& interval, const Second
391393 }
392394 else
393395 {
396+ LOG (LS_INFO) << " Keep alive enabled (interval=" << interval.count ()
397+ << " timeout=" << timeout.count () << " )" ;
398+
394399 keep_alive_interval_ = interval;
395400 keep_alive_timeout_ = timeout;
396401
@@ -989,6 +994,7 @@ void TcpChannel::onReadServiceData(const std::error_code& error_code, size_t byt
989994 largeNumberIncrement (&keep_alive_counter_);
990995
991996 // Restart keep alive timer.
997+ keep_alive_timer_->cancel ();
992998 keep_alive_timer_->expires_after (keep_alive_interval_);
993999 keep_alive_timer_->async_wait (
9941000 std::bind (&Handler::onKeepAliveInterval, handler_, std::placeholders::_1));
@@ -1017,6 +1023,7 @@ void TcpChannel::onKeepAliveInterval(const std::error_code& error_code)
10171023 LOG (LS_ERROR) << " Keep alive timer error: " << utf16FromLocal8Bit (error_code.message ());
10181024
10191025 // Restarting the timer.
1026+ keep_alive_timer_->cancel ();
10201027 keep_alive_timer_->expires_after (keep_alive_interval_);
10211028 keep_alive_timer_->async_wait (
10221029 std::bind (&Handler::onKeepAliveInterval, handler_, std::placeholders::_1));
@@ -1031,6 +1038,7 @@ void TcpChannel::onKeepAliveInterval(const std::error_code& error_code)
10311038
10321039 // If a response is not received within the specified interval, the connection will be
10331040 // terminated.
1041+ keep_alive_timer_->cancel ();
10341042 keep_alive_timer_->expires_after (keep_alive_timeout_);
10351043 keep_alive_timer_->async_wait (
10361044 std::bind (&Handler::onKeepAliveTimeout, handler_, std::placeholders::_1));
0 commit comments