From ae5c1fe4c8190e712081b3c79deb33b9d37e59c6 Mon Sep 17 00:00:00 2001 From: Morten Minde Neergaard <169057+xim@users.noreply.github.com> Date: Fri, 11 Aug 2023 14:17:11 +0200 Subject: [PATCH] websockets: Count pings from server as activity for idle_timeout If the stream is receiving control packets like ping, don't count it as idle. This means you can enable `timeout_opt.keep_alive_ping` on only one side to get heartbeat. Addresses issue #2716 --- include/boost/beast/websocket/impl/stream_impl.hpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/boost/beast/websocket/impl/stream_impl.hpp b/include/boost/beast/websocket/impl/stream_impl.hpp index 615b4beb19..1ee3809aa4 100644 --- a/include/boost/beast/websocket/impl/stream_impl.hpp +++ b/include/boost/beast/websocket/impl/stream_impl.hpp @@ -439,12 +439,8 @@ struct stream::impl_type if(timeout_opt.idle_timeout != none()) { idle_counter = 0; - if(timeout_opt.keep_alive_pings) - timer.expires_after( - timeout_opt.idle_timeout / 2); - else - timer.expires_after( - timeout_opt.idle_timeout); + timer.expires_after( + timeout_opt.idle_timeout / 2); BOOST_ASIO_HANDLER_LOCATION(( __FILE__, __LINE__, @@ -569,9 +565,9 @@ struct stream::impl_type if(impl.timeout_opt.idle_timeout == none()) return; - if( impl.timeout_opt.keep_alive_pings && - impl.idle_counter < 1) + if( impl.idle_counter < 1 ) { + if( impl.timeout_opt.keep_alive_pings ) { BOOST_ASIO_HANDLER_LOCATION(( __FILE__, __LINE__,