2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-26 06:12:08 +00:00

Change spawn() to be a completion token-based async operation.

Added new spawn() overloads that conform to the requirements for
asynchronous operations. These overloads also support cancellation. When
targeting C++11 and later these functions are implemented in terms of
Boost.Context directly.

The existing overloads have been retained but are deprecated.
This commit is contained in:
Christopher Kohlhoff
2022-06-30 00:30:27 +10:00
parent 74a94fe7f4
commit 5bbdc9b709
10 changed files with 1943 additions and 453 deletions

View File

@@ -8,6 +8,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
@@ -39,10 +40,12 @@ public:
{
boost::asio::spawn(strand_,
boost::bind(&session::echo,
shared_from_this(), boost::placeholders::_1));
shared_from_this(), boost::placeholders::_1),
boost::asio::detached_t());
boost::asio::spawn(strand_,
boost::bind(&session::timeout,
shared_from_this(), boost::placeholders::_1));
shared_from_this(), boost::placeholders::_1),
boost::asio::detached_t());
}
private:
@@ -108,8 +111,9 @@ int main(int argc, char* argv[])
boost::asio::io_context io_context;
boost::asio::spawn(io_context,
boost::bind(do_accept,
boost::ref(io_context), atoi(argv[1]), boost::placeholders::_1));
boost::bind(do_accept, boost::ref(io_context),
atoi(argv[1]), boost::placeholders::_1),
boost::asio::detached_t());
io_context.run();
}