annotate DEPENDENCIES/generic/include/boost/asio/basic_seq_packet_socket.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // basic_seq_packet_socket.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_BASIC_SEQ_PACKET_SOCKET_HPP
Chris@16 12 #define BOOST_ASIO_BASIC_SEQ_PACKET_SOCKET_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 <cstddef>
Chris@16 20 #include <boost/asio/basic_socket.hpp>
Chris@16 21 #include <boost/asio/detail/handler_type_requirements.hpp>
Chris@16 22 #include <boost/asio/detail/throw_error.hpp>
Chris@16 23 #include <boost/asio/error.hpp>
Chris@16 24 #include <boost/asio/seq_packet_socket_service.hpp>
Chris@16 25
Chris@16 26 #include <boost/asio/detail/push_options.hpp>
Chris@16 27
Chris@16 28 namespace boost {
Chris@16 29 namespace asio {
Chris@16 30
Chris@16 31 /// Provides sequenced packet socket functionality.
Chris@16 32 /**
Chris@16 33 * The basic_seq_packet_socket class template provides asynchronous and blocking
Chris@16 34 * sequenced packet socket functionality.
Chris@16 35 *
Chris@16 36 * @par Thread Safety
Chris@16 37 * @e Distinct @e objects: Safe.@n
Chris@16 38 * @e Shared @e objects: Unsafe.
Chris@16 39 */
Chris@16 40 template <typename Protocol,
Chris@16 41 typename SeqPacketSocketService = seq_packet_socket_service<Protocol> >
Chris@16 42 class basic_seq_packet_socket
Chris@16 43 : public basic_socket<Protocol, SeqPacketSocketService>
Chris@16 44 {
Chris@16 45 public:
Chris@16 46 /// (Deprecated: Use native_handle_type.) The native representation of a
Chris@16 47 /// socket.
Chris@16 48 typedef typename SeqPacketSocketService::native_handle_type native_type;
Chris@16 49
Chris@16 50 /// The native representation of a socket.
Chris@16 51 typedef typename SeqPacketSocketService::native_handle_type
Chris@16 52 native_handle_type;
Chris@16 53
Chris@16 54 /// The protocol type.
Chris@16 55 typedef Protocol protocol_type;
Chris@16 56
Chris@16 57 /// The endpoint type.
Chris@16 58 typedef typename Protocol::endpoint endpoint_type;
Chris@16 59
Chris@16 60 /// Construct a basic_seq_packet_socket without opening it.
Chris@16 61 /**
Chris@16 62 * This constructor creates a sequenced packet socket without opening it. The
Chris@16 63 * socket needs to be opened and then connected or accepted before data can
Chris@16 64 * be sent or received on it.
Chris@16 65 *
Chris@16 66 * @param io_service The io_service object that the sequenced packet socket
Chris@16 67 * will use to dispatch handlers for any asynchronous operations performed on
Chris@16 68 * the socket.
Chris@16 69 */
Chris@16 70 explicit basic_seq_packet_socket(boost::asio::io_service& io_service)
Chris@16 71 : basic_socket<Protocol, SeqPacketSocketService>(io_service)
Chris@16 72 {
Chris@16 73 }
Chris@16 74
Chris@16 75 /// Construct and open a basic_seq_packet_socket.
Chris@16 76 /**
Chris@16 77 * This constructor creates and opens a sequenced_packet socket. The socket
Chris@16 78 * needs to be connected or accepted before data can be sent or received on
Chris@16 79 * it.
Chris@16 80 *
Chris@16 81 * @param io_service The io_service object that the sequenced packet socket
Chris@16 82 * will use to dispatch handlers for any asynchronous operations performed on
Chris@16 83 * the socket.
Chris@16 84 *
Chris@16 85 * @param protocol An object specifying protocol parameters to be used.
Chris@16 86 *
Chris@16 87 * @throws boost::system::system_error Thrown on failure.
Chris@16 88 */
Chris@16 89 basic_seq_packet_socket(boost::asio::io_service& io_service,
Chris@16 90 const protocol_type& protocol)
Chris@16 91 : basic_socket<Protocol, SeqPacketSocketService>(io_service, protocol)
Chris@16 92 {
Chris@16 93 }
Chris@16 94
Chris@16 95 /// Construct a basic_seq_packet_socket, opening it and binding it to the
Chris@16 96 /// given local endpoint.
Chris@16 97 /**
Chris@16 98 * This constructor creates a sequenced packet socket and automatically opens
Chris@16 99 * it bound to the specified endpoint on the local machine. The protocol used
Chris@16 100 * is the protocol associated with the given endpoint.
Chris@16 101 *
Chris@16 102 * @param io_service The io_service object that the sequenced packet socket
Chris@16 103 * will use to dispatch handlers for any asynchronous operations performed on
Chris@16 104 * the socket.
Chris@16 105 *
Chris@16 106 * @param endpoint An endpoint on the local machine to which the sequenced
Chris@16 107 * packet socket will be bound.
Chris@16 108 *
Chris@16 109 * @throws boost::system::system_error Thrown on failure.
Chris@16 110 */
Chris@16 111 basic_seq_packet_socket(boost::asio::io_service& io_service,
Chris@16 112 const endpoint_type& endpoint)
Chris@16 113 : basic_socket<Protocol, SeqPacketSocketService>(io_service, endpoint)
Chris@16 114 {
Chris@16 115 }
Chris@16 116
Chris@16 117 /// Construct a basic_seq_packet_socket on an existing native socket.
Chris@16 118 /**
Chris@16 119 * This constructor creates a sequenced packet socket object to hold an
Chris@16 120 * existing native socket.
Chris@16 121 *
Chris@16 122 * @param io_service The io_service object that the sequenced packet socket
Chris@16 123 * will use to dispatch handlers for any asynchronous operations performed on
Chris@16 124 * the socket.
Chris@16 125 *
Chris@16 126 * @param protocol An object specifying protocol parameters to be used.
Chris@16 127 *
Chris@16 128 * @param native_socket The new underlying socket implementation.
Chris@16 129 *
Chris@16 130 * @throws boost::system::system_error Thrown on failure.
Chris@16 131 */
Chris@16 132 basic_seq_packet_socket(boost::asio::io_service& io_service,
Chris@16 133 const protocol_type& protocol, const native_handle_type& native_socket)
Chris@16 134 : basic_socket<Protocol, SeqPacketSocketService>(
Chris@16 135 io_service, protocol, native_socket)
Chris@16 136 {
Chris@16 137 }
Chris@16 138
Chris@16 139 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 140 /// Move-construct a basic_seq_packet_socket from another.
Chris@16 141 /**
Chris@16 142 * This constructor moves a sequenced packet socket from one object to
Chris@16 143 * another.
Chris@16 144 *
Chris@16 145 * @param other The other basic_seq_packet_socket object from which the move
Chris@16 146 * will occur.
Chris@16 147 *
Chris@16 148 * @note Following the move, the moved-from object is in the same state as if
Chris@16 149 * constructed using the @c basic_seq_packet_socket(io_service&) constructor.
Chris@16 150 */
Chris@16 151 basic_seq_packet_socket(basic_seq_packet_socket&& other)
Chris@16 152 : basic_socket<Protocol, SeqPacketSocketService>(
Chris@16 153 BOOST_ASIO_MOVE_CAST(basic_seq_packet_socket)(other))
Chris@16 154 {
Chris@16 155 }
Chris@16 156
Chris@16 157 /// Move-assign a basic_seq_packet_socket from another.
Chris@16 158 /**
Chris@16 159 * This assignment operator moves a sequenced packet socket from one object to
Chris@16 160 * another.
Chris@16 161 *
Chris@16 162 * @param other The other basic_seq_packet_socket object from which the move
Chris@16 163 * will occur.
Chris@16 164 *
Chris@16 165 * @note Following the move, the moved-from object is in the same state as if
Chris@16 166 * constructed using the @c basic_seq_packet_socket(io_service&) constructor.
Chris@16 167 */
Chris@16 168 basic_seq_packet_socket& operator=(basic_seq_packet_socket&& other)
Chris@16 169 {
Chris@16 170 basic_socket<Protocol, SeqPacketSocketService>::operator=(
Chris@16 171 BOOST_ASIO_MOVE_CAST(basic_seq_packet_socket)(other));
Chris@16 172 return *this;
Chris@16 173 }
Chris@16 174
Chris@16 175 /// Move-construct a basic_seq_packet_socket from a socket of another protocol
Chris@16 176 /// type.
Chris@16 177 /**
Chris@16 178 * This constructor moves a sequenced packet socket from one object to
Chris@16 179 * another.
Chris@16 180 *
Chris@16 181 * @param other The other basic_seq_packet_socket object from which the move
Chris@16 182 * will occur.
Chris@16 183 *
Chris@16 184 * @note Following the move, the moved-from object is in the same state as if
Chris@16 185 * constructed using the @c basic_seq_packet_socket(io_service&) constructor.
Chris@16 186 */
Chris@16 187 template <typename Protocol1, typename SeqPacketSocketService1>
Chris@16 188 basic_seq_packet_socket(
Chris@16 189 basic_seq_packet_socket<Protocol1, SeqPacketSocketService1>&& other,
Chris@16 190 typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
Chris@16 191 : basic_socket<Protocol, SeqPacketSocketService>(
Chris@16 192 BOOST_ASIO_MOVE_CAST2(basic_seq_packet_socket<
Chris@16 193 Protocol1, SeqPacketSocketService1>)(other))
Chris@16 194 {
Chris@16 195 }
Chris@16 196
Chris@16 197 /// Move-assign a basic_seq_packet_socket from a socket of another protocol
Chris@16 198 /// type.
Chris@16 199 /**
Chris@16 200 * This assignment operator moves a sequenced packet socket from one object to
Chris@16 201 * another.
Chris@16 202 *
Chris@16 203 * @param other The other basic_seq_packet_socket object from which the move
Chris@16 204 * will occur.
Chris@16 205 *
Chris@16 206 * @note Following the move, the moved-from object is in the same state as if
Chris@16 207 * constructed using the @c basic_seq_packet_socket(io_service&) constructor.
Chris@16 208 */
Chris@16 209 template <typename Protocol1, typename SeqPacketSocketService1>
Chris@16 210 typename enable_if<is_convertible<Protocol1, Protocol>::value,
Chris@16 211 basic_seq_packet_socket>::type& operator=(
Chris@16 212 basic_seq_packet_socket<Protocol1, SeqPacketSocketService1>&& other)
Chris@16 213 {
Chris@16 214 basic_socket<Protocol, SeqPacketSocketService>::operator=(
Chris@16 215 BOOST_ASIO_MOVE_CAST2(basic_seq_packet_socket<
Chris@16 216 Protocol1, SeqPacketSocketService1>)(other));
Chris@16 217 return *this;
Chris@16 218 }
Chris@16 219 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 220
Chris@16 221 /// Send some data on the socket.
Chris@16 222 /**
Chris@16 223 * This function is used to send data on the sequenced packet socket. The
Chris@16 224 * function call will block until the data has been sent successfully, or an
Chris@16 225 * until error occurs.
Chris@16 226 *
Chris@16 227 * @param buffers One or more data buffers to be sent on the socket.
Chris@16 228 *
Chris@16 229 * @param flags Flags specifying how the send call is to be made.
Chris@16 230 *
Chris@16 231 * @returns The number of bytes sent.
Chris@16 232 *
Chris@16 233 * @throws boost::system::system_error Thrown on failure.
Chris@16 234 *
Chris@16 235 * @par Example
Chris@16 236 * To send a single data buffer use the @ref buffer function as follows:
Chris@16 237 * @code
Chris@16 238 * socket.send(boost::asio::buffer(data, size), 0);
Chris@16 239 * @endcode
Chris@16 240 * See the @ref buffer documentation for information on sending multiple
Chris@16 241 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 242 * std::vector.
Chris@16 243 */
Chris@16 244 template <typename ConstBufferSequence>
Chris@16 245 std::size_t send(const ConstBufferSequence& buffers,
Chris@16 246 socket_base::message_flags flags)
Chris@16 247 {
Chris@16 248 boost::system::error_code ec;
Chris@16 249 std::size_t s = this->get_service().send(
Chris@16 250 this->get_implementation(), buffers, flags, ec);
Chris@16 251 boost::asio::detail::throw_error(ec, "send");
Chris@16 252 return s;
Chris@16 253 }
Chris@16 254
Chris@16 255 /// Send some data on the socket.
Chris@16 256 /**
Chris@16 257 * This function is used to send data on the sequenced packet socket. The
Chris@16 258 * function call will block the data has been sent successfully, or an until
Chris@16 259 * error occurs.
Chris@16 260 *
Chris@16 261 * @param buffers One or more data buffers to be sent on the socket.
Chris@16 262 *
Chris@16 263 * @param flags Flags specifying how the send call is to be made.
Chris@16 264 *
Chris@16 265 * @param ec Set to indicate what error occurred, if any.
Chris@16 266 *
Chris@16 267 * @returns The number of bytes sent. Returns 0 if an error occurred.
Chris@16 268 *
Chris@16 269 * @note The send operation may not transmit all of the data to the peer.
Chris@16 270 * Consider using the @ref write function if you need to ensure that all data
Chris@16 271 * is written before the blocking operation completes.
Chris@16 272 */
Chris@16 273 template <typename ConstBufferSequence>
Chris@16 274 std::size_t send(const ConstBufferSequence& buffers,
Chris@16 275 socket_base::message_flags flags, boost::system::error_code& ec)
Chris@16 276 {
Chris@16 277 return this->get_service().send(
Chris@16 278 this->get_implementation(), buffers, flags, ec);
Chris@16 279 }
Chris@16 280
Chris@16 281 /// Start an asynchronous send.
Chris@16 282 /**
Chris@16 283 * This function is used to asynchronously send data on the sequenced packet
Chris@16 284 * socket. The function call always returns immediately.
Chris@16 285 *
Chris@16 286 * @param buffers One or more data buffers to be sent on the socket. Although
Chris@16 287 * the buffers object may be copied as necessary, ownership of the underlying
Chris@16 288 * memory blocks is retained by the caller, which must guarantee that they
Chris@16 289 * remain valid until the handler is called.
Chris@16 290 *
Chris@16 291 * @param flags Flags specifying how the send call is to be made.
Chris@16 292 *
Chris@16 293 * @param handler The handler to be called when the send operation completes.
Chris@16 294 * Copies will be made of the handler as required. The function signature of
Chris@16 295 * the handler must be:
Chris@16 296 * @code void handler(
Chris@16 297 * const boost::system::error_code& error, // Result of operation.
Chris@16 298 * std::size_t bytes_transferred // Number of bytes sent.
Chris@16 299 * ); @endcode
Chris@16 300 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 301 * not, the handler will not be invoked from within this function. Invocation
Chris@16 302 * of the handler will be performed in a manner equivalent to using
Chris@16 303 * boost::asio::io_service::post().
Chris@16 304 *
Chris@16 305 * @par Example
Chris@16 306 * To send a single data buffer use the @ref buffer function as follows:
Chris@16 307 * @code
Chris@16 308 * socket.async_send(boost::asio::buffer(data, size), 0, handler);
Chris@16 309 * @endcode
Chris@16 310 * See the @ref buffer documentation for information on sending multiple
Chris@16 311 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 312 * std::vector.
Chris@16 313 */
Chris@16 314 template <typename ConstBufferSequence, typename WriteHandler>
Chris@16 315 BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
Chris@16 316 void (boost::system::error_code, std::size_t))
Chris@16 317 async_send(const ConstBufferSequence& buffers,
Chris@16 318 socket_base::message_flags flags,
Chris@16 319 BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
Chris@16 320 {
Chris@16 321 // If you get an error on the following line it means that your handler does
Chris@16 322 // not meet the documented type requirements for a WriteHandler.
Chris@16 323 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
Chris@16 324
Chris@16 325 return this->get_service().async_send(this->get_implementation(),
Chris@16 326 buffers, flags, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
Chris@16 327 }
Chris@16 328
Chris@16 329 /// Receive some data on the socket.
Chris@16 330 /**
Chris@16 331 * This function is used to receive data on the sequenced packet socket. The
Chris@16 332 * function call will block until data has been received successfully, or
Chris@16 333 * until an error occurs.
Chris@16 334 *
Chris@16 335 * @param buffers One or more buffers into which the data will be received.
Chris@16 336 *
Chris@16 337 * @param out_flags After the receive call completes, contains flags
Chris@16 338 * associated with the received data. For example, if the
Chris@16 339 * socket_base::message_end_of_record bit is set then the received data marks
Chris@16 340 * the end of a record.
Chris@16 341 *
Chris@16 342 * @returns The number of bytes received.
Chris@16 343 *
Chris@16 344 * @throws boost::system::system_error Thrown on failure. An error code of
Chris@16 345 * boost::asio::error::eof indicates that the connection was closed by the
Chris@16 346 * peer.
Chris@16 347 *
Chris@16 348 * @par Example
Chris@16 349 * To receive into a single data buffer use the @ref buffer function as
Chris@16 350 * follows:
Chris@16 351 * @code
Chris@16 352 * socket.receive(boost::asio::buffer(data, size), out_flags);
Chris@16 353 * @endcode
Chris@16 354 * See the @ref buffer documentation for information on receiving into
Chris@16 355 * multiple buffers in one go, and how to use it with arrays, boost::array or
Chris@16 356 * std::vector.
Chris@16 357 */
Chris@16 358 template <typename MutableBufferSequence>
Chris@16 359 std::size_t receive(const MutableBufferSequence& buffers,
Chris@16 360 socket_base::message_flags& out_flags)
Chris@16 361 {
Chris@16 362 boost::system::error_code ec;
Chris@16 363 std::size_t s = this->get_service().receive(
Chris@16 364 this->get_implementation(), buffers, 0, out_flags, ec);
Chris@16 365 boost::asio::detail::throw_error(ec, "receive");
Chris@16 366 return s;
Chris@16 367 }
Chris@16 368
Chris@16 369 /// Receive some data on the socket.
Chris@16 370 /**
Chris@16 371 * This function is used to receive data on the sequenced packet socket. The
Chris@16 372 * function call will block until data has been received successfully, or
Chris@16 373 * until an error occurs.
Chris@16 374 *
Chris@16 375 * @param buffers One or more buffers into which the data will be received.
Chris@16 376 *
Chris@16 377 * @param in_flags Flags specifying how the receive call is to be made.
Chris@16 378 *
Chris@16 379 * @param out_flags After the receive call completes, contains flags
Chris@16 380 * associated with the received data. For example, if the
Chris@16 381 * socket_base::message_end_of_record bit is set then the received data marks
Chris@16 382 * the end of a record.
Chris@16 383 *
Chris@16 384 * @returns The number of bytes received.
Chris@16 385 *
Chris@16 386 * @throws boost::system::system_error Thrown on failure. An error code of
Chris@16 387 * boost::asio::error::eof indicates that the connection was closed by the
Chris@16 388 * peer.
Chris@16 389 *
Chris@16 390 * @note The receive operation may not receive all of the requested number of
Chris@16 391 * bytes. Consider using the @ref read function if you need to ensure that the
Chris@16 392 * requested amount of data is read before the blocking operation completes.
Chris@16 393 *
Chris@16 394 * @par Example
Chris@16 395 * To receive into a single data buffer use the @ref buffer function as
Chris@16 396 * follows:
Chris@16 397 * @code
Chris@16 398 * socket.receive(boost::asio::buffer(data, size), 0, out_flags);
Chris@16 399 * @endcode
Chris@16 400 * See the @ref buffer documentation for information on receiving into
Chris@16 401 * multiple buffers in one go, and how to use it with arrays, boost::array or
Chris@16 402 * std::vector.
Chris@16 403 */
Chris@16 404 template <typename MutableBufferSequence>
Chris@16 405 std::size_t receive(const MutableBufferSequence& buffers,
Chris@16 406 socket_base::message_flags in_flags,
Chris@16 407 socket_base::message_flags& out_flags)
Chris@16 408 {
Chris@16 409 boost::system::error_code ec;
Chris@16 410 std::size_t s = this->get_service().receive(
Chris@16 411 this->get_implementation(), buffers, in_flags, out_flags, ec);
Chris@16 412 boost::asio::detail::throw_error(ec, "receive");
Chris@16 413 return s;
Chris@16 414 }
Chris@16 415
Chris@16 416 /// Receive some data on a connected socket.
Chris@16 417 /**
Chris@16 418 * This function is used to receive data on the sequenced packet socket. The
Chris@16 419 * function call will block until data has been received successfully, or
Chris@16 420 * until an error occurs.
Chris@16 421 *
Chris@16 422 * @param buffers One or more buffers into which the data will be received.
Chris@16 423 *
Chris@16 424 * @param in_flags Flags specifying how the receive call is to be made.
Chris@16 425 *
Chris@16 426 * @param out_flags After the receive call completes, contains flags
Chris@16 427 * associated with the received data. For example, if the
Chris@16 428 * socket_base::message_end_of_record bit is set then the received data marks
Chris@16 429 * the end of a record.
Chris@16 430 *
Chris@16 431 * @param ec Set to indicate what error occurred, if any.
Chris@16 432 *
Chris@16 433 * @returns The number of bytes received. Returns 0 if an error occurred.
Chris@16 434 *
Chris@16 435 * @note The receive operation may not receive all of the requested number of
Chris@16 436 * bytes. Consider using the @ref read function if you need to ensure that the
Chris@16 437 * requested amount of data is read before the blocking operation completes.
Chris@16 438 */
Chris@16 439 template <typename MutableBufferSequence>
Chris@16 440 std::size_t receive(const MutableBufferSequence& buffers,
Chris@16 441 socket_base::message_flags in_flags,
Chris@16 442 socket_base::message_flags& out_flags, boost::system::error_code& ec)
Chris@16 443 {
Chris@16 444 return this->get_service().receive(this->get_implementation(),
Chris@16 445 buffers, in_flags, out_flags, ec);
Chris@16 446 }
Chris@16 447
Chris@16 448 /// Start an asynchronous receive.
Chris@16 449 /**
Chris@16 450 * This function is used to asynchronously receive data from the sequenced
Chris@16 451 * packet socket. The function call always returns immediately.
Chris@16 452 *
Chris@16 453 * @param buffers One or more buffers into which the data will be received.
Chris@16 454 * Although the buffers object may be copied as necessary, ownership of the
Chris@16 455 * underlying memory blocks is retained by the caller, which must guarantee
Chris@16 456 * that they remain valid until the handler is called.
Chris@16 457 *
Chris@16 458 * @param out_flags Once the asynchronous operation completes, contains flags
Chris@16 459 * associated with the received data. For example, if the
Chris@16 460 * socket_base::message_end_of_record bit is set then the received data marks
Chris@16 461 * the end of a record. The caller must guarantee that the referenced
Chris@16 462 * variable remains valid until the handler is called.
Chris@16 463 *
Chris@16 464 * @param handler The handler to be called when the receive operation
Chris@16 465 * completes. Copies will be made of the handler as required. The function
Chris@16 466 * signature of the handler must be:
Chris@16 467 * @code void handler(
Chris@16 468 * const boost::system::error_code& error, // Result of operation.
Chris@16 469 * std::size_t bytes_transferred // Number of bytes received.
Chris@16 470 * ); @endcode
Chris@16 471 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 472 * not, the handler will not be invoked from within this function. Invocation
Chris@16 473 * of the handler will be performed in a manner equivalent to using
Chris@16 474 * boost::asio::io_service::post().
Chris@16 475 *
Chris@16 476 * @par Example
Chris@16 477 * To receive into a single data buffer use the @ref buffer function as
Chris@16 478 * follows:
Chris@16 479 * @code
Chris@16 480 * socket.async_receive(boost::asio::buffer(data, size), out_flags, handler);
Chris@16 481 * @endcode
Chris@16 482 * See the @ref buffer documentation for information on receiving into
Chris@16 483 * multiple buffers in one go, and how to use it with arrays, boost::array or
Chris@16 484 * std::vector.
Chris@16 485 */
Chris@16 486 template <typename MutableBufferSequence, typename ReadHandler>
Chris@16 487 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Chris@16 488 void (boost::system::error_code, std::size_t))
Chris@16 489 async_receive(const MutableBufferSequence& buffers,
Chris@16 490 socket_base::message_flags& out_flags,
Chris@16 491 BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
Chris@16 492 {
Chris@16 493 // If you get an error on the following line it means that your handler does
Chris@16 494 // not meet the documented type requirements for a ReadHandler.
Chris@16 495 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
Chris@16 496
Chris@16 497 return this->get_service().async_receive(
Chris@16 498 this->get_implementation(), buffers, 0, out_flags,
Chris@16 499 BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
Chris@16 500 }
Chris@16 501
Chris@16 502 /// Start an asynchronous receive.
Chris@16 503 /**
Chris@16 504 * This function is used to asynchronously receive data from the sequenced
Chris@16 505 * data socket. The function call always returns immediately.
Chris@16 506 *
Chris@16 507 * @param buffers One or more buffers into which the data will be received.
Chris@16 508 * Although the buffers object may be copied as necessary, ownership of the
Chris@16 509 * underlying memory blocks is retained by the caller, which must guarantee
Chris@16 510 * that they remain valid until the handler is called.
Chris@16 511 *
Chris@16 512 * @param in_flags Flags specifying how the receive call is to be made.
Chris@16 513 *
Chris@16 514 * @param out_flags Once the asynchronous operation completes, contains flags
Chris@16 515 * associated with the received data. For example, if the
Chris@16 516 * socket_base::message_end_of_record bit is set then the received data marks
Chris@16 517 * the end of a record. The caller must guarantee that the referenced
Chris@16 518 * variable remains valid until the handler is called.
Chris@16 519 *
Chris@16 520 * @param handler The handler to be called when the receive operation
Chris@16 521 * completes. Copies will be made of the handler as required. The function
Chris@16 522 * signature of the handler must be:
Chris@16 523 * @code void handler(
Chris@16 524 * const boost::system::error_code& error, // Result of operation.
Chris@16 525 * std::size_t bytes_transferred // Number of bytes received.
Chris@16 526 * ); @endcode
Chris@16 527 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 528 * not, the handler will not be invoked from within this function. Invocation
Chris@16 529 * of the handler will be performed in a manner equivalent to using
Chris@16 530 * boost::asio::io_service::post().
Chris@16 531 *
Chris@16 532 * @par Example
Chris@16 533 * To receive into a single data buffer use the @ref buffer function as
Chris@16 534 * follows:
Chris@16 535 * @code
Chris@16 536 * socket.async_receive(
Chris@16 537 * boost::asio::buffer(data, size),
Chris@16 538 * 0, out_flags, handler);
Chris@16 539 * @endcode
Chris@16 540 * See the @ref buffer documentation for information on receiving into
Chris@16 541 * multiple buffers in one go, and how to use it with arrays, boost::array or
Chris@16 542 * std::vector.
Chris@16 543 */
Chris@16 544 template <typename MutableBufferSequence, typename ReadHandler>
Chris@16 545 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Chris@16 546 void (boost::system::error_code, std::size_t))
Chris@16 547 async_receive(const MutableBufferSequence& buffers,
Chris@16 548 socket_base::message_flags in_flags,
Chris@16 549 socket_base::message_flags& out_flags,
Chris@16 550 BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
Chris@16 551 {
Chris@16 552 // If you get an error on the following line it means that your handler does
Chris@16 553 // not meet the documented type requirements for a ReadHandler.
Chris@16 554 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
Chris@16 555
Chris@16 556 return this->get_service().async_receive(
Chris@16 557 this->get_implementation(), buffers, in_flags, out_flags,
Chris@16 558 BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
Chris@16 559 }
Chris@16 560 };
Chris@16 561
Chris@16 562 } // namespace asio
Chris@16 563 } // namespace boost
Chris@16 564
Chris@16 565 #include <boost/asio/detail/pop_options.hpp>
Chris@16 566
Chris@16 567 #endif // BOOST_ASIO_BASIC_SEQ_PACKET_SOCKET_HPP