// echo_server.cpp
// ~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
class session : public std::enable_shared_from_this<session>
{
public:
- explicit session(tcp::socket socket)
+ explicit session(boost::asio::io_context& io_context, tcp::socket socket)
: socket_(std::move(socket)),
- timer_(socket_.get_io_context()),
- strand_(socket_.get_io_context())
+ timer_(io_context),
+ strand_(io_context.get_executor())
{
}
private:
tcp::socket socket_;
boost::asio::steady_timer timer_;
- boost::asio::io_context::strand strand_;
+ boost::asio::strand<boost::asio::io_context::executor_type> strand_;
};
int main(int argc, char* argv[])
boost::system::error_code ec;
tcp::socket socket(io_context);
acceptor.async_accept(socket, yield[ec]);
- if (!ec) std::make_shared<session>(std::move(socket))->go();
+ if (!ec)
+ {
+ std::make_shared<session>(io_context, std::move(socket))->go();
+ }
}
});