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.

Make tests that verify current behaviour.

Update documentation to match changes in PR #2718.

Addresses issue #2716
This commit is contained in:
Morten Minde Neergaard
2025-02-09 18:25:10 +03:30
committed by Mohammad Nejati
parent 84115e5b13
commit f9387fda71
5 changed files with 89 additions and 12 deletions
@@ -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__,
@@ -569,9 +565,9 @@ private:
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__,
@@ -116,8 +116,10 @@ struct stream_base
An outstanding read operation must be pending, which will
complete immediately the error @ref beast::error::timeout.
@li When `keep_alive_pings` is `false`, the connection will be closed.
An outstanding read operation must be pending, which will
@li When `keep_alive_pings` is `false`, the connection will
be closed if there has been no activity. Both websocket
message frames and control frames count as activity. An
outstanding read operation must be pending, which will
complete immediately the error @ref beast::error::timeout.
*/
bool keep_alive_pings;