boost::corosio::tcp_acceptor::accept
Initiate an asynchronous accept operation.
Synopsis
Declared in <boost/corosio/tcp_acceptor.hpp>
auto
accept(tcp_socket& peer);
Description
Accepts an incoming connection and initializes the provided socket with the new connection. The acceptor must be listening before calling this function.
The operation supports cancellation via std::stop_token through the affine awaitable protocol. If the associated stop token is triggered, the operation completes immediately with errc::operation_canceled.
Preconditions
The acceptor must be listening (is_open() == true). The peer socket must be associated with the same execution context.
Example
tcp_socket peer(ioc);
auto [ec] = co_await acc.accept(peer);
if (!ec) {
// Use peer socket
}
Return Value
An awaitable that completes with io_result<>. Returns success on successful accept, or an error code on failure including: ‐ operation_canceled: Cancelled via stop_token or cancel(). Check ec == cond::canceled for portable comparison.
Parameters
| Name | Description |
|---|---|
peer |
The socket to receive the accepted connection. Any existing connection on this socket will be closed. |
Created with MrDocs