...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Start an asynchronous accept.
template< typename ExecutionContext, typename MoveAcceptToken = DEFAULT> DEDUCED async_accept( ExecutionContext & context, endpoint_type & peer_endpoint, MoveAcceptToken && token = DEFAULT, typename constraint< is_convertible< ExecutionContext &, execution_context & >::value >::type = 0);
This function is used to asynchronously accept a new connection. It is an initiating function for an asynchronous operation, and always returns immediately.
This overload requires that the Protocol template parameter satisfy the AcceptableProtocol type requirements.
The I/O execution context object to be used for the newly accepted socket.
An endpoint object into which the endpoint of the remote peer will be written. Ownership of the peer_endpoint object is retained by the caller, which must guarantee that it is valid until the completion handler is called.
The completion
token that will be used to produce a completion handler,
which will be called when the accept completes. Potential completion
tokens include use_future
, use_awaitable
, yield_context
, or a function
object with the correct completion signature. The function signature
of the completion handler must be:
void handler( // Result of operation. const boost::system::error_code& error, // On success, the newly accepted socket. typename Protocol::socket::template rebind_executor< typename ExecutionContext::executor_type>::other peer );
Regardless of whether the asynchronous operation completes immediately
or not, the completion handler will not be invoked from within
this function. On immediate completion, invocation of the handler
will be performed in a manner equivalent to using post
.
void(boost::system::error_code, typename Protocol::socket::template rebind_executor< typename ExecutionContext::executor_type>::other))
void accept_handler(const boost::system::error_code& error, boost::asio::ip::tcp::socket peer) { if (!error) { // Accept succeeded. } } ... boost::asio::ip::tcp::acceptor acceptor(my_context); ... boost::asio::ip::tcp::endpoint endpoint; acceptor.async_accept(my_context2, endpoint, accept_handler);
On POSIX or Windows operating systems, this asynchronous operation supports
cancellation for the following cancellation_type
values:
cancellation_type::terminal
cancellation_type::partial
cancellation_type::total