Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:09

0001 //
0002 // connect.hpp
0003 // ~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_CONNECT_HPP
0012 #define BOOST_ASIO_CONNECT_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/async_result.hpp>
0020 #include <boost/asio/basic_socket.hpp>
0021 #include <boost/asio/detail/type_traits.hpp>
0022 #include <boost/asio/error.hpp>
0023 
0024 #include <boost/asio/detail/push_options.hpp>
0025 
0026 namespace boost {
0027 namespace asio {
0028 
0029 namespace detail
0030 {
0031   struct default_connect_condition;
0032   template <typename, typename> class initiate_async_range_connect;
0033   template <typename, typename> class initiate_async_iterator_connect;
0034 
0035   char (&has_iterator_helper(...))[2];
0036 
0037   template <typename T>
0038   char has_iterator_helper(T*, typename T::iterator* = 0);
0039 
0040   template <typename T>
0041   struct has_iterator_typedef
0042   {
0043     enum { value = (sizeof((has_iterator_helper)((T*)(0))) == 1) };
0044   };
0045 } // namespace detail
0046 
0047 /// Type trait used to determine whether a type is an endpoint sequence that can
0048 /// be used with with @c connect and @c async_connect.
0049 template <typename T>
0050 struct is_endpoint_sequence
0051 {
0052 #if defined(GENERATING_DOCUMENTATION)
0053   /// The value member is true if the type may be used as an endpoint sequence.
0054   static const bool value;
0055 #else
0056   enum
0057   {
0058     value = detail::has_iterator_typedef<T>::value
0059   };
0060 #endif
0061 };
0062 
0063 /**
0064  * @defgroup connect boost::asio::connect
0065  *
0066  * @brief The @c connect function is a composed operation that establishes a
0067  * socket connection by trying each endpoint in a sequence.
0068  */
0069 /*@{*/
0070 
0071 /// Establishes a socket connection by trying each endpoint in a sequence.
0072 /**
0073  * This function attempts to connect a socket to one of a sequence of
0074  * endpoints. It does this by repeated calls to the socket's @c connect member
0075  * function, once for each endpoint in the sequence, until a connection is
0076  * successfully established.
0077  *
0078  * @param s The socket to be connected. If the socket is already open, it will
0079  * be closed.
0080  *
0081  * @param endpoints A sequence of endpoints.
0082  *
0083  * @returns The successfully connected endpoint.
0084  *
0085  * @throws boost::system::system_error Thrown on failure. If the sequence is
0086  * empty, the associated @c error_code is boost::asio::error::not_found.
0087  * Otherwise, contains the error from the last connection attempt.
0088  *
0089  * @par Example
0090  * @code tcp::resolver r(my_context);
0091  * tcp::resolver::query q("host", "service");
0092  * tcp::socket s(my_context);
0093  * boost::asio::connect(s, r.resolve(q)); @endcode
0094  */
0095 template <typename Protocol, typename Executor, typename EndpointSequence>
0096 typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
0097     const EndpointSequence& endpoints,
0098     constraint_t<is_endpoint_sequence<EndpointSequence>::value> = 0);
0099 
0100 /// Establishes a socket connection by trying each endpoint in a sequence.
0101 /**
0102  * This function attempts to connect a socket to one of a sequence of
0103  * endpoints. It does this by repeated calls to the socket's @c connect member
0104  * function, once for each endpoint in the sequence, until a connection is
0105  * successfully established.
0106  *
0107  * @param s The socket to be connected. If the socket is already open, it will
0108  * be closed.
0109  *
0110  * @param endpoints A sequence of endpoints.
0111  *
0112  * @param ec Set to indicate what error occurred, if any. If the sequence is
0113  * empty, set to boost::asio::error::not_found. Otherwise, contains the error
0114  * from the last connection attempt.
0115  *
0116  * @returns On success, the successfully connected endpoint. Otherwise, a
0117  * default-constructed endpoint.
0118  *
0119  * @par Example
0120  * @code tcp::resolver r(my_context);
0121  * tcp::resolver::query q("host", "service");
0122  * tcp::socket s(my_context);
0123  * boost::system::error_code ec;
0124  * boost::asio::connect(s, r.resolve(q), ec);
0125  * if (ec)
0126  * {
0127  *   // An error occurred.
0128  * } @endcode
0129  */
0130 template <typename Protocol, typename Executor, typename EndpointSequence>
0131 typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
0132     const EndpointSequence& endpoints, boost::system::error_code& ec,
0133     constraint_t<is_endpoint_sequence<EndpointSequence>::value> = 0);
0134 
0135 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0136 /// (Deprecated: Use range overload.) Establishes a socket connection by trying
0137 /// each endpoint in a sequence.
0138 /**
0139  * This function attempts to connect a socket to one of a sequence of
0140  * endpoints. It does this by repeated calls to the socket's @c connect member
0141  * function, once for each endpoint in the sequence, until a connection is
0142  * successfully established.
0143  *
0144  * @param s The socket to be connected. If the socket is already open, it will
0145  * be closed.
0146  *
0147  * @param begin An iterator pointing to the start of a sequence of endpoints.
0148  *
0149  * @returns On success, an iterator denoting the successfully connected
0150  * endpoint. Otherwise, the end iterator.
0151  *
0152  * @throws boost::system::system_error Thrown on failure. If the sequence is
0153  * empty, the associated @c error_code is boost::asio::error::not_found.
0154  * Otherwise, contains the error from the last connection attempt.
0155  *
0156  * @note This overload assumes that a default constructed object of type @c
0157  * Iterator represents the end of the sequence. This is a valid assumption for
0158  * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
0159  */
0160 template <typename Protocol, typename Executor, typename Iterator>
0161 Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
0162     constraint_t<!is_endpoint_sequence<Iterator>::value> = 0);
0163 
0164 /// (Deprecated: Use range overload.) Establishes a socket connection by trying
0165 /// each endpoint in a sequence.
0166 /**
0167  * This function attempts to connect a socket to one of a sequence of
0168  * endpoints. It does this by repeated calls to the socket's @c connect member
0169  * function, once for each endpoint in the sequence, until a connection is
0170  * successfully established.
0171  *
0172  * @param s The socket to be connected. If the socket is already open, it will
0173  * be closed.
0174  *
0175  * @param begin An iterator pointing to the start of a sequence of endpoints.
0176  *
0177  * @param ec Set to indicate what error occurred, if any. If the sequence is
0178  * empty, set to boost::asio::error::not_found. Otherwise, contains the error
0179  * from the last connection attempt.
0180  *
0181  * @returns On success, an iterator denoting the successfully connected
0182  * endpoint. Otherwise, the end iterator.
0183  *
0184  * @note This overload assumes that a default constructed object of type @c
0185  * Iterator represents the end of the sequence. This is a valid assumption for
0186  * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
0187  */
0188 template <typename Protocol, typename Executor, typename Iterator>
0189 Iterator connect(basic_socket<Protocol, Executor>& s,
0190     Iterator begin, boost::system::error_code& ec,
0191     constraint_t<!is_endpoint_sequence<Iterator>::value> = 0);
0192 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
0193 
0194 /// Establishes a socket connection by trying each endpoint in a sequence.
0195 /**
0196  * This function attempts to connect a socket to one of a sequence of
0197  * endpoints. It does this by repeated calls to the socket's @c connect member
0198  * function, once for each endpoint in the sequence, until a connection is
0199  * successfully established.
0200  *
0201  * @param s The socket to be connected. If the socket is already open, it will
0202  * be closed.
0203  *
0204  * @param begin An iterator pointing to the start of a sequence of endpoints.
0205  *
0206  * @param end An iterator pointing to the end of a sequence of endpoints.
0207  *
0208  * @returns An iterator denoting the successfully connected endpoint.
0209  *
0210  * @throws boost::system::system_error Thrown on failure. If the sequence is
0211  * empty, the associated @c error_code is boost::asio::error::not_found.
0212  * Otherwise, contains the error from the last connection attempt.
0213  *
0214  * @par Example
0215  * @code tcp::resolver r(my_context);
0216  * tcp::resolver::query q("host", "service");
0217  * tcp::resolver::results_type e = r.resolve(q);
0218  * tcp::socket s(my_context);
0219  * boost::asio::connect(s, e.begin(), e.end()); @endcode
0220  */
0221 template <typename Protocol, typename Executor, typename Iterator>
0222 Iterator connect(basic_socket<Protocol, Executor>& s,
0223     Iterator begin, Iterator end);
0224 
0225 /// Establishes a socket connection by trying each endpoint in a sequence.
0226 /**
0227  * This function attempts to connect a socket to one of a sequence of
0228  * endpoints. It does this by repeated calls to the socket's @c connect member
0229  * function, once for each endpoint in the sequence, until a connection is
0230  * successfully established.
0231  *
0232  * @param s The socket to be connected. If the socket is already open, it will
0233  * be closed.
0234  *
0235  * @param begin An iterator pointing to the start of a sequence of endpoints.
0236  *
0237  * @param end An iterator pointing to the end of a sequence of endpoints.
0238  *
0239  * @param ec Set to indicate what error occurred, if any. If the sequence is
0240  * empty, set to boost::asio::error::not_found. Otherwise, contains the error
0241  * from the last connection attempt.
0242  *
0243  * @returns On success, an iterator denoting the successfully connected
0244  * endpoint. Otherwise, the end iterator.
0245  *
0246  * @par Example
0247  * @code tcp::resolver r(my_context);
0248  * tcp::resolver::query q("host", "service");
0249  * tcp::resolver::results_type e = r.resolve(q);
0250  * tcp::socket s(my_context);
0251  * boost::system::error_code ec;
0252  * boost::asio::connect(s, e.begin(), e.end(), ec);
0253  * if (ec)
0254  * {
0255  *   // An error occurred.
0256  * } @endcode
0257  */
0258 template <typename Protocol, typename Executor, typename Iterator>
0259 Iterator connect(basic_socket<Protocol, Executor>& s,
0260     Iterator begin, Iterator end, boost::system::error_code& ec);
0261 
0262 /// Establishes a socket connection by trying each endpoint in a sequence.
0263 /**
0264  * This function attempts to connect a socket to one of a sequence of
0265  * endpoints. It does this by repeated calls to the socket's @c connect member
0266  * function, once for each endpoint in the sequence, until a connection is
0267  * successfully established.
0268  *
0269  * @param s The socket to be connected. If the socket is already open, it will
0270  * be closed.
0271  *
0272  * @param endpoints A sequence of endpoints.
0273  *
0274  * @param connect_condition A function object that is called prior to each
0275  * connection attempt. The signature of the function object must be:
0276  * @code bool connect_condition(
0277  *     const boost::system::error_code& ec,
0278  *     const typename Protocol::endpoint& next); @endcode
0279  * The @c ec parameter contains the result from the most recent connect
0280  * operation. Before the first connection attempt, @c ec is always set to
0281  * indicate success. The @c next parameter is the next endpoint to be tried.
0282  * The function object should return true if the next endpoint should be tried,
0283  * and false if it should be skipped.
0284  *
0285  * @returns The successfully connected endpoint.
0286  *
0287  * @throws boost::system::system_error Thrown on failure. If the sequence is
0288  * empty, the associated @c error_code is boost::asio::error::not_found.
0289  * Otherwise, contains the error from the last connection attempt.
0290  *
0291  * @par Example
0292  * The following connect condition function object can be used to output
0293  * information about the individual connection attempts:
0294  * @code struct my_connect_condition
0295  * {
0296  *   bool operator()(
0297  *       const boost::system::error_code& ec,
0298  *       const::tcp::endpoint& next)
0299  *   {
0300  *     if (ec) std::cout << "Error: " << ec.message() << std::endl;
0301  *     std::cout << "Trying: " << next << std::endl;
0302  *     return true;
0303  *   }
0304  * }; @endcode
0305  * It would be used with the boost::asio::connect function as follows:
0306  * @code tcp::resolver r(my_context);
0307  * tcp::resolver::query q("host", "service");
0308  * tcp::socket s(my_context);
0309  * tcp::endpoint e = boost::asio::connect(s,
0310  *     r.resolve(q), my_connect_condition());
0311  * std::cout << "Connected to: " << e << std::endl; @endcode
0312  */
0313 template <typename Protocol, typename Executor,
0314     typename EndpointSequence, typename ConnectCondition>
0315 typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
0316     const EndpointSequence& endpoints, ConnectCondition connect_condition,
0317     constraint_t<is_endpoint_sequence<EndpointSequence>::value> = 0);
0318 
0319 /// Establishes a socket connection by trying each endpoint in a sequence.
0320 /**
0321  * This function attempts to connect a socket to one of a sequence of
0322  * endpoints. It does this by repeated calls to the socket's @c connect member
0323  * function, once for each endpoint in the sequence, until a connection is
0324  * successfully established.
0325  *
0326  * @param s The socket to be connected. If the socket is already open, it will
0327  * be closed.
0328  *
0329  * @param endpoints A sequence of endpoints.
0330  *
0331  * @param connect_condition A function object that is called prior to each
0332  * connection attempt. The signature of the function object must be:
0333  * @code bool connect_condition(
0334  *     const boost::system::error_code& ec,
0335  *     const typename Protocol::endpoint& next); @endcode
0336  * The @c ec parameter contains the result from the most recent connect
0337  * operation. Before the first connection attempt, @c ec is always set to
0338  * indicate success. The @c next parameter is the next endpoint to be tried.
0339  * The function object should return true if the next endpoint should be tried,
0340  * and false if it should be skipped.
0341  *
0342  * @param ec Set to indicate what error occurred, if any. If the sequence is
0343  * empty, set to boost::asio::error::not_found. Otherwise, contains the error
0344  * from the last connection attempt.
0345  *
0346  * @returns On success, the successfully connected endpoint. Otherwise, a
0347  * default-constructed endpoint.
0348  *
0349  * @par Example
0350  * The following connect condition function object can be used to output
0351  * information about the individual connection attempts:
0352  * @code struct my_connect_condition
0353  * {
0354  *   bool operator()(
0355  *       const boost::system::error_code& ec,
0356  *       const::tcp::endpoint& next)
0357  *   {
0358  *     if (ec) std::cout << "Error: " << ec.message() << std::endl;
0359  *     std::cout << "Trying: " << next << std::endl;
0360  *     return true;
0361  *   }
0362  * }; @endcode
0363  * It would be used with the boost::asio::connect function as follows:
0364  * @code tcp::resolver r(my_context);
0365  * tcp::resolver::query q("host", "service");
0366  * tcp::socket s(my_context);
0367  * boost::system::error_code ec;
0368  * tcp::endpoint e = boost::asio::connect(s,
0369  *     r.resolve(q), my_connect_condition(), ec);
0370  * if (ec)
0371  * {
0372  *   // An error occurred.
0373  * }
0374  * else
0375  * {
0376  *   std::cout << "Connected to: " << e << std::endl;
0377  * } @endcode
0378  */
0379 template <typename Protocol, typename Executor,
0380     typename EndpointSequence, typename ConnectCondition>
0381 typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
0382     const EndpointSequence& endpoints, ConnectCondition connect_condition,
0383     boost::system::error_code& ec,
0384     constraint_t<is_endpoint_sequence<EndpointSequence>::value> = 0);
0385 
0386 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0387 /// (Deprecated: Use range overload.) Establishes a socket connection by trying
0388 /// each endpoint in a sequence.
0389 /**
0390  * This function attempts to connect a socket to one of a sequence of
0391  * endpoints. It does this by repeated calls to the socket's @c connect member
0392  * function, once for each endpoint in the sequence, until a connection is
0393  * successfully established.
0394  *
0395  * @param s The socket to be connected. If the socket is already open, it will
0396  * be closed.
0397  *
0398  * @param begin An iterator pointing to the start of a sequence of endpoints.
0399  *
0400  * @param connect_condition A function object that is called prior to each
0401  * connection attempt. The signature of the function object must be:
0402  * @code bool connect_condition(
0403  *     const boost::system::error_code& ec,
0404  *     const typename Protocol::endpoint& next); @endcode
0405  * The @c ec parameter contains the result from the most recent connect
0406  * operation. Before the first connection attempt, @c ec is always set to
0407  * indicate success. The @c next parameter is the next endpoint to be tried.
0408  * The function object should return true if the next endpoint should be tried,
0409  * and false if it should be skipped.
0410  *
0411  * @returns On success, an iterator denoting the successfully connected
0412  * endpoint. Otherwise, the end iterator.
0413  *
0414  * @throws boost::system::system_error Thrown on failure. If the sequence is
0415  * empty, the associated @c error_code is boost::asio::error::not_found.
0416  * Otherwise, contains the error from the last connection attempt.
0417  *
0418  * @note This overload assumes that a default constructed object of type @c
0419  * Iterator represents the end of the sequence. This is a valid assumption for
0420  * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
0421  */
0422 template <typename Protocol, typename Executor,
0423     typename Iterator, typename ConnectCondition>
0424 Iterator connect(basic_socket<Protocol, Executor>& s,
0425     Iterator begin, ConnectCondition connect_condition,
0426     constraint_t<!is_endpoint_sequence<Iterator>::value> = 0);
0427 
0428 /// (Deprecated: Use range overload.) Establishes a socket connection by trying
0429 /// each endpoint in a sequence.
0430 /**
0431  * This function attempts to connect a socket to one of a sequence of
0432  * endpoints. It does this by repeated calls to the socket's @c connect member
0433  * function, once for each endpoint in the sequence, until a connection is
0434  * successfully established.
0435  *
0436  * @param s The socket to be connected. If the socket is already open, it will
0437  * be closed.
0438  *
0439  * @param begin An iterator pointing to the start of a sequence of endpoints.
0440  *
0441  * @param connect_condition A function object that is called prior to each
0442  * connection attempt. The signature of the function object must be:
0443  * @code bool connect_condition(
0444  *     const boost::system::error_code& ec,
0445  *     const typename Protocol::endpoint& next); @endcode
0446  * The @c ec parameter contains the result from the most recent connect
0447  * operation. Before the first connection attempt, @c ec is always set to
0448  * indicate success. The @c next parameter is the next endpoint to be tried.
0449  * The function object should return true if the next endpoint should be tried,
0450  * and false if it should be skipped.
0451  *
0452  * @param ec Set to indicate what error occurred, if any. If the sequence is
0453  * empty, set to boost::asio::error::not_found. Otherwise, contains the error
0454  * from the last connection attempt.
0455  *
0456  * @returns On success, an iterator denoting the successfully connected
0457  * endpoint. Otherwise, the end iterator.
0458  *
0459  * @note This overload assumes that a default constructed object of type @c
0460  * Iterator represents the end of the sequence. This is a valid assumption for
0461  * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
0462  */
0463 template <typename Protocol, typename Executor,
0464     typename Iterator, typename ConnectCondition>
0465 Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
0466     ConnectCondition connect_condition, boost::system::error_code& ec,
0467     constraint_t<!is_endpoint_sequence<Iterator>::value> = 0);
0468 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
0469 
0470 /// Establishes a socket connection by trying each endpoint in a sequence.
0471 /**
0472  * This function attempts to connect a socket to one of a sequence of
0473  * endpoints. It does this by repeated calls to the socket's @c connect member
0474  * function, once for each endpoint in the sequence, until a connection is
0475  * successfully established.
0476  *
0477  * @param s The socket to be connected. If the socket is already open, it will
0478  * be closed.
0479  *
0480  * @param begin An iterator pointing to the start of a sequence of endpoints.
0481  *
0482  * @param end An iterator pointing to the end of a sequence of endpoints.
0483  *
0484  * @param connect_condition A function object that is called prior to each
0485  * connection attempt. The signature of the function object must be:
0486  * @code bool connect_condition(
0487  *     const boost::system::error_code& ec,
0488  *     const typename Protocol::endpoint& next); @endcode
0489  * The @c ec parameter contains the result from the most recent connect
0490  * operation. Before the first connection attempt, @c ec is always set to
0491  * indicate success. The @c next parameter is the next endpoint to be tried.
0492  * The function object should return true if the next endpoint should be tried,
0493  * and false if it should be skipped.
0494  *
0495  * @returns An iterator denoting the successfully connected endpoint.
0496  *
0497  * @throws boost::system::system_error Thrown on failure. If the sequence is
0498  * empty, the associated @c error_code is boost::asio::error::not_found.
0499  * Otherwise, contains the error from the last connection attempt.
0500  *
0501  * @par Example
0502  * The following connect condition function object can be used to output
0503  * information about the individual connection attempts:
0504  * @code struct my_connect_condition
0505  * {
0506  *   bool operator()(
0507  *       const boost::system::error_code& ec,
0508  *       const::tcp::endpoint& next)
0509  *   {
0510  *     if (ec) std::cout << "Error: " << ec.message() << std::endl;
0511  *     std::cout << "Trying: " << next << std::endl;
0512  *     return true;
0513  *   }
0514  * }; @endcode
0515  * It would be used with the boost::asio::connect function as follows:
0516  * @code tcp::resolver r(my_context);
0517  * tcp::resolver::query q("host", "service");
0518  * tcp::resolver::results_type e = r.resolve(q);
0519  * tcp::socket s(my_context);
0520  * tcp::resolver::results_type::iterator i = boost::asio::connect(
0521  *     s, e.begin(), e.end(), my_connect_condition());
0522  * std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode
0523  */
0524 template <typename Protocol, typename Executor,
0525     typename Iterator, typename ConnectCondition>
0526 Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
0527     Iterator end, ConnectCondition connect_condition);
0528 
0529 /// Establishes a socket connection by trying each endpoint in a sequence.
0530 /**
0531  * This function attempts to connect a socket to one of a sequence of
0532  * endpoints. It does this by repeated calls to the socket's @c connect member
0533  * function, once for each endpoint in the sequence, until a connection is
0534  * successfully established.
0535  *
0536  * @param s The socket to be connected. If the socket is already open, it will
0537  * be closed.
0538  *
0539  * @param begin An iterator pointing to the start of a sequence of endpoints.
0540  *
0541  * @param end An iterator pointing to the end of a sequence of endpoints.
0542  *
0543  * @param connect_condition A function object that is called prior to each
0544  * connection attempt. The signature of the function object must be:
0545  * @code bool connect_condition(
0546  *     const boost::system::error_code& ec,
0547  *     const typename Protocol::endpoint& next); @endcode
0548  * The @c ec parameter contains the result from the most recent connect
0549  * operation. Before the first connection attempt, @c ec is always set to
0550  * indicate success. The @c next parameter is the next endpoint to be tried.
0551  * The function object should return true if the next endpoint should be tried,
0552  * and false if it should be skipped.
0553  *
0554  * @param ec Set to indicate what error occurred, if any. If the sequence is
0555  * empty, set to boost::asio::error::not_found. Otherwise, contains the error
0556  * from the last connection attempt.
0557  *
0558  * @returns On success, an iterator denoting the successfully connected
0559  * endpoint. Otherwise, the end iterator.
0560  *
0561  * @par Example
0562  * The following connect condition function object can be used to output
0563  * information about the individual connection attempts:
0564  * @code struct my_connect_condition
0565  * {
0566  *   bool operator()(
0567  *       const boost::system::error_code& ec,
0568  *       const::tcp::endpoint& next)
0569  *   {
0570  *     if (ec) std::cout << "Error: " << ec.message() << std::endl;
0571  *     std::cout << "Trying: " << next << std::endl;
0572  *     return true;
0573  *   }
0574  * }; @endcode
0575  * It would be used with the boost::asio::connect function as follows:
0576  * @code tcp::resolver r(my_context);
0577  * tcp::resolver::query q("host", "service");
0578  * tcp::resolver::results_type e = r.resolve(q);
0579  * tcp::socket s(my_context);
0580  * boost::system::error_code ec;
0581  * tcp::resolver::results_type::iterator i = boost::asio::connect(
0582  *     s, e.begin(), e.end(), my_connect_condition());
0583  * if (ec)
0584  * {
0585  *   // An error occurred.
0586  * }
0587  * else
0588  * {
0589  *   std::cout << "Connected to: " << i->endpoint() << std::endl;
0590  * } @endcode
0591  */
0592 template <typename Protocol, typename Executor,
0593     typename Iterator, typename ConnectCondition>
0594 Iterator connect(basic_socket<Protocol, Executor>& s,
0595     Iterator begin, Iterator end, ConnectCondition connect_condition,
0596     boost::system::error_code& ec);
0597 
0598 /*@}*/
0599 
0600 /**
0601  * @defgroup async_connect boost::asio::async_connect
0602  *
0603  * @brief The @c async_connect function is a composed asynchronous operation
0604  * that establishes a socket connection by trying each endpoint in a sequence.
0605  */
0606 /*@{*/
0607 
0608 /// Asynchronously establishes a socket connection by trying each endpoint in a
0609 /// sequence.
0610 /**
0611  * This function attempts to connect a socket to one of a sequence of
0612  * endpoints. It does this by repeated calls to the socket's @c async_connect
0613  * member function, once for each endpoint in the sequence, until a connection
0614  * is successfully established. It is an initiating function for an @ref
0615  * asynchronous_operation, and always returns immediately.
0616  *
0617  * @param s The socket to be connected. If the socket is already open, it will
0618  * be closed.
0619  *
0620  * @param endpoints A sequence of endpoints.
0621  *
0622  * @param token The @ref completion_token that will be used to produce a
0623  * completion handler, which will be called when the connect completes.
0624  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0625  * @ref yield_context, or a function object with the correct completion
0626  * signature. The function signature of the completion handler must be:
0627  * @code void handler(
0628  *   // Result of operation. if the sequence is empty, set to
0629  *   // boost::asio::error::not_found. Otherwise, contains the
0630  *   // error from the last connection attempt.
0631  *   const boost::system::error_code& error,
0632  *
0633  *   // On success, the successfully connected endpoint.
0634  *   // Otherwise, a default-constructed endpoint.
0635  *   const typename Protocol::endpoint& endpoint
0636  * ); @endcode
0637  * Regardless of whether the asynchronous operation completes immediately or
0638  * not, the completion handler will not be invoked from within this function.
0639  * On immediate completion, invocation of the handler will be performed in a
0640  * manner equivalent to using boost::asio::post().
0641  *
0642  * @par Completion Signature
0643  * @code void(boost::system::error_code, typename Protocol::endpoint) @endcode
0644  *
0645  * @par Example
0646  * @code tcp::resolver r(my_context);
0647  * tcp::resolver::query q("host", "service");
0648  * tcp::socket s(my_context);
0649  *
0650  * // ...
0651  *
0652  * r.async_resolve(q, resolve_handler);
0653  *
0654  * // ...
0655  *
0656  * void resolve_handler(
0657  *     const boost::system::error_code& ec,
0658  *     tcp::resolver::results_type results)
0659  * {
0660  *   if (!ec)
0661  *   {
0662  *     boost::asio::async_connect(s, results, connect_handler);
0663  *   }
0664  * }
0665  *
0666  * // ...
0667  *
0668  * void connect_handler(
0669  *     const boost::system::error_code& ec,
0670  *     const tcp::endpoint& endpoint)
0671  * {
0672  *   // ...
0673  * } @endcode
0674  *
0675  * @par Per-Operation Cancellation
0676  * This asynchronous operation supports cancellation for the following
0677  * boost::asio::cancellation_type values:
0678  *
0679  * @li @c cancellation_type::terminal
0680  *
0681  * @li @c cancellation_type::partial
0682  *
0683  * if they are also supported by the socket's @c async_connect operation.
0684  */
0685 template <typename Protocol, typename Executor, typename EndpointSequence,
0686     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0687       typename Protocol::endpoint)) RangeConnectToken
0688         = default_completion_token_t<Executor>>
0689 auto async_connect(basic_socket<Protocol, Executor>& s,
0690     const EndpointSequence& endpoints,
0691     RangeConnectToken&& token = default_completion_token_t<Executor>(),
0692     constraint_t<is_endpoint_sequence<EndpointSequence>::value> = 0)
0693   -> decltype(
0694     async_initiate<RangeConnectToken,
0695       void (boost::system::error_code, typename Protocol::endpoint)>(
0696         declval<detail::initiate_async_range_connect<Protocol, Executor>>(),
0697         token, endpoints, declval<detail::default_connect_condition>()));
0698 
0699 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0700 /// (Deprecated: Use range overload.) Asynchronously establishes a socket
0701 /// connection by trying each endpoint in a sequence.
0702 /**
0703  * This function attempts to connect a socket to one of a sequence of
0704  * endpoints. It does this by repeated calls to the socket's @c async_connect
0705  * member function, once for each endpoint in the sequence, until a connection
0706  * is successfully established. It is an initiating function for an @ref
0707  * asynchronous_operation, and always returns immediately.
0708  *
0709  * @param s The socket to be connected. If the socket is already open, it will
0710  * be closed.
0711  *
0712  * @param begin An iterator pointing to the start of a sequence of endpoints.
0713  *
0714  * @param token The @ref completion_token that will be used to produce a
0715  * completion handler, which will be called when the connect completes.
0716  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0717  * @ref yield_context, or a function object with the correct completion
0718  * signature. The function signature of the completion handler must be:
0719  * @code void handler(
0720  *   // Result of operation. if the sequence is empty, set to
0721  *   // boost::asio::error::not_found. Otherwise, contains the
0722  *   // error from the last connection attempt.
0723  *   const boost::system::error_code& error,
0724  *
0725  *   // On success, an iterator denoting the successfully
0726  *   // connected endpoint. Otherwise, the end iterator.
0727  *   Iterator iterator
0728  * ); @endcode
0729  * Regardless of whether the asynchronous operation completes immediately or
0730  * not, the completion handler will not be invoked from within this function.
0731  * On immediate completion, invocation of the handler will be performed in a
0732  * manner equivalent to using boost::asio::post().
0733  *
0734  * @par Completion Signature
0735  * @code void(boost::system::error_code, Iterator) @endcode
0736  *
0737  * @note This overload assumes that a default constructed object of type @c
0738  * Iterator represents the end of the sequence. This is a valid assumption for
0739  * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
0740  *
0741  * @par Per-Operation Cancellation
0742  * This asynchronous operation supports cancellation for the following
0743  * boost::asio::cancellation_type values:
0744  *
0745  * @li @c cancellation_type::terminal
0746  *
0747  * @li @c cancellation_type::partial
0748  *
0749  * if they are also supported by the socket's @c async_connect operation.
0750  */
0751 template <typename Protocol, typename Executor, typename Iterator,
0752     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0753       Iterator)) IteratorConnectToken = default_completion_token_t<Executor>>
0754 auto async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
0755     IteratorConnectToken&& token = default_completion_token_t<Executor>(),
0756     constraint_t<!is_endpoint_sequence<Iterator>::value> = 0)
0757   -> decltype(
0758     async_initiate<IteratorConnectToken,
0759       void (boost::system::error_code, Iterator)>(
0760         declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
0761         token, begin, Iterator(),
0762         declval<detail::default_connect_condition>()));
0763 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
0764 
0765 /// Asynchronously establishes a socket connection by trying each endpoint in a
0766 /// sequence.
0767 /**
0768  * This function attempts to connect a socket to one of a sequence of
0769  * endpoints. It does this by repeated calls to the socket's @c async_connect
0770  * member function, once for each endpoint in the sequence, until a connection
0771  * is successfully established. It is an initiating function for an @ref
0772  * asynchronous_operation, and always returns immediately.
0773  *
0774  * @param s The socket to be connected. If the socket is already open, it will
0775  * be closed.
0776  *
0777  * @param begin An iterator pointing to the start of a sequence of endpoints.
0778  *
0779  * @param end An iterator pointing to the end of a sequence of endpoints.
0780  *
0781  * @param token The @ref completion_token that will be used to produce a
0782  * completion handler, which will be called when the connect completes.
0783  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0784  * @ref yield_context, or a function object with the correct completion
0785  * signature. The function signature of the completion handler must be:
0786  * @code void handler(
0787  *   // Result of operation. if the sequence is empty, set to
0788  *   // boost::asio::error::not_found. Otherwise, contains the
0789  *   // error from the last connection attempt.
0790  *   const boost::system::error_code& error,
0791  *
0792  *   // On success, an iterator denoting the successfully
0793  *   // connected endpoint. Otherwise, the end iterator.
0794  *   Iterator iterator
0795  * ); @endcode
0796  * Regardless of whether the asynchronous operation completes immediately or
0797  * not, the completion handler will not be invoked from within this function.
0798  * On immediate completion, invocation of the handler will be performed in a
0799  * manner equivalent to using boost::asio::post().
0800  *
0801  * @par Completion Signature
0802  * @code void(boost::system::error_code, Iterator) @endcode
0803  *
0804  * @par Example
0805  * @code std::vector<tcp::endpoint> endpoints = ...;
0806  * tcp::socket s(my_context);
0807  * boost::asio::async_connect(s,
0808  *     endpoints.begin(), endpoints.end(),
0809  *     connect_handler);
0810  *
0811  * // ...
0812  *
0813  * void connect_handler(
0814  *     const boost::system::error_code& ec,
0815  *     std::vector<tcp::endpoint>::iterator i)
0816  * {
0817  *   // ...
0818  * } @endcode
0819  *
0820  * @par Per-Operation Cancellation
0821  * This asynchronous operation supports cancellation for the following
0822  * boost::asio::cancellation_type values:
0823  *
0824  * @li @c cancellation_type::terminal
0825  *
0826  * @li @c cancellation_type::partial
0827  *
0828  * if they are also supported by the socket's @c async_connect operation.
0829  */
0830 template <typename Protocol, typename Executor, typename Iterator,
0831     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0832       Iterator)) IteratorConnectToken = default_completion_token_t<Executor>>
0833 auto async_connect(
0834     basic_socket<Protocol, Executor>& s, Iterator begin, Iterator end,
0835     IteratorConnectToken&& token = default_completion_token_t<Executor>())
0836   -> decltype(
0837     async_initiate<IteratorConnectToken,
0838       void (boost::system::error_code, Iterator)>(
0839         declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
0840         token, begin, end, declval<detail::default_connect_condition>()));
0841 
0842 /// Asynchronously establishes a socket connection by trying each endpoint in a
0843 /// sequence.
0844 /**
0845  * This function attempts to connect a socket to one of a sequence of
0846  * endpoints. It does this by repeated calls to the socket's @c async_connect
0847  * member function, once for each endpoint in the sequence, until a connection
0848  * is successfully established. It is an initiating function for an @ref
0849  * asynchronous_operation, and always returns immediately.
0850  *
0851  * @param s The socket to be connected. If the socket is already open, it will
0852  * be closed.
0853  *
0854  * @param endpoints A sequence of endpoints.
0855  *
0856  * @param connect_condition A function object that is called prior to each
0857  * connection attempt. The signature of the function object must be:
0858  * @code bool connect_condition(
0859  *     const boost::system::error_code& ec,
0860  *     const typename Protocol::endpoint& next); @endcode
0861  * The @c ec parameter contains the result from the most recent connect
0862  * operation. Before the first connection attempt, @c ec is always set to
0863  * indicate success. The @c next parameter is the next endpoint to be tried.
0864  * The function object should return true if the next endpoint should be tried,
0865  * and false if it should be skipped.
0866  *
0867  * @param token The @ref completion_token that will be used to produce a
0868  * completion handler, which will be called when the connect completes.
0869  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0870  * @ref yield_context, or a function object with the correct completion
0871  * signature. The function signature of the completion handler must be:
0872  * @code void handler(
0873  *   // Result of operation. if the sequence is empty, set to
0874  *   // boost::asio::error::not_found. Otherwise, contains the
0875  *   // error from the last connection attempt.
0876  *   const boost::system::error_code& error,
0877  *
0878  *   // On success, an iterator denoting the successfully
0879  *   // connected endpoint. Otherwise, the end iterator.
0880  *   Iterator iterator
0881  * ); @endcode
0882  * Regardless of whether the asynchronous operation completes immediately or
0883  * not, the completion handler will not be invoked from within this function.
0884  * On immediate completion, invocation of the handler will be performed in a
0885  * manner equivalent to using boost::asio::post().
0886  *
0887  * @par Completion Signature
0888  * @code void(boost::system::error_code, typename Protocol::endpoint) @endcode
0889  *
0890  * @par Example
0891  * The following connect condition function object can be used to output
0892  * information about the individual connection attempts:
0893  * @code struct my_connect_condition
0894  * {
0895  *   bool operator()(
0896  *       const boost::system::error_code& ec,
0897  *       const::tcp::endpoint& next)
0898  *   {
0899  *     if (ec) std::cout << "Error: " << ec.message() << std::endl;
0900  *     std::cout << "Trying: " << next << std::endl;
0901  *     return true;
0902  *   }
0903  * }; @endcode
0904  * It would be used with the boost::asio::connect function as follows:
0905  * @code tcp::resolver r(my_context);
0906  * tcp::resolver::query q("host", "service");
0907  * tcp::socket s(my_context);
0908  *
0909  * // ...
0910  *
0911  * r.async_resolve(q, resolve_handler);
0912  *
0913  * // ...
0914  *
0915  * void resolve_handler(
0916  *     const boost::system::error_code& ec,
0917  *     tcp::resolver::results_type results)
0918  * {
0919  *   if (!ec)
0920  *   {
0921  *     boost::asio::async_connect(s, results,
0922  *         my_connect_condition(),
0923  *         connect_handler);
0924  *   }
0925  * }
0926  *
0927  * // ...
0928  *
0929  * void connect_handler(
0930  *     const boost::system::error_code& ec,
0931  *     const tcp::endpoint& endpoint)
0932  * {
0933  *   if (ec)
0934  *   {
0935  *     // An error occurred.
0936  *   }
0937  *   else
0938  *   {
0939  *     std::cout << "Connected to: " << endpoint << std::endl;
0940  *   }
0941  * } @endcode
0942  *
0943  * @par Per-Operation Cancellation
0944  * This asynchronous operation supports cancellation for the following
0945  * boost::asio::cancellation_type values:
0946  *
0947  * @li @c cancellation_type::terminal
0948  *
0949  * @li @c cancellation_type::partial
0950  *
0951  * if they are also supported by the socket's @c async_connect operation.
0952  */
0953 template <typename Protocol, typename Executor,
0954     typename EndpointSequence, typename ConnectCondition,
0955     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0956       typename Protocol::endpoint)) RangeConnectToken
0957         = default_completion_token_t<Executor>>
0958 auto async_connect(basic_socket<Protocol, Executor>& s,
0959     const EndpointSequence& endpoints, ConnectCondition connect_condition,
0960     RangeConnectToken&& token = default_completion_token_t<Executor>(),
0961     constraint_t<is_endpoint_sequence<EndpointSequence>::value> = 0)
0962   -> decltype(
0963     async_initiate<RangeConnectToken,
0964       void (boost::system::error_code, typename Protocol::endpoint)>(
0965         declval<detail::initiate_async_range_connect<Protocol, Executor>>(),
0966         token, endpoints, connect_condition));
0967 
0968 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0969 /// (Deprecated: Use range overload.) Asynchronously establishes a socket
0970 /// connection by trying each endpoint in a sequence.
0971 /**
0972  * This function attempts to connect a socket to one of a sequence of
0973  * endpoints. It does this by repeated calls to the socket's @c async_connect
0974  * member function, once for each endpoint in the sequence, until a connection
0975  * is successfully established. It is an initiating function for an @ref
0976  * asynchronous_operation, and always returns immediately.
0977  *
0978  * @param s The socket to be connected. If the socket is already open, it will
0979  * be closed.
0980  *
0981  * @param begin An iterator pointing to the start of a sequence of endpoints.
0982  *
0983  * @param connect_condition A function object that is called prior to each
0984  * connection attempt. The signature of the function object must be:
0985  * @code bool connect_condition(
0986  *     const boost::system::error_code& ec,
0987  *     const typename Protocol::endpoint& next); @endcode
0988  * The @c ec parameter contains the result from the most recent connect
0989  * operation. Before the first connection attempt, @c ec is always set to
0990  * indicate success. The @c next parameter is the next endpoint to be tried.
0991  * The function object should return true if the next endpoint should be tried,
0992  * and false if it should be skipped.
0993  *
0994  * @param token The @ref completion_token that will be used to produce a
0995  * completion handler, which will be called when the connect completes.
0996  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0997  * @ref yield_context, or a function object with the correct completion
0998  * signature. The function signature of the completion handler must be:
0999  * @code void handler(
1000  *   // Result of operation. if the sequence is empty, set to
1001  *   // boost::asio::error::not_found. Otherwise, contains the
1002  *   // error from the last connection attempt.
1003  *   const boost::system::error_code& error,
1004  *
1005  *   // On success, an iterator denoting the successfully
1006  *   // connected endpoint. Otherwise, the end iterator.
1007  *   Iterator iterator
1008  * ); @endcode
1009  * Regardless of whether the asynchronous operation completes immediately or
1010  * not, the completion handler will not be invoked from within this function.
1011  * On immediate completion, invocation of the handler will be performed in a
1012  * manner equivalent to using boost::asio::post().
1013  *
1014  * @par Completion Signature
1015  * @code void(boost::system::error_code, Iterator) @endcode
1016  *
1017  * @note This overload assumes that a default constructed object of type @c
1018  * Iterator represents the end of the sequence. This is a valid assumption for
1019  * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
1020  *
1021  * @par Per-Operation Cancellation
1022  * This asynchronous operation supports cancellation for the following
1023  * boost::asio::cancellation_type values:
1024  *
1025  * @li @c cancellation_type::terminal
1026  *
1027  * @li @c cancellation_type::partial
1028  *
1029  * if they are also supported by the socket's @c async_connect operation.
1030  */
1031 template <typename Protocol, typename Executor,
1032     typename Iterator, typename ConnectCondition,
1033     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1034       Iterator)) IteratorConnectToken = default_completion_token_t<Executor>>
1035 auto async_connect(basic_socket<Protocol, Executor>& s,
1036     Iterator begin, ConnectCondition connect_condition,
1037     IteratorConnectToken&& token = default_completion_token_t<Executor>(),
1038     constraint_t<!is_endpoint_sequence<Iterator>::value> = 0)
1039   -> decltype(
1040     async_initiate<IteratorConnectToken,
1041       void (boost::system::error_code, Iterator)>(
1042         declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
1043         token, begin, Iterator(), connect_condition));
1044 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
1045 
1046 /// Asynchronously establishes a socket connection by trying each endpoint in a
1047 /// sequence.
1048 /**
1049  * This function attempts to connect a socket to one of a sequence of
1050  * endpoints. It does this by repeated calls to the socket's @c async_connect
1051  * member function, once for each endpoint in the sequence, until a connection
1052  * is successfully established. It is an initiating function for an @ref
1053  * asynchronous_operation, and always returns immediately.
1054  *
1055  * @param s The socket to be connected. If the socket is already open, it will
1056  * be closed.
1057  *
1058  * @param begin An iterator pointing to the start of a sequence of endpoints.
1059  *
1060  * @param end An iterator pointing to the end of a sequence of endpoints.
1061  *
1062  * @param connect_condition A function object that is called prior to each
1063  * connection attempt. The signature of the function object must be:
1064  * @code bool connect_condition(
1065  *     const boost::system::error_code& ec,
1066  *     const typename Protocol::endpoint& next); @endcode
1067  * The @c ec parameter contains the result from the most recent connect
1068  * operation. Before the first connection attempt, @c ec is always set to
1069  * indicate success. The @c next parameter is the next endpoint to be tried.
1070  * The function object should return true if the next endpoint should be tried,
1071  * and false if it should be skipped.
1072  *
1073  * @param token The @ref completion_token that will be used to produce a
1074  * completion handler, which will be called when the connect completes.
1075  * Potential completion tokens include @ref use_future, @ref use_awaitable,
1076  * @ref yield_context, or a function object with the correct completion
1077  * signature. The function signature of the completion handler must be:
1078  * @code void handler(
1079  *   // Result of operation. if the sequence is empty, set to
1080  *   // boost::asio::error::not_found. Otherwise, contains the
1081  *   // error from the last connection attempt.
1082  *   const boost::system::error_code& error,
1083  *
1084  *   // On success, an iterator denoting the successfully
1085  *   // connected endpoint. Otherwise, the end iterator.
1086  *   Iterator iterator
1087  * ); @endcode
1088  * Regardless of whether the asynchronous operation completes immediately or
1089  * not, the completion handler will not be invoked from within this function.
1090  * On immediate completion, invocation of the handler will be performed in a
1091  * manner equivalent to using boost::asio::post().
1092  *
1093  * @par Completion Signature
1094  * @code void(boost::system::error_code, Iterator) @endcode
1095  *
1096  * @par Example
1097  * The following connect condition function object can be used to output
1098  * information about the individual connection attempts:
1099  * @code struct my_connect_condition
1100  * {
1101  *   bool operator()(
1102  *       const boost::system::error_code& ec,
1103  *       const::tcp::endpoint& next)
1104  *   {
1105  *     if (ec) std::cout << "Error: " << ec.message() << std::endl;
1106  *     std::cout << "Trying: " << next << std::endl;
1107  *     return true;
1108  *   }
1109  * }; @endcode
1110  * It would be used with the boost::asio::connect function as follows:
1111  * @code tcp::resolver r(my_context);
1112  * tcp::resolver::query q("host", "service");
1113  * tcp::socket s(my_context);
1114  *
1115  * // ...
1116  *
1117  * r.async_resolve(q, resolve_handler);
1118  *
1119  * // ...
1120  *
1121  * void resolve_handler(
1122  *     const boost::system::error_code& ec,
1123  *     tcp::resolver::iterator i)
1124  * {
1125  *   if (!ec)
1126  *   {
1127  *     tcp::resolver::iterator end;
1128  *     boost::asio::async_connect(s, i, end,
1129  *         my_connect_condition(),
1130  *         connect_handler);
1131  *   }
1132  * }
1133  *
1134  * // ...
1135  *
1136  * void connect_handler(
1137  *     const boost::system::error_code& ec,
1138  *     tcp::resolver::iterator i)
1139  * {
1140  *   if (ec)
1141  *   {
1142  *     // An error occurred.
1143  *   }
1144  *   else
1145  *   {
1146  *     std::cout << "Connected to: " << i->endpoint() << std::endl;
1147  *   }
1148  * } @endcode
1149  *
1150  * @par Per-Operation Cancellation
1151  * This asynchronous operation supports cancellation for the following
1152  * boost::asio::cancellation_type values:
1153  *
1154  * @li @c cancellation_type::terminal
1155  *
1156  * @li @c cancellation_type::partial
1157  *
1158  * if they are also supported by the socket's @c async_connect operation.
1159  */
1160 template <typename Protocol, typename Executor,
1161     typename Iterator, typename ConnectCondition,
1162     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1163       Iterator)) IteratorConnectToken = default_completion_token_t<Executor>>
1164 auto async_connect(basic_socket<Protocol, Executor>& s,
1165     Iterator begin, Iterator end, ConnectCondition connect_condition,
1166     IteratorConnectToken&& token = default_completion_token_t<Executor>())
1167   -> decltype(
1168     async_initiate<IteratorConnectToken,
1169       void (boost::system::error_code, Iterator)>(
1170         declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
1171         token, begin, end, connect_condition));
1172 
1173 /*@}*/
1174 
1175 } // namespace asio
1176 } // namespace boost
1177 
1178 #include <boost/asio/detail/pop_options.hpp>
1179 
1180 #include <boost/asio/impl/connect.hpp>
1181 
1182 #endif