boost::corosio::tcp_socket::connect

Initiate an asynchronous connect operation.

Synopsis

auto
connect(endpoint ep);

Description

Connects the socket to the specified remote endpoint. The socket must be open 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 socket must be open (is_open() == true).

Example

auto [ec] = co_await s.connect(endpoint);
if (ec) { ... }

Exceptions

Name

Thrown on

std::logic_error

if the socket is not open.

Return Value

An awaitable that completes with io_result<>. Returns success (default error_code) on successful connection, or an error code on failure including: ‐ connection_refused: No server listening at endpoint ‐ timed_out: Connection attempt timed out ‐ network_unreachable: No route to host ‐ operation_canceled: Cancelled via stop_token or cancel(). Check ec == cond::canceled for portable comparison.

Parameters

Name Description

ep

The remote endpoint to connect to.

Created with MrDocs