forked from boostorg/beast
Pass strand to async_accept
This commit is contained in:
@@ -148,7 +148,6 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
{
|
||||
net::io_context& ioc_;
|
||||
tcp::acceptor acceptor_;
|
||||
tcp::socket socket_;
|
||||
|
||||
public:
|
||||
listener(
|
||||
@@ -156,7 +155,6 @@ public:
|
||||
tcp::endpoint endpoint)
|
||||
: ioc_(ioc)
|
||||
, acceptor_(ioc)
|
||||
, socket_(beast::make_strand(ioc_))
|
||||
{
|
||||
beast::error_code ec;
|
||||
|
||||
@@ -206,15 +204,16 @@ public:
|
||||
void
|
||||
do_accept()
|
||||
{
|
||||
// The new connection gets its own strand
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
beast::make_strand(ioc_),
|
||||
beast::bind_front_handler(
|
||||
&listener::on_accept,
|
||||
shared_from_this()));
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(beast::error_code ec)
|
||||
on_accept(beast::error_code ec, tcp::socket socket)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@@ -223,12 +222,9 @@ public:
|
||||
else
|
||||
{
|
||||
// Create the session and run it
|
||||
std::make_shared<session>(std::move(socket_))->run();
|
||||
std::make_shared<session>(std::move(socket))->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