Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
basic_stream::async_connect (1 of 5 overloads)

Connect the stream to the specified endpoint asynchronously.

Synopsis
template<
    class ConnectHandler = net::default_completion_token_t<executor_type>>
DEDUCED
async_connect(
    endpoint_type const& ep,
    ConnectHandler&& handler = net::default_completion_token_t< executor_type >{});
Description

This function is used to asynchronously connect the underlying socket to the specified remote endpoint. The function call always returns immediately. The underlying socket is automatically opened if needed. An automatically opened socket is not returned to the closed state upon failure. If the timeout timer expires while the operation is outstanding, the operation will be canceled and the completion handler will be invoked with the error error::timeout.

Parameters

Name

Description

ep

The remote endpoint to which the underlying socket will be connected. Copies will be made of the endpoint object as required.

handler

The completion handler to invoke when the operation completes. The implementation takes ownership of the handler by performing a decay-copy. The equivalent function signature of the handler must be:

void handler(
    error_code ec         // Result of operation
);

If the handler has an associated immediate executor, an immediate completion will be dispatched to it. Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed by dispatching to the immediate executor. If no immediate executor is specified, this is equivalent to using net::post.

Per-Operation Cancellation

This asynchronous operation supports cancellation for the following net::cancellation_type values:

if they are also supported by the socket's async_connect operation.

See Also

async_connect


PrevUpHomeNext