Skip to content

Commit

Permalink
websockets: Count pings from server as activity for idle_timeout
Browse files Browse the repository at this point in the history
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 boostorg#2716
  • Loading branch information
xim committed Aug 29, 2023
1 parent 35d5332 commit 6667dbc
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions include/boost/beast/websocket/impl/stream_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,8 @@ struct stream<NextLayer, deflateSupported>::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__,
Expand Down Expand Up @@ -569,9 +565,9 @@ struct stream<NextLayer, deflateSupported>::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__,
Expand Down

0 comments on commit 6667dbc

Please sign in to comment.