mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 12:27:44 +02:00
Fixes to support Asio changes (API Change):
This adjusts Beast's interfaces and implementation to match the changes in Boost.Asio.
This commit is contained in:
@ -48,13 +48,13 @@ fail(beast::error_code ec, char const* what)
|
||||
// Echoes back all received WebSocket messages
|
||||
class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
websocket::stream<beast::ssl_stream<
|
||||
beast::tcp_stream<net::io_context::strand>>> ws_;
|
||||
websocket::stream<
|
||||
beast::ssl_stream<beast::tcp_stream>> ws_;
|
||||
beast::multi_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
session(tcp::socket socket, ssl::context& ctx)
|
||||
session(tcp::socket&& socket, ssl::context& ctx)
|
||||
: ws_(std::move(socket), ctx)
|
||||
{
|
||||
}
|
||||
@ -172,16 +172,20 @@ public:
|
||||
// Accepts incoming connections and launches the sessions
|
||||
class listener : public std::enable_shared_from_this<listener>
|
||||
{
|
||||
net::io_context& ioc_;
|
||||
ssl::context& ctx_;
|
||||
tcp::acceptor acceptor_;
|
||||
tcp::socket socket_;
|
||||
|
||||
public:
|
||||
listener(
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint)
|
||||
: ctx_(ctx)
|
||||
, acceptor_(ioc)
|
||||
: ioc_(ioc)
|
||||
, ctx_(ctx)
|
||||
, acceptor_(beast::make_strand(ioc))
|
||||
, socket_(beast::make_strand(ioc))
|
||||
{
|
||||
beast::error_code ec;
|
||||
|
||||
@ -232,13 +236,14 @@ public:
|
||||
do_accept()
|
||||
{
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
beast::bind_front_handler(
|
||||
&listener::on_accept,
|
||||
shared_from_this()));
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(beast::error_code ec, tcp::socket socket)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -247,9 +252,12 @@ public:
|
||||
else
|
||||
{
|
||||
// Create the session and run it
|
||||
std::make_shared<session>(std::move(socket), ctx_)->run();
|
||||
std::make_shared<session>(std::move(socket_), ctx_)->run();
|
||||
}
|
||||
|
||||
// Make sure each session gets its own strand
|
||||
socket_ = tcp::socket(beast::make_strand(ioc_));
|
||||
|
||||
// Accept another connection
|
||||
do_accept();
|
||||
}
|
||||
|
Reference in New Issue
Block a user