boost::corosio::tcp_acceptor
An asynchronous TCP acceptor for coroutine I/O.
Synopsis
Declared in <boost/corosio/tcp_acceptor.hpp>
class tcp_acceptor
: public io_object
Description
This class provides asynchronous TCP accept operations that return awaitable types. The acceptor binds to a local endpoint and listens for incoming connections.
Each accept operation participates in the affine awaitable protocol, ensuring coroutines resume on the correct executor.
Thread Safety
Distinct objects: Safe. Shared objects: Unsafe. An acceptor must not have concurrent accept operations.
Semantics
Wraps the platform TCP listener. Operations dispatch to OS accept APIs via the io_context reactor.
Example
// Convenience constructor: open + SO_REUSEADDR + bind + listen
io_context ioc;
tcp_acceptor acc( ioc, endpoint( 8080 ) );
tcp_socket peer( ioc );
auto [ec] = co_await acc.accept( peer );
if ( !ec ) {
// peer is now a connected socket
auto [ec2, n] = co_await peer.read_some( buf );
}
Example
// Fine-grained setup
tcp_acceptor acc( ioc );
acc.open( tcp::v6() );
acc.set_option( socket_option::reuse_address( true ) );
acc.set_option( socket_option::v6_only( true ) );
if ( auto ec = acc.bind( endpoint( ipv6_address::any(), 8080 ) ) )
return ec;
if ( auto ec = acc.listen() )
return ec;
Types
Name |
Description |
RAII wrapper for I/O object implementation lifetime. |
|
Define backend hooks for TCP acceptor operations. |
|
Service interface for I/O object lifecycle management. |
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
|
|
Bind to a local endpoint. |
|
Cancel any pending asynchronous operations. |
|
Close the acceptor. |
|
Return the execution context. |
|
Get a socket option from the acceptor. |
|
Check if the acceptor is listening. |
|
Start listening for incoming connections. |
|
Get the local endpoint of the acceptor. |
|
Create the acceptor socket without binding or listening. |
|
Set a socket option on the acceptor. |
|
Wait for an incoming connection or readiness condition. |
Protected Member Functions
Name |
Description |
|
Construct from |
|
Move assign from another I/O object. |
Protected Static Member Functions
Name |
Description |
Create a handle bound to a service found in the context. |
|
Transfer accepted peer impl to the peer socket. |
Derived Classes
Name |
Description |
An asynchronous TCP acceptor with devirtualized accept operations. |
Created with MrDocs