annotate DEPENDENCIES/generic/include/boost/asio/read.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 // read.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_READ_HPP
Chris@16 12 #define BOOST_ASIO_READ_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/async_result.hpp>
Chris@16 21 #include <boost/asio/basic_streambuf_fwd.hpp>
Chris@16 22 #include <boost/asio/error.hpp>
Chris@16 23
Chris@16 24 #include <boost/asio/detail/push_options.hpp>
Chris@16 25
Chris@16 26 namespace boost {
Chris@16 27 namespace asio {
Chris@16 28
Chris@16 29 /**
Chris@16 30 * @defgroup read boost::asio::read
Chris@16 31 *
Chris@16 32 * @brief Attempt to read a certain amount of data from a stream before
Chris@16 33 * returning.
Chris@16 34 */
Chris@16 35 /*@{*/
Chris@16 36
Chris@16 37 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 38 /**
Chris@16 39 * This function is used to read a certain number of bytes of data from a
Chris@16 40 * stream. The call will block until one of the following conditions is true:
Chris@16 41 *
Chris@16 42 * @li The supplied buffers are full. That is, the bytes transferred is equal to
Chris@16 43 * the sum of the buffer sizes.
Chris@16 44 *
Chris@16 45 * @li An error occurred.
Chris@16 46 *
Chris@16 47 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 48 * read_some function.
Chris@16 49 *
Chris@16 50 * @param s The stream from which the data is to be read. The type must support
Chris@16 51 * the SyncReadStream concept.
Chris@16 52 *
Chris@16 53 * @param buffers One or more buffers into which the data will be read. The sum
Chris@16 54 * of the buffer sizes indicates the maximum number of bytes to read from the
Chris@16 55 * stream.
Chris@16 56 *
Chris@16 57 * @returns The number of bytes transferred.
Chris@16 58 *
Chris@16 59 * @throws boost::system::system_error Thrown on failure.
Chris@16 60 *
Chris@16 61 * @par Example
Chris@16 62 * To read into a single data buffer use the @ref buffer function as follows:
Chris@16 63 * @code boost::asio::read(s, boost::asio::buffer(data, size)); @endcode
Chris@16 64 * See the @ref buffer documentation for information on reading into multiple
Chris@16 65 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 66 * std::vector.
Chris@16 67 *
Chris@16 68 * @note This overload is equivalent to calling:
Chris@16 69 * @code boost::asio::read(
Chris@16 70 * s, buffers,
Chris@16 71 * boost::asio::transfer_all()); @endcode
Chris@16 72 */
Chris@16 73 template <typename SyncReadStream, typename MutableBufferSequence>
Chris@16 74 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers);
Chris@16 75
Chris@16 76 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 77 /**
Chris@16 78 * This function is used to read a certain number of bytes of data from a
Chris@16 79 * stream. The call will block until one of the following conditions is true:
Chris@16 80 *
Chris@16 81 * @li The supplied buffers are full. That is, the bytes transferred is equal to
Chris@16 82 * the sum of the buffer sizes.
Chris@16 83 *
Chris@16 84 * @li An error occurred.
Chris@16 85 *
Chris@16 86 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 87 * read_some function.
Chris@16 88 *
Chris@16 89 * @param s The stream from which the data is to be read. The type must support
Chris@16 90 * the SyncReadStream concept.
Chris@16 91 *
Chris@16 92 * @param buffers One or more buffers into which the data will be read. The sum
Chris@16 93 * of the buffer sizes indicates the maximum number of bytes to read from the
Chris@16 94 * stream.
Chris@16 95 *
Chris@16 96 * @param ec Set to indicate what error occurred, if any.
Chris@16 97 *
Chris@16 98 * @returns The number of bytes transferred.
Chris@16 99 *
Chris@16 100 * @par Example
Chris@16 101 * To read into a single data buffer use the @ref buffer function as follows:
Chris@16 102 * @code boost::asio::read(s, boost::asio::buffer(data, size), ec); @endcode
Chris@16 103 * See the @ref buffer documentation for information on reading into multiple
Chris@16 104 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 105 * std::vector.
Chris@16 106 *
Chris@16 107 * @note This overload is equivalent to calling:
Chris@16 108 * @code boost::asio::read(
Chris@16 109 * s, buffers,
Chris@16 110 * boost::asio::transfer_all(), ec); @endcode
Chris@16 111 */
Chris@16 112 template <typename SyncReadStream, typename MutableBufferSequence>
Chris@16 113 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
Chris@16 114 boost::system::error_code& ec);
Chris@16 115
Chris@16 116 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 117 /**
Chris@16 118 * This function is used to read a certain number of bytes of data from a
Chris@16 119 * stream. The call will block until one of the following conditions is true:
Chris@16 120 *
Chris@16 121 * @li The supplied buffers are full. That is, the bytes transferred is equal to
Chris@16 122 * the sum of the buffer sizes.
Chris@16 123 *
Chris@16 124 * @li The completion_condition function object returns 0.
Chris@16 125 *
Chris@16 126 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 127 * read_some function.
Chris@16 128 *
Chris@16 129 * @param s The stream from which the data is to be read. The type must support
Chris@16 130 * the SyncReadStream concept.
Chris@16 131 *
Chris@16 132 * @param buffers One or more buffers into which the data will be read. The sum
Chris@16 133 * of the buffer sizes indicates the maximum number of bytes to read from the
Chris@16 134 * stream.
Chris@16 135 *
Chris@16 136 * @param completion_condition The function object to be called to determine
Chris@16 137 * whether the read operation is complete. The signature of the function object
Chris@16 138 * must be:
Chris@16 139 * @code std::size_t completion_condition(
Chris@16 140 * // Result of latest read_some operation.
Chris@16 141 * const boost::system::error_code& error,
Chris@16 142 *
Chris@16 143 * // Number of bytes transferred so far.
Chris@16 144 * std::size_t bytes_transferred
Chris@16 145 * ); @endcode
Chris@16 146 * A return value of 0 indicates that the read operation is complete. A non-zero
Chris@16 147 * return value indicates the maximum number of bytes to be read on the next
Chris@16 148 * call to the stream's read_some function.
Chris@16 149 *
Chris@16 150 * @returns The number of bytes transferred.
Chris@16 151 *
Chris@16 152 * @throws boost::system::system_error Thrown on failure.
Chris@16 153 *
Chris@16 154 * @par Example
Chris@16 155 * To read into a single data buffer use the @ref buffer function as follows:
Chris@16 156 * @code boost::asio::read(s, boost::asio::buffer(data, size),
Chris@16 157 * boost::asio::transfer_at_least(32)); @endcode
Chris@16 158 * See the @ref buffer documentation for information on reading into multiple
Chris@16 159 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 160 * std::vector.
Chris@16 161 */
Chris@16 162 template <typename SyncReadStream, typename MutableBufferSequence,
Chris@16 163 typename CompletionCondition>
Chris@16 164 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
Chris@16 165 CompletionCondition completion_condition);
Chris@16 166
Chris@16 167 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 168 /**
Chris@16 169 * This function is used to read a certain number of bytes of data from a
Chris@16 170 * stream. The call will block until one of the following conditions is true:
Chris@16 171 *
Chris@16 172 * @li The supplied buffers are full. That is, the bytes transferred is equal to
Chris@16 173 * the sum of the buffer sizes.
Chris@16 174 *
Chris@16 175 * @li The completion_condition function object returns 0.
Chris@16 176 *
Chris@16 177 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 178 * read_some function.
Chris@16 179 *
Chris@16 180 * @param s The stream from which the data is to be read. The type must support
Chris@16 181 * the SyncReadStream concept.
Chris@16 182 *
Chris@16 183 * @param buffers One or more buffers into which the data will be read. The sum
Chris@16 184 * of the buffer sizes indicates the maximum number of bytes to read from the
Chris@16 185 * stream.
Chris@16 186 *
Chris@16 187 * @param completion_condition The function object to be called to determine
Chris@16 188 * whether the read operation is complete. The signature of the function object
Chris@16 189 * must be:
Chris@16 190 * @code std::size_t completion_condition(
Chris@16 191 * // Result of latest read_some operation.
Chris@16 192 * const boost::system::error_code& error,
Chris@16 193 *
Chris@16 194 * // Number of bytes transferred so far.
Chris@16 195 * std::size_t bytes_transferred
Chris@16 196 * ); @endcode
Chris@16 197 * A return value of 0 indicates that the read operation is complete. A non-zero
Chris@16 198 * return value indicates the maximum number of bytes to be read on the next
Chris@16 199 * call to the stream's read_some function.
Chris@16 200 *
Chris@16 201 * @param ec Set to indicate what error occurred, if any.
Chris@16 202 *
Chris@16 203 * @returns The number of bytes read. If an error occurs, returns the total
Chris@16 204 * number of bytes successfully transferred prior to the error.
Chris@16 205 */
Chris@16 206 template <typename SyncReadStream, typename MutableBufferSequence,
Chris@16 207 typename CompletionCondition>
Chris@16 208 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
Chris@16 209 CompletionCondition completion_condition, boost::system::error_code& ec);
Chris@16 210
Chris@16 211 #if !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 212
Chris@16 213 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 214 /**
Chris@16 215 * This function is used to read a certain number of bytes of data from a
Chris@16 216 * stream. The call will block until one of the following conditions is true:
Chris@16 217 *
Chris@16 218 * @li The supplied buffer is full (that is, it has reached maximum size).
Chris@16 219 *
Chris@16 220 * @li An error occurred.
Chris@16 221 *
Chris@16 222 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 223 * read_some function.
Chris@16 224 *
Chris@16 225 * @param s The stream from which the data is to be read. The type must support
Chris@16 226 * the SyncReadStream concept.
Chris@16 227 *
Chris@16 228 * @param b The basic_streambuf object into which the data will be read.
Chris@16 229 *
Chris@16 230 * @returns The number of bytes transferred.
Chris@16 231 *
Chris@16 232 * @throws boost::system::system_error Thrown on failure.
Chris@16 233 *
Chris@16 234 * @note This overload is equivalent to calling:
Chris@16 235 * @code boost::asio::read(
Chris@16 236 * s, b,
Chris@16 237 * boost::asio::transfer_all()); @endcode
Chris@16 238 */
Chris@16 239 template <typename SyncReadStream, typename Allocator>
Chris@16 240 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
Chris@16 241
Chris@16 242 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 243 /**
Chris@16 244 * This function is used to read a certain number of bytes of data from a
Chris@16 245 * stream. The call will block until one of the following conditions is true:
Chris@16 246 *
Chris@16 247 * @li The supplied buffer is full (that is, it has reached maximum size).
Chris@16 248 *
Chris@16 249 * @li An error occurred.
Chris@16 250 *
Chris@16 251 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 252 * read_some function.
Chris@16 253 *
Chris@16 254 * @param s The stream from which the data is to be read. The type must support
Chris@16 255 * the SyncReadStream concept.
Chris@16 256 *
Chris@16 257 * @param b The basic_streambuf object into which the data will be read.
Chris@16 258 *
Chris@16 259 * @param ec Set to indicate what error occurred, if any.
Chris@16 260 *
Chris@16 261 * @returns The number of bytes transferred.
Chris@16 262 *
Chris@16 263 * @note This overload is equivalent to calling:
Chris@16 264 * @code boost::asio::read(
Chris@16 265 * s, b,
Chris@16 266 * boost::asio::transfer_all(), ec); @endcode
Chris@16 267 */
Chris@16 268 template <typename SyncReadStream, typename Allocator>
Chris@16 269 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
Chris@16 270 boost::system::error_code& ec);
Chris@16 271
Chris@16 272 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 273 /**
Chris@16 274 * This function is used to read a certain number of bytes of data from a
Chris@16 275 * stream. The call will block until one of the following conditions is true:
Chris@16 276 *
Chris@16 277 * @li The supplied buffer is full (that is, it has reached maximum size).
Chris@16 278 *
Chris@16 279 * @li The completion_condition function object returns 0.
Chris@16 280 *
Chris@16 281 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 282 * read_some function.
Chris@16 283 *
Chris@16 284 * @param s The stream from which the data is to be read. The type must support
Chris@16 285 * the SyncReadStream concept.
Chris@16 286 *
Chris@16 287 * @param b The basic_streambuf object into which the data will be read.
Chris@16 288 *
Chris@16 289 * @param completion_condition The function object to be called to determine
Chris@16 290 * whether the read operation is complete. The signature of the function object
Chris@16 291 * must be:
Chris@16 292 * @code std::size_t completion_condition(
Chris@16 293 * // Result of latest read_some operation.
Chris@16 294 * const boost::system::error_code& error,
Chris@16 295 *
Chris@16 296 * // Number of bytes transferred so far.
Chris@16 297 * std::size_t bytes_transferred
Chris@16 298 * ); @endcode
Chris@16 299 * A return value of 0 indicates that the read operation is complete. A non-zero
Chris@16 300 * return value indicates the maximum number of bytes to be read on the next
Chris@16 301 * call to the stream's read_some function.
Chris@16 302 *
Chris@16 303 * @returns The number of bytes transferred.
Chris@16 304 *
Chris@16 305 * @throws boost::system::system_error Thrown on failure.
Chris@16 306 */
Chris@16 307 template <typename SyncReadStream, typename Allocator,
Chris@16 308 typename CompletionCondition>
Chris@16 309 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
Chris@16 310 CompletionCondition completion_condition);
Chris@16 311
Chris@16 312 /// Attempt to read a certain amount of data from a stream before returning.
Chris@16 313 /**
Chris@16 314 * This function is used to read a certain number of bytes of data from a
Chris@16 315 * stream. The call will block until one of the following conditions is true:
Chris@16 316 *
Chris@16 317 * @li The supplied buffer is full (that is, it has reached maximum size).
Chris@16 318 *
Chris@16 319 * @li The completion_condition function object returns 0.
Chris@16 320 *
Chris@16 321 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 322 * read_some function.
Chris@16 323 *
Chris@16 324 * @param s The stream from which the data is to be read. The type must support
Chris@16 325 * the SyncReadStream concept.
Chris@16 326 *
Chris@16 327 * @param b The basic_streambuf object into which the data will be read.
Chris@16 328 *
Chris@16 329 * @param completion_condition The function object to be called to determine
Chris@16 330 * whether the read operation is complete. The signature of the function object
Chris@16 331 * must be:
Chris@16 332 * @code std::size_t completion_condition(
Chris@16 333 * // Result of latest read_some operation.
Chris@16 334 * const boost::system::error_code& error,
Chris@16 335 *
Chris@16 336 * // Number of bytes transferred so far.
Chris@16 337 * std::size_t bytes_transferred
Chris@16 338 * ); @endcode
Chris@16 339 * A return value of 0 indicates that the read operation is complete. A non-zero
Chris@16 340 * return value indicates the maximum number of bytes to be read on the next
Chris@16 341 * call to the stream's read_some function.
Chris@16 342 *
Chris@16 343 * @param ec Set to indicate what error occurred, if any.
Chris@16 344 *
Chris@16 345 * @returns The number of bytes read. If an error occurs, returns the total
Chris@16 346 * number of bytes successfully transferred prior to the error.
Chris@16 347 */
Chris@16 348 template <typename SyncReadStream, typename Allocator,
Chris@16 349 typename CompletionCondition>
Chris@16 350 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
Chris@16 351 CompletionCondition completion_condition, boost::system::error_code& ec);
Chris@16 352
Chris@16 353 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 354
Chris@16 355 /*@}*/
Chris@16 356 /**
Chris@16 357 * @defgroup async_read boost::asio::async_read
Chris@16 358 *
Chris@16 359 * @brief Start an asynchronous operation to read a certain amount of data from
Chris@16 360 * a stream.
Chris@16 361 */
Chris@16 362 /*@{*/
Chris@16 363
Chris@16 364 /// Start an asynchronous operation to read a certain amount of data from a
Chris@16 365 /// stream.
Chris@16 366 /**
Chris@16 367 * This function is used to asynchronously read a certain number of bytes of
Chris@16 368 * data from a stream. The function call always returns immediately. The
Chris@16 369 * asynchronous operation will continue until one of the following conditions is
Chris@16 370 * true:
Chris@16 371 *
Chris@16 372 * @li The supplied buffers are full. That is, the bytes transferred is equal to
Chris@16 373 * the sum of the buffer sizes.
Chris@16 374 *
Chris@16 375 * @li An error occurred.
Chris@16 376 *
Chris@16 377 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 378 * async_read_some function, and is known as a <em>composed operation</em>. The
Chris@16 379 * program must ensure that the stream performs no other read operations (such
Chris@16 380 * as async_read, the stream's async_read_some function, or any other composed
Chris@16 381 * operations that perform reads) until this operation completes.
Chris@16 382 *
Chris@16 383 * @param s The stream from which the data is to be read. The type must support
Chris@16 384 * the AsyncReadStream concept.
Chris@16 385 *
Chris@16 386 * @param buffers One or more buffers into which the data will be read. The sum
Chris@16 387 * of the buffer sizes indicates the maximum number of bytes to read from the
Chris@16 388 * stream. Although the buffers object may be copied as necessary, ownership of
Chris@16 389 * the underlying memory blocks is retained by the caller, which must guarantee
Chris@16 390 * that they remain valid until the handler is called.
Chris@16 391 *
Chris@16 392 * @param handler The handler to be called when the read operation completes.
Chris@16 393 * Copies will be made of the handler as required. The function signature of the
Chris@16 394 * handler must be:
Chris@16 395 * @code void handler(
Chris@16 396 * const boost::system::error_code& error, // Result of operation.
Chris@16 397 *
Chris@16 398 * std::size_t bytes_transferred // Number of bytes copied into the
Chris@16 399 * // buffers. If an error occurred,
Chris@16 400 * // this will be the number of
Chris@16 401 * // bytes successfully transferred
Chris@16 402 * // prior to the error.
Chris@16 403 * ); @endcode
Chris@16 404 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 405 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 406 * the handler will be performed in a manner equivalent to using
Chris@16 407 * boost::asio::io_service::post().
Chris@16 408 *
Chris@16 409 * @par Example
Chris@16 410 * To read into a single data buffer use the @ref buffer function as follows:
Chris@16 411 * @code
Chris@16 412 * boost::asio::async_read(s, boost::asio::buffer(data, size), handler);
Chris@16 413 * @endcode
Chris@16 414 * See the @ref buffer documentation for information on reading into multiple
Chris@16 415 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 416 * std::vector.
Chris@16 417 *
Chris@16 418 * @note This overload is equivalent to calling:
Chris@16 419 * @code boost::asio::async_read(
Chris@16 420 * s, buffers,
Chris@16 421 * boost::asio::transfer_all(),
Chris@16 422 * handler); @endcode
Chris@16 423 */
Chris@16 424 template <typename AsyncReadStream, typename MutableBufferSequence,
Chris@16 425 typename ReadHandler>
Chris@16 426 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Chris@16 427 void (boost::system::error_code, std::size_t))
Chris@16 428 async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
Chris@16 429 BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
Chris@16 430
Chris@16 431 /// Start an asynchronous operation to read a certain amount of data from a
Chris@16 432 /// stream.
Chris@16 433 /**
Chris@16 434 * This function is used to asynchronously read a certain number of bytes of
Chris@16 435 * data from a stream. The function call always returns immediately. The
Chris@16 436 * asynchronous operation will continue until one of the following conditions is
Chris@16 437 * true:
Chris@16 438 *
Chris@16 439 * @li The supplied buffers are full. That is, the bytes transferred is equal to
Chris@16 440 * the sum of the buffer sizes.
Chris@16 441 *
Chris@16 442 * @li The completion_condition function object returns 0.
Chris@16 443 *
Chris@16 444 * @param s The stream from which the data is to be read. The type must support
Chris@16 445 * the AsyncReadStream concept.
Chris@16 446 *
Chris@16 447 * @param buffers One or more buffers into which the data will be read. The sum
Chris@16 448 * of the buffer sizes indicates the maximum number of bytes to read from the
Chris@16 449 * stream. Although the buffers object may be copied as necessary, ownership of
Chris@16 450 * the underlying memory blocks is retained by the caller, which must guarantee
Chris@16 451 * that they remain valid until the handler is called.
Chris@16 452 *
Chris@16 453 * @param completion_condition The function object to be called to determine
Chris@16 454 * whether the read operation is complete. The signature of the function object
Chris@16 455 * must be:
Chris@16 456 * @code std::size_t completion_condition(
Chris@16 457 * // Result of latest async_read_some operation.
Chris@16 458 * const boost::system::error_code& error,
Chris@16 459 *
Chris@16 460 * // Number of bytes transferred so far.
Chris@16 461 * std::size_t bytes_transferred
Chris@16 462 * ); @endcode
Chris@16 463 * A return value of 0 indicates that the read operation is complete. A non-zero
Chris@16 464 * return value indicates the maximum number of bytes to be read on the next
Chris@16 465 * call to the stream's async_read_some function.
Chris@16 466 *
Chris@16 467 * @param handler The handler to be called when the read operation completes.
Chris@16 468 * Copies will be made of the handler as required. The function signature of the
Chris@16 469 * handler must be:
Chris@16 470 * @code void handler(
Chris@16 471 * const boost::system::error_code& error, // Result of operation.
Chris@16 472 *
Chris@16 473 * std::size_t bytes_transferred // Number of bytes copied into the
Chris@16 474 * // buffers. If an error occurred,
Chris@16 475 * // this will be the number of
Chris@16 476 * // bytes successfully transferred
Chris@16 477 * // prior to the error.
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 of
Chris@16 481 * 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 * @par Example
Chris@16 485 * To read into a single data buffer use the @ref buffer function as follows:
Chris@16 486 * @code boost::asio::async_read(s,
Chris@16 487 * boost::asio::buffer(data, size),
Chris@16 488 * boost::asio::transfer_at_least(32),
Chris@16 489 * handler); @endcode
Chris@16 490 * See the @ref buffer documentation for information on reading into multiple
Chris@16 491 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 492 * std::vector.
Chris@16 493 */
Chris@16 494 template <typename AsyncReadStream, typename MutableBufferSequence,
Chris@16 495 typename CompletionCondition, typename ReadHandler>
Chris@16 496 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Chris@16 497 void (boost::system::error_code, std::size_t))
Chris@16 498 async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
Chris@16 499 CompletionCondition completion_condition,
Chris@16 500 BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
Chris@16 501
Chris@16 502 #if !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 503
Chris@16 504 /// Start an asynchronous operation to read a certain amount of data from a
Chris@16 505 /// stream.
Chris@16 506 /**
Chris@16 507 * This function is used to asynchronously read a certain number of bytes of
Chris@16 508 * data from a stream. The function call always returns immediately. The
Chris@16 509 * asynchronous operation will continue until one of the following conditions is
Chris@16 510 * true:
Chris@16 511 *
Chris@16 512 * @li The supplied buffer is full (that is, it has reached maximum size).
Chris@16 513 *
Chris@16 514 * @li An error occurred.
Chris@16 515 *
Chris@16 516 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 517 * async_read_some function, and is known as a <em>composed operation</em>. The
Chris@16 518 * program must ensure that the stream performs no other read operations (such
Chris@16 519 * as async_read, the stream's async_read_some function, or any other composed
Chris@16 520 * operations that perform reads) until this operation completes.
Chris@16 521 *
Chris@16 522 * @param s The stream from which the data is to be read. The type must support
Chris@16 523 * the AsyncReadStream concept.
Chris@16 524 *
Chris@16 525 * @param b A basic_streambuf object into which the data will be read. Ownership
Chris@16 526 * of the streambuf is retained by the caller, which must guarantee that it
Chris@16 527 * remains valid until the handler is called.
Chris@16 528 *
Chris@16 529 * @param handler The handler to be called when the read operation completes.
Chris@16 530 * Copies will be made of the handler as required. The function signature of the
Chris@16 531 * handler must be:
Chris@16 532 * @code void handler(
Chris@16 533 * const boost::system::error_code& error, // Result of operation.
Chris@16 534 *
Chris@16 535 * std::size_t bytes_transferred // Number of bytes copied into the
Chris@16 536 * // buffers. If an error occurred,
Chris@16 537 * // this will be the number of
Chris@16 538 * // bytes successfully transferred
Chris@16 539 * // prior to the error.
Chris@16 540 * ); @endcode
Chris@16 541 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 542 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 543 * the handler will be performed in a manner equivalent to using
Chris@16 544 * boost::asio::io_service::post().
Chris@16 545 *
Chris@16 546 * @note This overload is equivalent to calling:
Chris@16 547 * @code boost::asio::async_read(
Chris@16 548 * s, b,
Chris@16 549 * boost::asio::transfer_all(),
Chris@16 550 * handler); @endcode
Chris@16 551 */
Chris@16 552 template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
Chris@16 553 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Chris@16 554 void (boost::system::error_code, std::size_t))
Chris@16 555 async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
Chris@16 556 BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
Chris@16 557
Chris@16 558 /// Start an asynchronous operation to read a certain amount of data from a
Chris@16 559 /// stream.
Chris@16 560 /**
Chris@16 561 * This function is used to asynchronously read a certain number of bytes of
Chris@16 562 * data from a stream. The function call always returns immediately. The
Chris@16 563 * asynchronous operation will continue until one of the following conditions is
Chris@16 564 * true:
Chris@16 565 *
Chris@16 566 * @li The supplied buffer is full (that is, it has reached maximum size).
Chris@16 567 *
Chris@16 568 * @li The completion_condition function object returns 0.
Chris@16 569 *
Chris@16 570 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 571 * async_read_some function, and is known as a <em>composed operation</em>. The
Chris@16 572 * program must ensure that the stream performs no other read operations (such
Chris@16 573 * as async_read, the stream's async_read_some function, or any other composed
Chris@16 574 * operations that perform reads) until this operation completes.
Chris@16 575 *
Chris@16 576 * @param s The stream from which the data is to be read. The type must support
Chris@16 577 * the AsyncReadStream concept.
Chris@16 578 *
Chris@16 579 * @param b A basic_streambuf object into which the data will be read. Ownership
Chris@16 580 * of the streambuf is retained by the caller, which must guarantee that it
Chris@16 581 * remains valid until the handler is called.
Chris@16 582 *
Chris@16 583 * @param completion_condition The function object to be called to determine
Chris@16 584 * whether the read operation is complete. The signature of the function object
Chris@16 585 * must be:
Chris@16 586 * @code std::size_t completion_condition(
Chris@16 587 * // Result of latest async_read_some operation.
Chris@16 588 * const boost::system::error_code& error,
Chris@16 589 *
Chris@16 590 * // Number of bytes transferred so far.
Chris@16 591 * std::size_t bytes_transferred
Chris@16 592 * ); @endcode
Chris@16 593 * A return value of 0 indicates that the read operation is complete. A non-zero
Chris@16 594 * return value indicates the maximum number of bytes to be read on the next
Chris@16 595 * call to the stream's async_read_some function.
Chris@16 596 *
Chris@16 597 * @param handler The handler to be called when the read operation completes.
Chris@16 598 * Copies will be made of the handler as required. The function signature of the
Chris@16 599 * handler must be:
Chris@16 600 * @code void handler(
Chris@16 601 * const boost::system::error_code& error, // Result of operation.
Chris@16 602 *
Chris@16 603 * std::size_t bytes_transferred // Number of bytes copied into the
Chris@16 604 * // buffers. If an error occurred,
Chris@16 605 * // this will be the number of
Chris@16 606 * // bytes successfully transferred
Chris@16 607 * // prior to the error.
Chris@16 608 * ); @endcode
Chris@16 609 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 610 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 611 * the handler will be performed in a manner equivalent to using
Chris@16 612 * boost::asio::io_service::post().
Chris@16 613 */
Chris@16 614 template <typename AsyncReadStream, typename Allocator,
Chris@16 615 typename CompletionCondition, typename ReadHandler>
Chris@16 616 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Chris@16 617 void (boost::system::error_code, std::size_t))
Chris@16 618 async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
Chris@16 619 CompletionCondition completion_condition,
Chris@16 620 BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
Chris@16 621
Chris@16 622 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 623
Chris@16 624 /*@}*/
Chris@16 625
Chris@16 626 } // namespace asio
Chris@16 627 } // namespace boost
Chris@16 628
Chris@16 629 #include <boost/asio/detail/pop_options.hpp>
Chris@16 630
Chris@16 631 #include <boost/asio/impl/read.hpp>
Chris@16 632
Chris@16 633 #endif // BOOST_ASIO_READ_HPP