| Home | Libraries | People | FAQ | More

###### basic_stream::async_connect (1 of 5 overloads)

Connect the stream to the specified endpoint asynchronously.

<h7> Synopsis </h7>

    template<
        class ConnectHandler>
    DEDUCED
    async_connect(
        endpoint_type const& ep,
        ConnectHandler&& handler);

<h7> Description </h7>

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 `timeout`.

<h7> Parameters </h7>

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
    );

Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`.

<h7> See Also </h7>

`basic_stream::async_connect`