forked from boostorg/beast
Use suggested timeouts in Websocket examples
This commit is contained in:
@@ -123,6 +123,15 @@ public:
|
||||
if(ec)
|
||||
return fail(ec, "ssl_handshake");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws_).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::client));
|
||||
|
||||
// Perform the websocket handshake
|
||||
ws_.async_handshake(host_, "/",
|
||||
beast::bind_front_handler(
|
||||
|
||||
@@ -101,6 +101,15 @@ public:
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws_).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::client));
|
||||
|
||||
// Perform the websocket handshake
|
||||
ws_.async_handshake(host_, "/",
|
||||
beast::bind_front_handler(
|
||||
|
||||
@@ -79,6 +79,15 @@ do_session(
|
||||
if(ec)
|
||||
return fail(ec, "ssl_handshake");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::client));
|
||||
|
||||
// Perform the websocket handshake
|
||||
ws.async_handshake(host, "/", yield[ec]);
|
||||
if(ec)
|
||||
|
||||
@@ -65,6 +65,15 @@ do_session(
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::client));
|
||||
|
||||
// Perform the websocket handshake
|
||||
ws.async_handshake(host, "/", yield[ec]);
|
||||
if(ec)
|
||||
|
||||
@@ -80,6 +80,15 @@ public:
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws_).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
|
||||
// Accept the websocket handshake
|
||||
ws_.async_accept(
|
||||
beast::bind_front_handler(
|
||||
|
||||
@@ -52,6 +52,10 @@ public:
|
||||
session(tcp::socket socket)
|
||||
: ws_(std::move(socket))
|
||||
{
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
}
|
||||
|
||||
// Start the asynchronous operation
|
||||
|
||||
@@ -17,6 +17,10 @@ websocket_session(
|
||||
: ws_(std::move(socket))
|
||||
, state_(state)
|
||||
{
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
}
|
||||
|
||||
websocket_session::
|
||||
|
||||
@@ -66,6 +66,15 @@ do_session(
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
|
||||
// Accept the websocket handshake
|
||||
ws.async_accept(yield[ec]);
|
||||
if(ec)
|
||||
|
||||
@@ -51,6 +51,11 @@ do_session(ws_type& ws, net::yield_context yield)
|
||||
{
|
||||
beast::error_code ec;
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
|
||||
// Accept the websocket handshake
|
||||
ws.async_accept(yield[ec]);
|
||||
if(ec)
|
||||
|
||||
@@ -79,6 +79,9 @@ public:
|
||||
|
||||
reenter(*this)
|
||||
{
|
||||
// Set the timeout.
|
||||
beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));
|
||||
|
||||
// Perform the SSL handshake
|
||||
yield ws_.next_layer().async_handshake(
|
||||
ssl::stream_base::server,
|
||||
@@ -90,6 +93,15 @@ public:
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Turn off the timeout on the tcp_stream, because
|
||||
// the websocket stream has its own timeout system.
|
||||
beast::get_lowest_layer(ws_).expires_never();
|
||||
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
|
||||
// Accept the websocket handshake
|
||||
yield ws_.async_accept(
|
||||
std::bind(
|
||||
|
||||
@@ -74,6 +74,11 @@ public:
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
reenter(*this)
|
||||
{
|
||||
// Set suggested timeout settings for the websocket
|
||||
ws_.set_option(
|
||||
websocket::stream_base::suggested_settings(
|
||||
websocket::role_type::server));
|
||||
|
||||
// Accept the websocket handshake
|
||||
yield ws_.async_accept(
|
||||
std::bind(
|
||||
|
||||
Reference in New Issue
Block a user