20 Socket algorithms [socket.algo]

20.2 Asynchronous connect operations [socket.algo.async.connect]

template<class Protocol, class EndpointSequence, class CompletionToken> DEDUCED async_connect(basic_socket<Protocol>& s, const EndpointSequence& endpoints, CompletionToken&& token);

Returns:

async_connect(s, endpoints, [](auto, auto){ return true; }, forward<CompletionToken>(token))

template<class Protocol, class EndpointSequence, class ConnectCondition, class CompletionToken> DEDUCED async_connect(basic_socket<Protocol>& s, const EndpointSequence& endpoints, ConnectCondition c, CompletionToken&& token);

A composed asynchronous operation ([async.reqmts.async.composed]).

Completion signature: void(error_code ec, typename Protocol::endpoint ep).

Effects: Performs ec.clear(), then finds the first element ep in the sequence endpoints for which:

  • c(ec, ep) yields true;

  • s.close(ec) succeeds;

  • s.open(ep.protocol(), ec) succeeds; and

  • the asynchronous operation s.async_connect(ep, unspecified) succeeds.

ec is updated with the result of the s.async_connect(ep, unspecified) operation, if any. If no such element is found, or if the operation fails with one of the error conditions listed below, ep is set to typename Protocol::endpoint(). [ Note: The underlying close, open, and async_connect operations are performed sequentially.  — end note ]

Error conditions:

  • socket_errc::not_found — if endpoints.empty() or if the function object c returned false for all elements in the sequence.

  • errc::operation_canceled — if s.is_open() == false immediately following an async_connect operation on the underlying socket.

template<class Protocol, class InputIterator, class CompletionToken> DEDUCED async_connect(basic_socket<Protocol>& s, InputIterator first, InputIterator last, CompletionToken&& token);

Returns:

async_connect(s, first, last, [](auto, auto){ return true; },
              forward<CompletionToken>(token))

template<class Protocol, class InputIterator, class ConnectCondition, class CompletionToken> DEDUCED async_connect(basic_socket<Protocol>& s, InputIterator first, InputIterator last, ConnectCondition c, CompletionToken&& token);

A composed asynchronous operation ([async.reqmts.async.composed]).

Completion signature: void(error_code ec, InputIterator i).

Effects: Performs ec.clear(), then finds the first iterator i in the range [first, last) for which:

  • c(ec, *i) yields true;

  • s.close(ec) succeeds;

  • s.open(typename Protocol::endpoint(*i).protocol(), ec) succeeds; and

  • the asynchronous operation s.async_connect(*i, unspecified) succeeds.

ec is updated with the result of the s.async_connect(*i, unspecified) operation, if any. If no such iterator is found, or if the operation fails with one of the error conditions listed below, i is set to last. [ Note: The underlying close, open, and async_connect operations are performed sequentially.  — end note ]

Error conditions:

  • socket_errc::not_found — if first == last or if the function object c returned false for all iterators in the range.

  • errc::operation_canceled — if s.is_open() == false immediately following an async_connect operation on the underlying socket.