fix: Fix bugs in new webserver (#1780)

Fixes #919.

Fixes bugs for new webserver:
- Unhandled exception when closing already closed websocket
- No pings for plain websocket connection
- Server drops websocket connection when client responds to pings but
doesn't send anything

Also changing API of ng connections. Now timeout is set by a separate
method instead of providing it for each call.
This commit is contained in:
Sergey Kuznetsov
2024-12-19 15:14:04 +00:00
committed by GitHub
parent c4b87d2a0a
commit 7d4e3619b0
13 changed files with 238 additions and 204 deletions

View File

@@ -32,6 +32,7 @@
#include <boost/asio/ssl/verify_mode.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/role.hpp>
#include <boost/beast/core/stream_traits.hpp>
#include <boost/beast/http/field.hpp>
#include <boost/beast/version.hpp>
@@ -150,8 +151,8 @@ WebSocketAsyncClient::connect(
if (error)
return error;
boost::beast::websocket::stream_base::timeout wsTimeout{};
stream_.get_option(wsTimeout);
boost::beast::websocket::stream_base::timeout wsTimeout =
boost::beast::websocket::stream_base::timeout::suggested(boost::beast::role_type::client);
wsTimeout.handshake_timeout = timeout;
stream_.set_option(wsTimeout);
boost::beast::get_lowest_layer(stream_).expires_never();