annotate DEPENDENCIES/generic/include/boost/asio/connect.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // connect.hpp
Chris@16 3 // ~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_CONNECT_HPP
Chris@16 12 #define BOOST_ASIO_CONNECT_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19 #include <boost/asio/async_result.hpp>
Chris@16 20 #include <boost/asio/basic_socket.hpp>
Chris@16 21 #include <boost/asio/error.hpp>
Chris@16 22
Chris@16 23 #include <boost/asio/detail/push_options.hpp>
Chris@16 24
Chris@16 25 namespace boost {
Chris@16 26 namespace asio {
Chris@16 27
Chris@16 28 /**
Chris@16 29 * @defgroup connect boost::asio::connect
Chris@16 30 *
Chris@16 31 * @brief Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 32 */
Chris@16 33 /*@{*/
Chris@16 34
Chris@16 35 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 36 /**
Chris@16 37 * This function attempts to connect a socket to one of a sequence of
Chris@16 38 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 39 * function, once for each endpoint in the sequence, until a connection is
Chris@16 40 * successfully established.
Chris@16 41 *
Chris@16 42 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 43 * be closed.
Chris@16 44 *
Chris@16 45 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 46 *
Chris@16 47 * @returns On success, an iterator denoting the successfully connected
Chris@16 48 * endpoint. Otherwise, the end iterator.
Chris@16 49 *
Chris@16 50 * @throws boost::system::system_error Thrown on failure. If the sequence is
Chris@16 51 * empty, the associated @c error_code is boost::asio::error::not_found.
Chris@16 52 * Otherwise, contains the error from the last connection attempt.
Chris@16 53 *
Chris@16 54 * @note This overload assumes that a default constructed object of type @c
Chris@16 55 * Iterator represents the end of the sequence. This is a valid assumption for
Chris@16 56 * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
Chris@16 57 *
Chris@16 58 * @par Example
Chris@16 59 * @code tcp::resolver r(io_service);
Chris@16 60 * tcp::resolver::query q("host", "service");
Chris@16 61 * tcp::socket s(io_service);
Chris@16 62 * boost::asio::connect(s, r.resolve(q)); @endcode
Chris@16 63 */
Chris@16 64 template <typename Protocol, typename SocketService, typename Iterator>
Chris@16 65 Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin);
Chris@16 66
Chris@16 67 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 68 /**
Chris@16 69 * This function attempts to connect a socket to one of a sequence of
Chris@16 70 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 71 * function, once for each endpoint in the sequence, until a connection is
Chris@16 72 * successfully established.
Chris@16 73 *
Chris@16 74 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 75 * be closed.
Chris@16 76 *
Chris@16 77 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 78 *
Chris@16 79 * @param ec Set to indicate what error occurred, if any. If the sequence is
Chris@16 80 * empty, set to boost::asio::error::not_found. Otherwise, contains the error
Chris@16 81 * from the last connection attempt.
Chris@16 82 *
Chris@16 83 * @returns On success, an iterator denoting the successfully connected
Chris@16 84 * endpoint. Otherwise, the end iterator.
Chris@16 85 *
Chris@16 86 * @note This overload assumes that a default constructed object of type @c
Chris@16 87 * Iterator represents the end of the sequence. This is a valid assumption for
Chris@16 88 * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
Chris@16 89 *
Chris@16 90 * @par Example
Chris@16 91 * @code tcp::resolver r(io_service);
Chris@16 92 * tcp::resolver::query q("host", "service");
Chris@16 93 * tcp::socket s(io_service);
Chris@16 94 * boost::system::error_code ec;
Chris@16 95 * boost::asio::connect(s, r.resolve(q), ec);
Chris@16 96 * if (ec)
Chris@16 97 * {
Chris@16 98 * // An error occurred.
Chris@16 99 * } @endcode
Chris@16 100 */
Chris@16 101 template <typename Protocol, typename SocketService, typename Iterator>
Chris@16 102 Iterator connect(basic_socket<Protocol, SocketService>& s,
Chris@16 103 Iterator begin, boost::system::error_code& ec);
Chris@16 104
Chris@16 105 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 106 /**
Chris@16 107 * This function attempts to connect a socket to one of a sequence of
Chris@16 108 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 109 * function, once for each endpoint in the sequence, until a connection is
Chris@16 110 * successfully established.
Chris@16 111 *
Chris@16 112 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 113 * be closed.
Chris@16 114 *
Chris@16 115 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 116 *
Chris@16 117 * @param end An iterator pointing to the end of a sequence of endpoints.
Chris@16 118 *
Chris@16 119 * @returns On success, an iterator denoting the successfully connected
Chris@16 120 * endpoint. Otherwise, the end iterator.
Chris@16 121 *
Chris@16 122 * @throws boost::system::system_error Thrown on failure. If the sequence is
Chris@16 123 * empty, the associated @c error_code is boost::asio::error::not_found.
Chris@16 124 * Otherwise, contains the error from the last connection attempt.
Chris@16 125 *
Chris@16 126 * @par Example
Chris@16 127 * @code tcp::resolver r(io_service);
Chris@16 128 * tcp::resolver::query q("host", "service");
Chris@16 129 * tcp::resolver::iterator i = r.resolve(q), end;
Chris@16 130 * tcp::socket s(io_service);
Chris@16 131 * boost::asio::connect(s, i, end); @endcode
Chris@16 132 */
Chris@16 133 template <typename Protocol, typename SocketService, typename Iterator>
Chris@16 134 Iterator connect(basic_socket<Protocol, SocketService>& s,
Chris@16 135 Iterator begin, Iterator end);
Chris@16 136
Chris@16 137 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 138 /**
Chris@16 139 * This function attempts to connect a socket to one of a sequence of
Chris@16 140 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 141 * function, once for each endpoint in the sequence, until a connection is
Chris@16 142 * successfully established.
Chris@16 143 *
Chris@16 144 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 145 * be closed.
Chris@16 146 *
Chris@16 147 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 148 *
Chris@16 149 * @param end An iterator pointing to the end of a sequence of endpoints.
Chris@16 150 *
Chris@16 151 * @param ec Set to indicate what error occurred, if any. If the sequence is
Chris@16 152 * empty, set to boost::asio::error::not_found. Otherwise, contains the error
Chris@16 153 * from the last connection attempt.
Chris@16 154 *
Chris@16 155 * @returns On success, an iterator denoting the successfully connected
Chris@16 156 * endpoint. Otherwise, the end iterator.
Chris@16 157 *
Chris@16 158 * @par Example
Chris@16 159 * @code tcp::resolver r(io_service);
Chris@16 160 * tcp::resolver::query q("host", "service");
Chris@16 161 * tcp::resolver::iterator i = r.resolve(q), end;
Chris@16 162 * tcp::socket s(io_service);
Chris@16 163 * boost::system::error_code ec;
Chris@16 164 * boost::asio::connect(s, i, end, ec);
Chris@16 165 * if (ec)
Chris@16 166 * {
Chris@16 167 * // An error occurred.
Chris@16 168 * } @endcode
Chris@16 169 */
Chris@16 170 template <typename Protocol, typename SocketService, typename Iterator>
Chris@16 171 Iterator connect(basic_socket<Protocol, SocketService>& s,
Chris@16 172 Iterator begin, Iterator end, boost::system::error_code& ec);
Chris@16 173
Chris@16 174 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 175 /**
Chris@16 176 * This function attempts to connect a socket to one of a sequence of
Chris@16 177 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 178 * function, once for each endpoint in the sequence, until a connection is
Chris@16 179 * successfully established.
Chris@16 180 *
Chris@16 181 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 182 * be closed.
Chris@16 183 *
Chris@16 184 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 185 *
Chris@16 186 * @param connect_condition A function object that is called prior to each
Chris@16 187 * connection attempt. The signature of the function object must be:
Chris@16 188 * @code Iterator connect_condition(
Chris@16 189 * const boost::system::error_code& ec,
Chris@16 190 * Iterator next); @endcode
Chris@16 191 * The @c ec parameter contains the result from the most recent connect
Chris@16 192 * operation. Before the first connection attempt, @c ec is always set to
Chris@16 193 * indicate success. The @c next parameter is an iterator pointing to the next
Chris@16 194 * endpoint to be tried. The function object should return the next iterator,
Chris@16 195 * but is permitted to return a different iterator so that endpoints may be
Chris@16 196 * skipped. The implementation guarantees that the function object will never
Chris@16 197 * be called with the end iterator.
Chris@16 198 *
Chris@16 199 * @returns On success, an iterator denoting the successfully connected
Chris@16 200 * endpoint. Otherwise, the end iterator.
Chris@16 201 *
Chris@16 202 * @throws boost::system::system_error Thrown on failure. If the sequence is
Chris@16 203 * empty, the associated @c error_code is boost::asio::error::not_found.
Chris@16 204 * Otherwise, contains the error from the last connection attempt.
Chris@16 205 *
Chris@16 206 * @note This overload assumes that a default constructed object of type @c
Chris@16 207 * Iterator represents the end of the sequence. This is a valid assumption for
Chris@16 208 * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
Chris@16 209 *
Chris@16 210 * @par Example
Chris@16 211 * The following connect condition function object can be used to output
Chris@16 212 * information about the individual connection attempts:
Chris@16 213 * @code struct my_connect_condition
Chris@16 214 * {
Chris@16 215 * template <typename Iterator>
Chris@16 216 * Iterator operator()(
Chris@16 217 * const boost::system::error_code& ec,
Chris@16 218 * Iterator next)
Chris@16 219 * {
Chris@16 220 * if (ec) std::cout << "Error: " << ec.message() << std::endl;
Chris@16 221 * std::cout << "Trying: " << next->endpoint() << std::endl;
Chris@16 222 * return next;
Chris@16 223 * }
Chris@16 224 * }; @endcode
Chris@16 225 * It would be used with the boost::asio::connect function as follows:
Chris@16 226 * @code tcp::resolver r(io_service);
Chris@16 227 * tcp::resolver::query q("host", "service");
Chris@16 228 * tcp::socket s(io_service);
Chris@16 229 * tcp::resolver::iterator i = boost::asio::connect(
Chris@16 230 * s, r.resolve(q), my_connect_condition());
Chris@16 231 * std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode
Chris@16 232 */
Chris@16 233 template <typename Protocol, typename SocketService,
Chris@16 234 typename Iterator, typename ConnectCondition>
Chris@16 235 Iterator connect(basic_socket<Protocol, SocketService>& s,
Chris@16 236 Iterator begin, ConnectCondition connect_condition);
Chris@16 237
Chris@16 238 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 239 /**
Chris@16 240 * This function attempts to connect a socket to one of a sequence of
Chris@16 241 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 242 * function, once for each endpoint in the sequence, until a connection is
Chris@16 243 * successfully established.
Chris@16 244 *
Chris@16 245 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 246 * be closed.
Chris@16 247 *
Chris@16 248 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 249 *
Chris@16 250 * @param connect_condition A function object that is called prior to each
Chris@16 251 * connection attempt. The signature of the function object must be:
Chris@16 252 * @code Iterator connect_condition(
Chris@16 253 * const boost::system::error_code& ec,
Chris@16 254 * Iterator next); @endcode
Chris@16 255 * The @c ec parameter contains the result from the most recent connect
Chris@16 256 * operation. Before the first connection attempt, @c ec is always set to
Chris@16 257 * indicate success. The @c next parameter is an iterator pointing to the next
Chris@16 258 * endpoint to be tried. The function object should return the next iterator,
Chris@16 259 * but is permitted to return a different iterator so that endpoints may be
Chris@16 260 * skipped. The implementation guarantees that the function object will never
Chris@16 261 * be called with the end iterator.
Chris@16 262 *
Chris@16 263 * @param ec Set to indicate what error occurred, if any. If the sequence is
Chris@16 264 * empty, set to boost::asio::error::not_found. Otherwise, contains the error
Chris@16 265 * from the last connection attempt.
Chris@16 266 *
Chris@16 267 * @returns On success, an iterator denoting the successfully connected
Chris@16 268 * endpoint. Otherwise, the end iterator.
Chris@16 269 *
Chris@16 270 * @note This overload assumes that a default constructed object of type @c
Chris@16 271 * Iterator represents the end of the sequence. This is a valid assumption for
Chris@16 272 * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
Chris@16 273 *
Chris@16 274 * @par Example
Chris@16 275 * The following connect condition function object can be used to output
Chris@16 276 * information about the individual connection attempts:
Chris@16 277 * @code struct my_connect_condition
Chris@16 278 * {
Chris@16 279 * template <typename Iterator>
Chris@16 280 * Iterator operator()(
Chris@16 281 * const boost::system::error_code& ec,
Chris@16 282 * Iterator next)
Chris@16 283 * {
Chris@16 284 * if (ec) std::cout << "Error: " << ec.message() << std::endl;
Chris@16 285 * std::cout << "Trying: " << next->endpoint() << std::endl;
Chris@16 286 * return next;
Chris@16 287 * }
Chris@16 288 * }; @endcode
Chris@16 289 * It would be used with the boost::asio::connect function as follows:
Chris@16 290 * @code tcp::resolver r(io_service);
Chris@16 291 * tcp::resolver::query q("host", "service");
Chris@16 292 * tcp::socket s(io_service);
Chris@16 293 * boost::system::error_code ec;
Chris@16 294 * tcp::resolver::iterator i = boost::asio::connect(
Chris@16 295 * s, r.resolve(q), my_connect_condition(), ec);
Chris@16 296 * if (ec)
Chris@16 297 * {
Chris@16 298 * // An error occurred.
Chris@16 299 * }
Chris@16 300 * else
Chris@16 301 * {
Chris@16 302 * std::cout << "Connected to: " << i->endpoint() << std::endl;
Chris@16 303 * } @endcode
Chris@16 304 */
Chris@16 305 template <typename Protocol, typename SocketService,
Chris@16 306 typename Iterator, typename ConnectCondition>
Chris@16 307 Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
Chris@16 308 ConnectCondition connect_condition, boost::system::error_code& ec);
Chris@16 309
Chris@16 310 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 311 /**
Chris@16 312 * This function attempts to connect a socket to one of a sequence of
Chris@16 313 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 314 * function, once for each endpoint in the sequence, until a connection is
Chris@16 315 * successfully established.
Chris@16 316 *
Chris@16 317 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 318 * be closed.
Chris@16 319 *
Chris@16 320 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 321 *
Chris@16 322 * @param end An iterator pointing to the end of a sequence of endpoints.
Chris@16 323 *
Chris@16 324 * @param connect_condition A function object that is called prior to each
Chris@16 325 * connection attempt. The signature of the function object must be:
Chris@16 326 * @code Iterator connect_condition(
Chris@16 327 * const boost::system::error_code& ec,
Chris@16 328 * Iterator next); @endcode
Chris@16 329 * The @c ec parameter contains the result from the most recent connect
Chris@16 330 * operation. Before the first connection attempt, @c ec is always set to
Chris@16 331 * indicate success. The @c next parameter is an iterator pointing to the next
Chris@16 332 * endpoint to be tried. The function object should return the next iterator,
Chris@16 333 * but is permitted to return a different iterator so that endpoints may be
Chris@16 334 * skipped. The implementation guarantees that the function object will never
Chris@16 335 * be called with the end iterator.
Chris@16 336 *
Chris@16 337 * @returns On success, an iterator denoting the successfully connected
Chris@16 338 * endpoint. Otherwise, the end iterator.
Chris@16 339 *
Chris@16 340 * @throws boost::system::system_error Thrown on failure. If the sequence is
Chris@16 341 * empty, the associated @c error_code is boost::asio::error::not_found.
Chris@16 342 * Otherwise, contains the error from the last connection attempt.
Chris@16 343 *
Chris@16 344 * @par Example
Chris@16 345 * The following connect condition function object can be used to output
Chris@16 346 * information about the individual connection attempts:
Chris@16 347 * @code struct my_connect_condition
Chris@16 348 * {
Chris@16 349 * template <typename Iterator>
Chris@16 350 * Iterator operator()(
Chris@16 351 * const boost::system::error_code& ec,
Chris@16 352 * Iterator next)
Chris@16 353 * {
Chris@16 354 * if (ec) std::cout << "Error: " << ec.message() << std::endl;
Chris@16 355 * std::cout << "Trying: " << next->endpoint() << std::endl;
Chris@16 356 * return next;
Chris@16 357 * }
Chris@16 358 * }; @endcode
Chris@16 359 * It would be used with the boost::asio::connect function as follows:
Chris@16 360 * @code tcp::resolver r(io_service);
Chris@16 361 * tcp::resolver::query q("host", "service");
Chris@16 362 * tcp::resolver::iterator i = r.resolve(q), end;
Chris@16 363 * tcp::socket s(io_service);
Chris@16 364 * i = boost::asio::connect(s, i, end, my_connect_condition());
Chris@16 365 * std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode
Chris@16 366 */
Chris@16 367 template <typename Protocol, typename SocketService,
Chris@16 368 typename Iterator, typename ConnectCondition>
Chris@16 369 Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
Chris@16 370 Iterator end, ConnectCondition connect_condition);
Chris@16 371
Chris@16 372 /// Establishes a socket connection by trying each endpoint in a sequence.
Chris@16 373 /**
Chris@16 374 * This function attempts to connect a socket to one of a sequence of
Chris@16 375 * endpoints. It does this by repeated calls to the socket's @c connect member
Chris@16 376 * function, once for each endpoint in the sequence, until a connection is
Chris@16 377 * successfully established.
Chris@16 378 *
Chris@16 379 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 380 * be closed.
Chris@16 381 *
Chris@16 382 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 383 *
Chris@16 384 * @param end An iterator pointing to the end of a sequence of endpoints.
Chris@16 385 *
Chris@16 386 * @param connect_condition A function object that is called prior to each
Chris@16 387 * connection attempt. The signature of the function object must be:
Chris@16 388 * @code Iterator connect_condition(
Chris@16 389 * const boost::system::error_code& ec,
Chris@16 390 * Iterator next); @endcode
Chris@16 391 * The @c ec parameter contains the result from the most recent connect
Chris@16 392 * operation. Before the first connection attempt, @c ec is always set to
Chris@16 393 * indicate success. The @c next parameter is an iterator pointing to the next
Chris@16 394 * endpoint to be tried. The function object should return the next iterator,
Chris@16 395 * but is permitted to return a different iterator so that endpoints may be
Chris@16 396 * skipped. The implementation guarantees that the function object will never
Chris@16 397 * be called with the end iterator.
Chris@16 398 *
Chris@16 399 * @param ec Set to indicate what error occurred, if any. If the sequence is
Chris@16 400 * empty, set to boost::asio::error::not_found. Otherwise, contains the error
Chris@16 401 * from the last connection attempt.
Chris@16 402 *
Chris@16 403 * @returns On success, an iterator denoting the successfully connected
Chris@16 404 * endpoint. Otherwise, the end iterator.
Chris@16 405 *
Chris@16 406 * @par Example
Chris@16 407 * The following connect condition function object can be used to output
Chris@16 408 * information about the individual connection attempts:
Chris@16 409 * @code struct my_connect_condition
Chris@16 410 * {
Chris@16 411 * template <typename Iterator>
Chris@16 412 * Iterator operator()(
Chris@16 413 * const boost::system::error_code& ec,
Chris@16 414 * Iterator next)
Chris@16 415 * {
Chris@16 416 * if (ec) std::cout << "Error: " << ec.message() << std::endl;
Chris@16 417 * std::cout << "Trying: " << next->endpoint() << std::endl;
Chris@16 418 * return next;
Chris@16 419 * }
Chris@16 420 * }; @endcode
Chris@16 421 * It would be used with the boost::asio::connect function as follows:
Chris@16 422 * @code tcp::resolver r(io_service);
Chris@16 423 * tcp::resolver::query q("host", "service");
Chris@16 424 * tcp::resolver::iterator i = r.resolve(q), end;
Chris@16 425 * tcp::socket s(io_service);
Chris@16 426 * boost::system::error_code ec;
Chris@16 427 * i = boost::asio::connect(s, i, end, my_connect_condition(), ec);
Chris@16 428 * if (ec)
Chris@16 429 * {
Chris@16 430 * // An error occurred.
Chris@16 431 * }
Chris@16 432 * else
Chris@16 433 * {
Chris@16 434 * std::cout << "Connected to: " << i->endpoint() << std::endl;
Chris@16 435 * } @endcode
Chris@16 436 */
Chris@16 437 template <typename Protocol, typename SocketService,
Chris@16 438 typename Iterator, typename ConnectCondition>
Chris@16 439 Iterator connect(basic_socket<Protocol, SocketService>& s,
Chris@16 440 Iterator begin, Iterator end, ConnectCondition connect_condition,
Chris@16 441 boost::system::error_code& ec);
Chris@16 442
Chris@16 443 /*@}*/
Chris@16 444
Chris@16 445 /**
Chris@16 446 * @defgroup async_connect boost::asio::async_connect
Chris@16 447 *
Chris@16 448 * @brief Asynchronously establishes a socket connection by trying each
Chris@16 449 * endpoint in a sequence.
Chris@16 450 */
Chris@16 451 /*@{*/
Chris@16 452
Chris@16 453 /// Asynchronously establishes a socket connection by trying each endpoint in a
Chris@16 454 /// sequence.
Chris@16 455 /**
Chris@16 456 * This function attempts to connect a socket to one of a sequence of
Chris@16 457 * endpoints. It does this by repeated calls to the socket's @c async_connect
Chris@16 458 * member function, once for each endpoint in the sequence, until a connection
Chris@16 459 * is successfully established.
Chris@16 460 *
Chris@16 461 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 462 * be closed.
Chris@16 463 *
Chris@16 464 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 465 *
Chris@16 466 * @param handler The handler to be called when the connect operation
Chris@16 467 * completes. Copies will be made of the handler as required. The function
Chris@16 468 * signature of the handler must be:
Chris@16 469 * @code void handler(
Chris@16 470 * // Result of operation. if the sequence is empty, set to
Chris@16 471 * // boost::asio::error::not_found. Otherwise, contains the
Chris@16 472 * // error from the last connection attempt.
Chris@16 473 * const boost::system::error_code& error,
Chris@16 474 *
Chris@16 475 * // On success, an iterator denoting the successfully
Chris@16 476 * // connected endpoint. Otherwise, the end iterator.
Chris@16 477 * Iterator iterator
Chris@16 478 * ); @endcode
Chris@16 479 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 480 * not, the handler will not be invoked from within this function. Invocation
Chris@16 481 * of the handler will be performed in a manner equivalent to using
Chris@16 482 * boost::asio::io_service::post().
Chris@16 483 *
Chris@16 484 * @note This overload assumes that a default constructed object of type @c
Chris@16 485 * Iterator represents the end of the sequence. This is a valid assumption for
Chris@16 486 * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
Chris@16 487 *
Chris@16 488 * @par Example
Chris@16 489 * @code tcp::resolver r(io_service);
Chris@16 490 * tcp::resolver::query q("host", "service");
Chris@16 491 * tcp::socket s(io_service);
Chris@16 492 *
Chris@16 493 * // ...
Chris@16 494 *
Chris@16 495 * r.async_resolve(q, resolve_handler);
Chris@16 496 *
Chris@16 497 * // ...
Chris@16 498 *
Chris@16 499 * void resolve_handler(
Chris@16 500 * const boost::system::error_code& ec,
Chris@16 501 * tcp::resolver::iterator i)
Chris@16 502 * {
Chris@16 503 * if (!ec)
Chris@16 504 * {
Chris@16 505 * boost::asio::async_connect(s, i, connect_handler);
Chris@16 506 * }
Chris@16 507 * }
Chris@16 508 *
Chris@16 509 * // ...
Chris@16 510 *
Chris@16 511 * void connect_handler(
Chris@16 512 * const boost::system::error_code& ec,
Chris@16 513 * tcp::resolver::iterator i)
Chris@16 514 * {
Chris@16 515 * // ...
Chris@16 516 * } @endcode
Chris@16 517 */
Chris@16 518 template <typename Protocol, typename SocketService,
Chris@16 519 typename Iterator, typename ComposedConnectHandler>
Chris@16 520 BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
Chris@16 521 void (boost::system::error_code, Iterator))
Chris@16 522 async_connect(basic_socket<Protocol, SocketService>& s,
Chris@16 523 Iterator begin, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler);
Chris@16 524
Chris@16 525 /// Asynchronously establishes a socket connection by trying each endpoint in a
Chris@16 526 /// sequence.
Chris@16 527 /**
Chris@16 528 * This function attempts to connect a socket to one of a sequence of
Chris@16 529 * endpoints. It does this by repeated calls to the socket's @c async_connect
Chris@16 530 * member function, once for each endpoint in the sequence, until a connection
Chris@16 531 * is successfully established.
Chris@16 532 *
Chris@16 533 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 534 * be closed.
Chris@16 535 *
Chris@16 536 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 537 *
Chris@16 538 * @param end An iterator pointing to the end of a sequence of endpoints.
Chris@16 539 *
Chris@16 540 * @param handler The handler to be called when the connect operation
Chris@16 541 * completes. Copies will be made of the handler as required. The function
Chris@16 542 * signature of the handler must be:
Chris@16 543 * @code void handler(
Chris@16 544 * // Result of operation. if the sequence is empty, set to
Chris@16 545 * // boost::asio::error::not_found. Otherwise, contains the
Chris@16 546 * // error from the last connection attempt.
Chris@16 547 * const boost::system::error_code& error,
Chris@16 548 *
Chris@16 549 * // On success, an iterator denoting the successfully
Chris@16 550 * // connected endpoint. Otherwise, the end iterator.
Chris@16 551 * Iterator iterator
Chris@16 552 * ); @endcode
Chris@16 553 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 554 * not, the handler will not be invoked from within this function. Invocation
Chris@16 555 * of the handler will be performed in a manner equivalent to using
Chris@16 556 * boost::asio::io_service::post().
Chris@16 557 *
Chris@16 558 * @par Example
Chris@16 559 * @code tcp::resolver r(io_service);
Chris@16 560 * tcp::resolver::query q("host", "service");
Chris@16 561 * tcp::socket s(io_service);
Chris@16 562 *
Chris@16 563 * // ...
Chris@16 564 *
Chris@16 565 * r.async_resolve(q, resolve_handler);
Chris@16 566 *
Chris@16 567 * // ...
Chris@16 568 *
Chris@16 569 * void resolve_handler(
Chris@16 570 * const boost::system::error_code& ec,
Chris@16 571 * tcp::resolver::iterator i)
Chris@16 572 * {
Chris@16 573 * if (!ec)
Chris@16 574 * {
Chris@16 575 * tcp::resolver::iterator end;
Chris@16 576 * boost::asio::async_connect(s, i, end, connect_handler);
Chris@16 577 * }
Chris@16 578 * }
Chris@16 579 *
Chris@16 580 * // ...
Chris@16 581 *
Chris@16 582 * void connect_handler(
Chris@16 583 * const boost::system::error_code& ec,
Chris@16 584 * tcp::resolver::iterator i)
Chris@16 585 * {
Chris@16 586 * // ...
Chris@16 587 * } @endcode
Chris@16 588 */
Chris@16 589 template <typename Protocol, typename SocketService,
Chris@16 590 typename Iterator, typename ComposedConnectHandler>
Chris@16 591 BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
Chris@16 592 void (boost::system::error_code, Iterator))
Chris@16 593 async_connect(basic_socket<Protocol, SocketService>& s,
Chris@16 594 Iterator begin, Iterator end,
Chris@16 595 BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler);
Chris@16 596
Chris@16 597 /// Asynchronously establishes a socket connection by trying each endpoint in a
Chris@16 598 /// sequence.
Chris@16 599 /**
Chris@16 600 * This function attempts to connect a socket to one of a sequence of
Chris@16 601 * endpoints. It does this by repeated calls to the socket's @c async_connect
Chris@16 602 * member function, once for each endpoint in the sequence, until a connection
Chris@16 603 * is successfully established.
Chris@16 604 *
Chris@16 605 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 606 * be closed.
Chris@16 607 *
Chris@16 608 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 609 *
Chris@16 610 * @param connect_condition A function object that is called prior to each
Chris@16 611 * connection attempt. The signature of the function object must be:
Chris@16 612 * @code Iterator connect_condition(
Chris@16 613 * const boost::system::error_code& ec,
Chris@16 614 * Iterator next); @endcode
Chris@16 615 * The @c ec parameter contains the result from the most recent connect
Chris@16 616 * operation. Before the first connection attempt, @c ec is always set to
Chris@16 617 * indicate success. The @c next parameter is an iterator pointing to the next
Chris@16 618 * endpoint to be tried. The function object should return the next iterator,
Chris@16 619 * but is permitted to return a different iterator so that endpoints may be
Chris@16 620 * skipped. The implementation guarantees that the function object will never
Chris@16 621 * be called with the end iterator.
Chris@16 622 *
Chris@16 623 * @param handler The handler to be called when the connect operation
Chris@16 624 * completes. Copies will be made of the handler as required. The function
Chris@16 625 * signature of the handler must be:
Chris@16 626 * @code void handler(
Chris@16 627 * // Result of operation. if the sequence is empty, set to
Chris@16 628 * // boost::asio::error::not_found. Otherwise, contains the
Chris@16 629 * // error from the last connection attempt.
Chris@16 630 * const boost::system::error_code& error,
Chris@16 631 *
Chris@16 632 * // On success, an iterator denoting the successfully
Chris@16 633 * // connected endpoint. Otherwise, the end iterator.
Chris@16 634 * Iterator iterator
Chris@16 635 * ); @endcode
Chris@16 636 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 637 * not, the handler will not be invoked from within this function. Invocation
Chris@16 638 * of the handler will be performed in a manner equivalent to using
Chris@16 639 * boost::asio::io_service::post().
Chris@16 640 *
Chris@16 641 * @note This overload assumes that a default constructed object of type @c
Chris@16 642 * Iterator represents the end of the sequence. This is a valid assumption for
Chris@16 643 * iterator types such as @c boost::asio::ip::tcp::resolver::iterator.
Chris@16 644 *
Chris@16 645 * @par Example
Chris@16 646 * The following connect condition function object can be used to output
Chris@16 647 * information about the individual connection attempts:
Chris@16 648 * @code struct my_connect_condition
Chris@16 649 * {
Chris@16 650 * template <typename Iterator>
Chris@16 651 * Iterator operator()(
Chris@16 652 * const boost::system::error_code& ec,
Chris@16 653 * Iterator next)
Chris@16 654 * {
Chris@16 655 * if (ec) std::cout << "Error: " << ec.message() << std::endl;
Chris@16 656 * std::cout << "Trying: " << next->endpoint() << std::endl;
Chris@16 657 * return next;
Chris@16 658 * }
Chris@16 659 * }; @endcode
Chris@16 660 * It would be used with the boost::asio::connect function as follows:
Chris@16 661 * @code tcp::resolver r(io_service);
Chris@16 662 * tcp::resolver::query q("host", "service");
Chris@16 663 * tcp::socket s(io_service);
Chris@16 664 *
Chris@16 665 * // ...
Chris@16 666 *
Chris@16 667 * r.async_resolve(q, resolve_handler);
Chris@16 668 *
Chris@16 669 * // ...
Chris@16 670 *
Chris@16 671 * void resolve_handler(
Chris@16 672 * const boost::system::error_code& ec,
Chris@16 673 * tcp::resolver::iterator i)
Chris@16 674 * {
Chris@16 675 * if (!ec)
Chris@16 676 * {
Chris@16 677 * boost::asio::async_connect(s, i,
Chris@16 678 * my_connect_condition(),
Chris@16 679 * connect_handler);
Chris@16 680 * }
Chris@16 681 * }
Chris@16 682 *
Chris@16 683 * // ...
Chris@16 684 *
Chris@16 685 * void connect_handler(
Chris@16 686 * const boost::system::error_code& ec,
Chris@16 687 * tcp::resolver::iterator i)
Chris@16 688 * {
Chris@16 689 * if (ec)
Chris@16 690 * {
Chris@16 691 * // An error occurred.
Chris@16 692 * }
Chris@16 693 * else
Chris@16 694 * {
Chris@16 695 * std::cout << "Connected to: " << i->endpoint() << std::endl;
Chris@16 696 * }
Chris@16 697 * } @endcode
Chris@16 698 */
Chris@16 699 template <typename Protocol, typename SocketService, typename Iterator,
Chris@16 700 typename ConnectCondition, typename ComposedConnectHandler>
Chris@16 701 BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
Chris@16 702 void (boost::system::error_code, Iterator))
Chris@16 703 async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
Chris@16 704 ConnectCondition connect_condition,
Chris@16 705 BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler);
Chris@16 706
Chris@16 707 /// Asynchronously establishes a socket connection by trying each endpoint in a
Chris@16 708 /// sequence.
Chris@16 709 /**
Chris@16 710 * This function attempts to connect a socket to one of a sequence of
Chris@16 711 * endpoints. It does this by repeated calls to the socket's @c async_connect
Chris@16 712 * member function, once for each endpoint in the sequence, until a connection
Chris@16 713 * is successfully established.
Chris@16 714 *
Chris@16 715 * @param s The socket to be connected. If the socket is already open, it will
Chris@16 716 * be closed.
Chris@16 717 *
Chris@16 718 * @param begin An iterator pointing to the start of a sequence of endpoints.
Chris@16 719 *
Chris@16 720 * @param end An iterator pointing to the end of a sequence of endpoints.
Chris@16 721 *
Chris@16 722 * @param connect_condition A function object that is called prior to each
Chris@16 723 * connection attempt. The signature of the function object must be:
Chris@16 724 * @code Iterator connect_condition(
Chris@16 725 * const boost::system::error_code& ec,
Chris@16 726 * Iterator next); @endcode
Chris@16 727 * The @c ec parameter contains the result from the most recent connect
Chris@16 728 * operation. Before the first connection attempt, @c ec is always set to
Chris@16 729 * indicate success. The @c next parameter is an iterator pointing to the next
Chris@16 730 * endpoint to be tried. The function object should return the next iterator,
Chris@16 731 * but is permitted to return a different iterator so that endpoints may be
Chris@16 732 * skipped. The implementation guarantees that the function object will never
Chris@16 733 * be called with the end iterator.
Chris@16 734 *
Chris@16 735 * @param handler The handler to be called when the connect operation
Chris@16 736 * completes. Copies will be made of the handler as required. The function
Chris@16 737 * signature of the handler must be:
Chris@16 738 * @code void handler(
Chris@16 739 * // Result of operation. if the sequence is empty, set to
Chris@16 740 * // boost::asio::error::not_found. Otherwise, contains the
Chris@16 741 * // error from the last connection attempt.
Chris@16 742 * const boost::system::error_code& error,
Chris@16 743 *
Chris@16 744 * // On success, an iterator denoting the successfully
Chris@16 745 * // connected endpoint. Otherwise, the end iterator.
Chris@16 746 * Iterator iterator
Chris@16 747 * ); @endcode
Chris@16 748 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 749 * not, the handler will not be invoked from within this function. Invocation
Chris@16 750 * of the handler will be performed in a manner equivalent to using
Chris@16 751 * boost::asio::io_service::post().
Chris@16 752 *
Chris@16 753 * @par Example
Chris@16 754 * The following connect condition function object can be used to output
Chris@16 755 * information about the individual connection attempts:
Chris@16 756 * @code struct my_connect_condition
Chris@16 757 * {
Chris@16 758 * template <typename Iterator>
Chris@16 759 * Iterator operator()(
Chris@16 760 * const boost::system::error_code& ec,
Chris@16 761 * Iterator next)
Chris@16 762 * {
Chris@16 763 * if (ec) std::cout << "Error: " << ec.message() << std::endl;
Chris@16 764 * std::cout << "Trying: " << next->endpoint() << std::endl;
Chris@16 765 * return next;
Chris@16 766 * }
Chris@16 767 * }; @endcode
Chris@16 768 * It would be used with the boost::asio::connect function as follows:
Chris@16 769 * @code tcp::resolver r(io_service);
Chris@16 770 * tcp::resolver::query q("host", "service");
Chris@16 771 * tcp::socket s(io_service);
Chris@16 772 *
Chris@16 773 * // ...
Chris@16 774 *
Chris@16 775 * r.async_resolve(q, resolve_handler);
Chris@16 776 *
Chris@16 777 * // ...
Chris@16 778 *
Chris@16 779 * void resolve_handler(
Chris@16 780 * const boost::system::error_code& ec,
Chris@16 781 * tcp::resolver::iterator i)
Chris@16 782 * {
Chris@16 783 * if (!ec)
Chris@16 784 * {
Chris@16 785 * tcp::resolver::iterator end;
Chris@16 786 * boost::asio::async_connect(s, i, end,
Chris@16 787 * my_connect_condition(),
Chris@16 788 * connect_handler);
Chris@16 789 * }
Chris@16 790 * }
Chris@16 791 *
Chris@16 792 * // ...
Chris@16 793 *
Chris@16 794 * void connect_handler(
Chris@16 795 * const boost::system::error_code& ec,
Chris@16 796 * tcp::resolver::iterator i)
Chris@16 797 * {
Chris@16 798 * if (ec)
Chris@16 799 * {
Chris@16 800 * // An error occurred.
Chris@16 801 * }
Chris@16 802 * else
Chris@16 803 * {
Chris@16 804 * std::cout << "Connected to: " << i->endpoint() << std::endl;
Chris@16 805 * }
Chris@16 806 * } @endcode
Chris@16 807 */
Chris@16 808 template <typename Protocol, typename SocketService, typename Iterator,
Chris@16 809 typename ConnectCondition, typename ComposedConnectHandler>
Chris@16 810 BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
Chris@16 811 void (boost::system::error_code, Iterator))
Chris@16 812 async_connect(basic_socket<Protocol, SocketService>& s,
Chris@16 813 Iterator begin, Iterator end, ConnectCondition connect_condition,
Chris@16 814 BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler);
Chris@16 815
Chris@16 816 /*@}*/
Chris@16 817
Chris@16 818 } // namespace asio
Chris@16 819 } // namespace boost
Chris@16 820
Chris@16 821 #include <boost/asio/detail/pop_options.hpp>
Chris@16 822
Chris@16 823 #include <boost/asio/impl/connect.hpp>
Chris@16 824
Chris@16 825 #endif