boost::corosio::connect

connect overloads

Synopses

Asynchronously connect a socket by trying each endpoint in a range.

template<
    class Socket,
    std::ranges::input_range Range>
requires std::convertible_to<
        std::ranges::range_reference_t<Range>,
        typename Socket::endpoint_type>
capy::task<capy::io_result<Socket::endpoint_type>>
connect(
    Socket& s,
    Range endpoints);

Asynchronously connect a socket by trying each endpoint in an iterator range.

template<
    class Socket,
    std::input_iterator Iter>
requires std::convertible_to<
        std::iter_reference_t<Iter>,
        typename Socket::endpoint_type>
capy::task<capy::io_result<Iter>>
connect(
    Socket& s,
    Iter begin,
    Iter end);

Asynchronously connect a socket by trying each endpoint in a range, filtered by a user‐supplied condition.

template<
    class Socket,
    std::ranges::input_range Range,
    class ConnectCondition>
requires std::convertible_to<
                 std::ranges::range_reference_t<Range>,
                 typename Socket::endpoint_type> &&
    std::predicate<
                 ConnectCondition&,
                 std::error_code const&,
                 typename Socket::endpoint_type const&>
capy::task<capy::io_result<Socket::endpoint_type>>
connect(
    Socket& s,
    Range endpoints,
    ConnectCondition cond);

Asynchronously connect a socket by trying each endpoint in an iterator range, filtered by a user‐supplied condition.

template<
    class Socket,
    std::input_iterator Iter,
    class ConnectCondition>
requires std::convertible_to<
                 std::iter_reference_t<Iter>,
                 typename Socket::endpoint_type> &&
    std::predicate<
                 ConnectCondition&,
                 std::error_code const&,
                 typename Socket::endpoint_type const&>
capy::task<capy::io_result<Iter>>
connect(
    Socket& s,
    Iter begin,
    Iter end,
    ConnectCondition cond);

Exceptions

Name

Thrown on

std::system_error

if auto‐opening the socket fails during an attempt (inherits the contract of Socket::connect).

Return Value

  • An awaitable completing with capy::io_result<typename Socket::endpoint_type>: ‐ on success: default error_code and the connected endpoint; ‐ on failure of all attempts: the error from the last attempt and a default‐constructed endpoint; ‐ on empty range: std::errc::no_such_device_or_address and a default‐constructed endpoint.

  • An awaitable completing with capy::io_result<Iter>: ‐ on success: default error_code and the iterator of the successful endpoint; ‐ on failure of all attempts: the error from the last attempt and end; ‐ on empty range: std::errc::no_such_device_or_address and end.

  • Same as the non‐condition overload. If every candidate is rejected, completes with std::errc::no_such_device_or_address.

  • Same as the plain iterator overload. If every candidate is rejected, completes with std::errc::no_such_device_or_address.

Parameters

Name

Description

s

The socket to connect. Must have a connect(endpoint) member returning an awaitable, plus close() and is_open(). If the socket is already open, it will be closed before the first attempt.

endpoints

A range of candidate endpoints. Taken by value so temporaries (e.g. resolver_results returned from resolver::resolve) remain alive for the coroutine's lifetime. Because the range is owned by the coroutine, passing an lvalue copies it; since resolver_results is a std::vector<resolver_entry>, that is a deep copy of every entry. Pass an rvalue (std::move(results)) or use the iterator overload (connect(s, results.begin(), results.end())) to avoid the copy.

begin

The first candidate.

end

One past the last candidate.

cond

A predicate invocable with (std::error_code const&, typename Socket::endpoint_type const&) returning a value contextually convertible to bool.

Created with MrDocs