boost::corosio::tcp_acceptor

An asynchronous TCP acceptor for coroutine I/O.

Synopsis

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

io_context ioc;
tcp_acceptor acc(ioc);
acc.listen(endpoint(8080));  // Bind to port 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);
}

Base Classes

Name Description

io_object

Base class for platform I/O objects.

Types

Name

Description

acceptor_impl

handle

RAII wrapper for I/O object implementation lifetime.

implementation

Forward declaration for platform‐specific implementation.

io_object_impl

Base interface for platform I/O implementations.

io_service

Service interface for I/O object lifecycle management.

Member Functions

Name

Description

tcp_acceptor [constructor] [deleted]

Constructors

~tcp_acceptor [destructor] [virtual]

Destructor.

operator= [deleted]

Move assignment operator.

accept

Initiate an asynchronous accept operation.

cancel

Cancel any pending asynchronous operations.

close

Close the acceptor.

context

Return the execution context.

is_open

Check if the acceptor is listening.

listen

Open, bind, and listen on an endpoint.

local_endpoint

Get the local endpoint of the acceptor.

Protected Data Members

Name

ctx_

impl_

Created with MrDocs