5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_READ_HPP
12 #define BOOST_ASIO_READ_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #include <boost/asio/async_result.hpp>
21 #include <boost/asio/buffer.hpp>
22 #include <boost/asio/error.hpp>
24 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
25 # include <boost/asio/basic_streambuf_fwd.hpp>
26 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
28 #include <boost/asio/detail/push_options.hpp>
34 * @defgroup read boost::asio::read
36 * @brief Attempt to read a certain amount of data from a stream before
41 /// Attempt to read a certain amount of data from a stream before returning.
43 * This function is used to read a certain number of bytes of data from a
44 * stream. The call will block until one of the following conditions is true:
46 * @li The supplied buffers are full. That is, the bytes transferred is equal to
47 * the sum of the buffer sizes.
49 * @li An error occurred.
51 * This operation is implemented in terms of zero or more calls to the stream's
54 * @param s The stream from which the data is to be read. The type must support
55 * the SyncReadStream concept.
57 * @param buffers One or more buffers into which the data will be read. The sum
58 * of the buffer sizes indicates the maximum number of bytes to read from the
61 * @returns The number of bytes transferred.
63 * @throws boost::system::system_error Thrown on failure.
66 * To read into a single data buffer use the @ref buffer function as follows:
67 * @code boost::asio::read(s, boost::asio::buffer(data, size)); @endcode
68 * See the @ref buffer documentation for information on reading into multiple
69 * buffers in one go, and how to use it with arrays, boost::array or
72 * @note This overload is equivalent to calling:
73 * @code boost::asio::read(
75 * boost::asio::transfer_all()); @endcode
77 template <typename SyncReadStream, typename MutableBufferSequence>
78 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
80 is_mutable_buffer_sequence<MutableBufferSequence>::value
83 /// Attempt to read a certain amount of data from a stream before returning.
85 * This function is used to read a certain number of bytes of data from a
86 * stream. The call will block until one of the following conditions is true:
88 * @li The supplied buffers are full. That is, the bytes transferred is equal to
89 * the sum of the buffer sizes.
91 * @li An error occurred.
93 * This operation is implemented in terms of zero or more calls to the stream's
96 * @param s The stream from which the data is to be read. The type must support
97 * the SyncReadStream concept.
99 * @param buffers One or more buffers into which the data will be read. The sum
100 * of the buffer sizes indicates the maximum number of bytes to read from the
103 * @param ec Set to indicate what error occurred, if any.
105 * @returns The number of bytes transferred.
108 * To read into a single data buffer use the @ref buffer function as follows:
109 * @code boost::asio::read(s, boost::asio::buffer(data, size), ec); @endcode
110 * See the @ref buffer documentation for information on reading into multiple
111 * buffers in one go, and how to use it with arrays, boost::array or
114 * @note This overload is equivalent to calling:
115 * @code boost::asio::read(
117 * boost::asio::transfer_all(), ec); @endcode
119 template <typename SyncReadStream, typename MutableBufferSequence>
120 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
121 boost::system::error_code& ec,
123 is_mutable_buffer_sequence<MutableBufferSequence>::value
126 /// Attempt to read a certain amount of data from a stream before returning.
128 * This function is used to read a certain number of bytes of data from a
129 * stream. The call will block until one of the following conditions is true:
131 * @li The supplied buffers are full. That is, the bytes transferred is equal to
132 * the sum of the buffer sizes.
134 * @li The completion_condition function object returns 0.
136 * This operation is implemented in terms of zero or more calls to the stream's
137 * read_some function.
139 * @param s The stream from which the data is to be read. The type must support
140 * the SyncReadStream concept.
142 * @param buffers One or more buffers into which the data will be read. The sum
143 * of the buffer sizes indicates the maximum number of bytes to read from the
146 * @param completion_condition The function object to be called to determine
147 * whether the read operation is complete. The signature of the function object
149 * @code std::size_t completion_condition(
150 * // Result of latest read_some operation.
151 * const boost::system::error_code& error,
153 * // Number of bytes transferred so far.
154 * std::size_t bytes_transferred
156 * A return value of 0 indicates that the read operation is complete. A non-zero
157 * return value indicates the maximum number of bytes to be read on the next
158 * call to the stream's read_some function.
160 * @returns The number of bytes transferred.
162 * @throws boost::system::system_error Thrown on failure.
165 * To read into a single data buffer use the @ref buffer function as follows:
166 * @code boost::asio::read(s, boost::asio::buffer(data, size),
167 * boost::asio::transfer_at_least(32)); @endcode
168 * See the @ref buffer documentation for information on reading into multiple
169 * buffers in one go, and how to use it with arrays, boost::array or
172 template <typename SyncReadStream, typename MutableBufferSequence,
173 typename CompletionCondition>
174 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
175 CompletionCondition completion_condition,
177 is_mutable_buffer_sequence<MutableBufferSequence>::value
180 /// Attempt to read a certain amount of data from a stream before returning.
182 * This function is used to read a certain number of bytes of data from a
183 * stream. The call will block until one of the following conditions is true:
185 * @li The supplied buffers are full. That is, the bytes transferred is equal to
186 * the sum of the buffer sizes.
188 * @li The completion_condition function object returns 0.
190 * This operation is implemented in terms of zero or more calls to the stream's
191 * read_some function.
193 * @param s The stream from which the data is to be read. The type must support
194 * the SyncReadStream concept.
196 * @param buffers One or more buffers into which the data will be read. The sum
197 * of the buffer sizes indicates the maximum number of bytes to read from the
200 * @param completion_condition The function object to be called to determine
201 * whether the read operation is complete. The signature of the function object
203 * @code std::size_t completion_condition(
204 * // Result of latest read_some operation.
205 * const boost::system::error_code& error,
207 * // Number of bytes transferred so far.
208 * std::size_t bytes_transferred
210 * A return value of 0 indicates that the read operation is complete. A non-zero
211 * return value indicates the maximum number of bytes to be read on the next
212 * call to the stream's read_some function.
214 * @param ec Set to indicate what error occurred, if any.
216 * @returns The number of bytes read. If an error occurs, returns the total
217 * number of bytes successfully transferred prior to the error.
219 template <typename SyncReadStream, typename MutableBufferSequence,
220 typename CompletionCondition>
221 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
222 CompletionCondition completion_condition, boost::system::error_code& ec,
224 is_mutable_buffer_sequence<MutableBufferSequence>::value
227 /// Attempt to read a certain amount of data from a stream before returning.
229 * This function is used to read a certain number of bytes of data from a
230 * stream. The call will block until one of the following conditions is true:
232 * @li The specified dynamic buffer sequence is full (that is, it has reached
235 * @li An error occurred.
237 * This operation is implemented in terms of zero or more calls to the stream's
238 * read_some function.
240 * @param s The stream from which the data is to be read. The type must support
241 * the SyncReadStream concept.
243 * @param buffers The dynamic buffer sequence into which the data will be read.
245 * @returns The number of bytes transferred.
247 * @throws boost::system::system_error Thrown on failure.
249 * @note This overload is equivalent to calling:
250 * @code boost::asio::read(
252 * boost::asio::transfer_all()); @endcode
254 template <typename SyncReadStream, typename DynamicBuffer>
255 std::size_t read(SyncReadStream& s,
256 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
258 is_dynamic_buffer<DynamicBuffer>::value
261 /// Attempt to read a certain amount of data from a stream before returning.
263 * This function is used to read a certain number of bytes of data from a
264 * stream. The call will block until one of the following conditions is true:
266 * @li The supplied buffer is full (that is, it has reached maximum size).
268 * @li An error occurred.
270 * This operation is implemented in terms of zero or more calls to the stream's
271 * read_some function.
273 * @param s The stream from which the data is to be read. The type must support
274 * the SyncReadStream concept.
276 * @param buffers The dynamic buffer sequence into which the data will be read.
278 * @param ec Set to indicate what error occurred, if any.
280 * @returns The number of bytes transferred.
282 * @note This overload is equivalent to calling:
283 * @code boost::asio::read(
285 * boost::asio::transfer_all(), ec); @endcode
287 template <typename SyncReadStream, typename DynamicBuffer>
288 std::size_t read(SyncReadStream& s,
289 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
290 boost::system::error_code& ec,
292 is_dynamic_buffer<DynamicBuffer>::value
295 /// Attempt to read a certain amount of data from a stream before returning.
297 * This function is used to read a certain number of bytes of data from a
298 * stream. The call will block until one of the following conditions is true:
300 * @li The specified dynamic buffer sequence is full (that is, it has reached
303 * @li The completion_condition function object returns 0.
305 * This operation is implemented in terms of zero or more calls to the stream's
306 * read_some function.
308 * @param s The stream from which the data is to be read. The type must support
309 * the SyncReadStream concept.
311 * @param buffers The dynamic buffer sequence into which the data will be read.
313 * @param completion_condition The function object to be called to determine
314 * whether the read operation is complete. The signature of the function object
316 * @code std::size_t completion_condition(
317 * // Result of latest read_some operation.
318 * const boost::system::error_code& error,
320 * // Number of bytes transferred so far.
321 * std::size_t bytes_transferred
323 * A return value of 0 indicates that the read operation is complete. A non-zero
324 * return value indicates the maximum number of bytes to be read on the next
325 * call to the stream's read_some function.
327 * @returns The number of bytes transferred.
329 * @throws boost::system::system_error Thrown on failure.
331 template <typename SyncReadStream, typename DynamicBuffer,
332 typename CompletionCondition>
333 std::size_t read(SyncReadStream& s,
334 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
335 CompletionCondition completion_condition,
337 is_dynamic_buffer<DynamicBuffer>::value
340 /// Attempt to read a certain amount of data from a stream before returning.
342 * This function is used to read a certain number of bytes of data from a
343 * stream. The call will block until one of the following conditions is true:
345 * @li The specified dynamic buffer sequence is full (that is, it has reached
348 * @li The completion_condition function object returns 0.
350 * This operation is implemented in terms of zero or more calls to the stream's
351 * read_some function.
353 * @param s The stream from which the data is to be read. The type must support
354 * the SyncReadStream concept.
356 * @param buffers The dynamic buffer sequence into which the data will be read.
358 * @param completion_condition The function object to be called to determine
359 * whether the read operation is complete. The signature of the function object
361 * @code std::size_t completion_condition(
362 * // Result of latest read_some operation.
363 * const boost::system::error_code& error,
365 * // Number of bytes transferred so far.
366 * std::size_t bytes_transferred
368 * A return value of 0 indicates that the read operation is complete. A non-zero
369 * return value indicates the maximum number of bytes to be read on the next
370 * call to the stream's read_some function.
372 * @param ec Set to indicate what error occurred, if any.
374 * @returns The number of bytes read. If an error occurs, returns the total
375 * number of bytes successfully transferred prior to the error.
377 template <typename SyncReadStream, typename DynamicBuffer,
378 typename CompletionCondition>
379 std::size_t read(SyncReadStream& s,
380 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
381 CompletionCondition completion_condition, boost::system::error_code& ec,
383 is_dynamic_buffer<DynamicBuffer>::value
386 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
387 #if !defined(BOOST_ASIO_NO_IOSTREAM)
389 /// Attempt to read a certain amount of data from a stream before returning.
391 * This function is used to read a certain number of bytes of data from a
392 * stream. The call will block until one of the following conditions is true:
394 * @li The supplied buffer is full (that is, it has reached maximum size).
396 * @li An error occurred.
398 * This operation is implemented in terms of zero or more calls to the stream's
399 * read_some function.
401 * @param s The stream from which the data is to be read. The type must support
402 * the SyncReadStream concept.
404 * @param b The basic_streambuf object into which the data will be read.
406 * @returns The number of bytes transferred.
408 * @throws boost::system::system_error Thrown on failure.
410 * @note This overload is equivalent to calling:
411 * @code boost::asio::read(
413 * boost::asio::transfer_all()); @endcode
415 template <typename SyncReadStream, typename Allocator>
416 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
418 /// Attempt to read a certain amount of data from a stream before returning.
420 * This function is used to read a certain number of bytes of data from a
421 * stream. The call will block until one of the following conditions is true:
423 * @li The supplied buffer is full (that is, it has reached maximum size).
425 * @li An error occurred.
427 * This operation is implemented in terms of zero or more calls to the stream's
428 * read_some function.
430 * @param s The stream from which the data is to be read. The type must support
431 * the SyncReadStream concept.
433 * @param b The basic_streambuf object into which the data will be read.
435 * @param ec Set to indicate what error occurred, if any.
437 * @returns The number of bytes transferred.
439 * @note This overload is equivalent to calling:
440 * @code boost::asio::read(
442 * boost::asio::transfer_all(), ec); @endcode
444 template <typename SyncReadStream, typename Allocator>
445 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
446 boost::system::error_code& ec);
448 /// Attempt to read a certain amount of data from a stream before returning.
450 * This function is used to read a certain number of bytes of data from a
451 * stream. The call will block until one of the following conditions is true:
453 * @li The supplied buffer is full (that is, it has reached maximum size).
455 * @li The completion_condition function object returns 0.
457 * This operation is implemented in terms of zero or more calls to the stream's
458 * read_some function.
460 * @param s The stream from which the data is to be read. The type must support
461 * the SyncReadStream concept.
463 * @param b The basic_streambuf object into which the data will be read.
465 * @param completion_condition The function object to be called to determine
466 * whether the read operation is complete. The signature of the function object
468 * @code std::size_t completion_condition(
469 * // Result of latest read_some operation.
470 * const boost::system::error_code& error,
472 * // Number of bytes transferred so far.
473 * std::size_t bytes_transferred
475 * A return value of 0 indicates that the read operation is complete. A non-zero
476 * return value indicates the maximum number of bytes to be read on the next
477 * call to the stream's read_some function.
479 * @returns The number of bytes transferred.
481 * @throws boost::system::system_error Thrown on failure.
483 template <typename SyncReadStream, typename Allocator,
484 typename CompletionCondition>
485 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
486 CompletionCondition completion_condition);
488 /// Attempt to read a certain amount of data from a stream before returning.
490 * This function is used to read a certain number of bytes of data from a
491 * stream. The call will block until one of the following conditions is true:
493 * @li The supplied buffer is full (that is, it has reached maximum size).
495 * @li The completion_condition function object returns 0.
497 * This operation is implemented in terms of zero or more calls to the stream's
498 * read_some function.
500 * @param s The stream from which the data is to be read. The type must support
501 * the SyncReadStream concept.
503 * @param b The basic_streambuf object into which the data will be read.
505 * @param completion_condition The function object to be called to determine
506 * whether the read operation is complete. The signature of the function object
508 * @code std::size_t completion_condition(
509 * // Result of latest read_some operation.
510 * const boost::system::error_code& error,
512 * // Number of bytes transferred so far.
513 * std::size_t bytes_transferred
515 * A return value of 0 indicates that the read operation is complete. A non-zero
516 * return value indicates the maximum number of bytes to be read on the next
517 * call to the stream's read_some function.
519 * @param ec Set to indicate what error occurred, if any.
521 * @returns The number of bytes read. If an error occurs, returns the total
522 * number of bytes successfully transferred prior to the error.
524 template <typename SyncReadStream, typename Allocator,
525 typename CompletionCondition>
526 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
527 CompletionCondition completion_condition, boost::system::error_code& ec);
529 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
530 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
534 * @defgroup async_read boost::asio::async_read
536 * @brief Start an asynchronous operation to read a certain amount of data from
541 /// Start an asynchronous operation to read a certain amount of data from a
544 * This function is used to asynchronously read a certain number of bytes of
545 * data from a stream. The function call always returns immediately. The
546 * asynchronous operation will continue until one of the following conditions is
549 * @li The supplied buffers are full. That is, the bytes transferred is equal to
550 * the sum of the buffer sizes.
552 * @li An error occurred.
554 * This operation is implemented in terms of zero or more calls to the stream's
555 * async_read_some function, and is known as a <em>composed operation</em>. The
556 * program must ensure that the stream performs no other read operations (such
557 * as async_read, the stream's async_read_some function, or any other composed
558 * operations that perform reads) until this operation completes.
560 * @param s The stream from which the data is to be read. The type must support
561 * the AsyncReadStream concept.
563 * @param buffers One or more buffers into which the data will be read. The sum
564 * of the buffer sizes indicates the maximum number of bytes to read from the
565 * stream. Although the buffers object may be copied as necessary, ownership of
566 * the underlying memory blocks is retained by the caller, which must guarantee
567 * that they remain valid until the handler is called.
569 * @param handler The handler to be called when the read operation completes.
570 * Copies will be made of the handler as required. The function signature of the
572 * @code void handler(
573 * const boost::system::error_code& error, // Result of operation.
575 * std::size_t bytes_transferred // Number of bytes copied into the
576 * // buffers. If an error occurred,
577 * // this will be the number of
578 * // bytes successfully transferred
579 * // prior to the error.
581 * Regardless of whether the asynchronous operation completes immediately or
582 * not, the handler will not be invoked from within this function. Invocation of
583 * the handler will be performed in a manner equivalent to using
584 * boost::asio::io_context::post().
587 * To read into a single data buffer use the @ref buffer function as follows:
589 * boost::asio::async_read(s, boost::asio::buffer(data, size), handler);
591 * See the @ref buffer documentation for information on reading into multiple
592 * buffers in one go, and how to use it with arrays, boost::array or
595 * @note This overload is equivalent to calling:
596 * @code boost::asio::async_read(
598 * boost::asio::transfer_all(),
601 template <typename AsyncReadStream, typename MutableBufferSequence,
602 typename ReadHandler>
603 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
604 void (boost::system::error_code, std::size_t))
605 async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
606 BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
608 is_mutable_buffer_sequence<MutableBufferSequence>::value
611 /// Start an asynchronous operation to read a certain amount of data from a
614 * This function is used to asynchronously read a certain number of bytes of
615 * data from a stream. The function call always returns immediately. The
616 * asynchronous operation will continue until one of the following conditions is
619 * @li The supplied buffers are full. That is, the bytes transferred is equal to
620 * the sum of the buffer sizes.
622 * @li The completion_condition function object returns 0.
624 * @param s The stream from which the data is to be read. The type must support
625 * the AsyncReadStream concept.
627 * @param buffers One or more buffers into which the data will be read. The sum
628 * of the buffer sizes indicates the maximum number of bytes to read from the
629 * stream. Although the buffers object may be copied as necessary, ownership of
630 * the underlying memory blocks is retained by the caller, which must guarantee
631 * that they remain valid until the handler is called.
633 * @param completion_condition The function object to be called to determine
634 * whether the read operation is complete. The signature of the function object
636 * @code std::size_t completion_condition(
637 * // Result of latest async_read_some operation.
638 * const boost::system::error_code& error,
640 * // Number of bytes transferred so far.
641 * std::size_t bytes_transferred
643 * A return value of 0 indicates that the read operation is complete. A non-zero
644 * return value indicates the maximum number of bytes to be read on the next
645 * call to the stream's async_read_some function.
647 * @param handler The handler to be called when the read operation completes.
648 * Copies will be made of the handler as required. The function signature of the
650 * @code void handler(
651 * const boost::system::error_code& error, // Result of operation.
653 * std::size_t bytes_transferred // Number of bytes copied into the
654 * // buffers. If an error occurred,
655 * // this will be the number of
656 * // bytes successfully transferred
657 * // prior to the error.
659 * Regardless of whether the asynchronous operation completes immediately or
660 * not, the handler will not be invoked from within this function. Invocation of
661 * the handler will be performed in a manner equivalent to using
662 * boost::asio::io_context::post().
665 * To read into a single data buffer use the @ref buffer function as follows:
666 * @code boost::asio::async_read(s,
667 * boost::asio::buffer(data, size),
668 * boost::asio::transfer_at_least(32),
670 * See the @ref buffer documentation for information on reading into multiple
671 * buffers in one go, and how to use it with arrays, boost::array or
674 template <typename AsyncReadStream, typename MutableBufferSequence,
675 typename CompletionCondition, typename ReadHandler>
676 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
677 void (boost::system::error_code, std::size_t))
678 async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
679 CompletionCondition completion_condition,
680 BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
682 is_mutable_buffer_sequence<MutableBufferSequence>::value
685 /// Start an asynchronous operation to read a certain amount of data from a
688 * This function is used to asynchronously read a certain number of bytes of
689 * data from a stream. The function call always returns immediately. The
690 * asynchronous operation will continue until one of the following conditions is
693 * @li The specified dynamic buffer sequence is full (that is, it has reached
696 * @li An error occurred.
698 * This operation is implemented in terms of zero or more calls to the stream's
699 * async_read_some function, and is known as a <em>composed operation</em>. The
700 * program must ensure that the stream performs no other read operations (such
701 * as async_read, the stream's async_read_some function, or any other composed
702 * operations that perform reads) until this operation completes.
704 * @param s The stream from which the data is to be read. The type must support
705 * the AsyncReadStream concept.
707 * @param buffers The dynamic buffer sequence into which the data will be read.
708 * Although the buffers object may be copied as necessary, ownership of the
709 * underlying memory blocks is retained by the caller, which must guarantee
710 * that they remain valid until the handler is called.
712 * @param handler The handler to be called when the read operation completes.
713 * Copies will be made of the handler as required. The function signature of the
715 * @code void handler(
716 * const boost::system::error_code& error, // Result of operation.
718 * std::size_t bytes_transferred // Number of bytes copied into the
719 * // buffers. If an error occurred,
720 * // this will be the number of
721 * // bytes successfully transferred
722 * // prior to the error.
724 * Regardless of whether the asynchronous operation completes immediately or
725 * not, the handler will not be invoked from within this function. Invocation of
726 * the handler will be performed in a manner equivalent to using
727 * boost::asio::io_context::post().
729 * @note This overload is equivalent to calling:
730 * @code boost::asio::async_read(
732 * boost::asio::transfer_all(),
735 template <typename AsyncReadStream,
736 typename DynamicBuffer, typename ReadHandler>
737 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
738 void (boost::system::error_code, std::size_t))
739 async_read(AsyncReadStream& s,
740 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
741 BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
743 is_dynamic_buffer<DynamicBuffer>::value
746 /// Start an asynchronous operation to read a certain amount of data from a
749 * This function is used to asynchronously read a certain number of bytes of
750 * data from a stream. The function call always returns immediately. The
751 * asynchronous operation will continue until one of the following conditions is
754 * @li The specified dynamic buffer sequence is full (that is, it has reached
757 * @li The completion_condition function object returns 0.
759 * This operation is implemented in terms of zero or more calls to the stream's
760 * async_read_some function, and is known as a <em>composed operation</em>. The
761 * program must ensure that the stream performs no other read operations (such
762 * as async_read, the stream's async_read_some function, or any other composed
763 * operations that perform reads) until this operation completes.
765 * @param s The stream from which the data is to be read. The type must support
766 * the AsyncReadStream concept.
768 * @param buffers The dynamic buffer sequence into which the data will be read.
769 * Although the buffers object may be copied as necessary, ownership of the
770 * underlying memory blocks is retained by the caller, which must guarantee
771 * that they remain valid until the handler is called.
773 * @param completion_condition The function object to be called to determine
774 * whether the read operation is complete. The signature of the function object
776 * @code std::size_t completion_condition(
777 * // Result of latest async_read_some operation.
778 * const boost::system::error_code& error,
780 * // Number of bytes transferred so far.
781 * std::size_t bytes_transferred
783 * A return value of 0 indicates that the read operation is complete. A non-zero
784 * return value indicates the maximum number of bytes to be read on the next
785 * call to the stream's async_read_some function.
787 * @param handler The handler to be called when the read operation completes.
788 * Copies will be made of the handler as required. The function signature of the
790 * @code void handler(
791 * const boost::system::error_code& error, // Result of operation.
793 * std::size_t bytes_transferred // Number of bytes copied into the
794 * // buffers. If an error occurred,
795 * // this will be the number of
796 * // bytes successfully transferred
797 * // prior to the error.
799 * Regardless of whether the asynchronous operation completes immediately or
800 * not, the handler will not be invoked from within this function. Invocation of
801 * the handler will be performed in a manner equivalent to using
802 * boost::asio::io_context::post().
804 template <typename AsyncReadStream, typename DynamicBuffer,
805 typename CompletionCondition, typename ReadHandler>
806 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
807 void (boost::system::error_code, std::size_t))
808 async_read(AsyncReadStream& s,
809 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
810 CompletionCondition completion_condition,
811 BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
813 is_dynamic_buffer<DynamicBuffer>::value
816 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
817 #if !defined(BOOST_ASIO_NO_IOSTREAM)
819 /// Start an asynchronous operation to read a certain amount of data from a
822 * This function is used to asynchronously read a certain number of bytes of
823 * data from a stream. The function call always returns immediately. The
824 * asynchronous operation will continue until one of the following conditions is
827 * @li The supplied buffer is full (that is, it has reached maximum size).
829 * @li An error occurred.
831 * This operation is implemented in terms of zero or more calls to the stream's
832 * async_read_some function, and is known as a <em>composed operation</em>. The
833 * program must ensure that the stream performs no other read operations (such
834 * as async_read, the stream's async_read_some function, or any other composed
835 * operations that perform reads) until this operation completes.
837 * @param s The stream from which the data is to be read. The type must support
838 * the AsyncReadStream concept.
840 * @param b A basic_streambuf object into which the data will be read. Ownership
841 * of the streambuf is retained by the caller, which must guarantee that it
842 * remains valid until the handler is called.
844 * @param handler The handler to be called when the read operation completes.
845 * Copies will be made of the handler as required. The function signature of the
847 * @code void handler(
848 * const boost::system::error_code& error, // Result of operation.
850 * std::size_t bytes_transferred // Number of bytes copied into the
851 * // buffers. If an error occurred,
852 * // this will be the number of
853 * // bytes successfully transferred
854 * // prior to the error.
856 * Regardless of whether the asynchronous operation completes immediately or
857 * not, the handler will not be invoked from within this function. Invocation of
858 * the handler will be performed in a manner equivalent to using
859 * boost::asio::io_context::post().
861 * @note This overload is equivalent to calling:
862 * @code boost::asio::async_read(
864 * boost::asio::transfer_all(),
867 template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
868 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
869 void (boost::system::error_code, std::size_t))
870 async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
871 BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
873 /// Start an asynchronous operation to read a certain amount of data from a
876 * This function is used to asynchronously read a certain number of bytes of
877 * data from a stream. The function call always returns immediately. The
878 * asynchronous operation will continue until one of the following conditions is
881 * @li The supplied buffer is full (that is, it has reached maximum size).
883 * @li The completion_condition function object returns 0.
885 * This operation is implemented in terms of zero or more calls to the stream's
886 * async_read_some function, and is known as a <em>composed operation</em>. The
887 * program must ensure that the stream performs no other read operations (such
888 * as async_read, the stream's async_read_some function, or any other composed
889 * operations that perform reads) until this operation completes.
891 * @param s The stream from which the data is to be read. The type must support
892 * the AsyncReadStream concept.
894 * @param b A basic_streambuf object into which the data will be read. Ownership
895 * of the streambuf is retained by the caller, which must guarantee that it
896 * remains valid until the handler is called.
898 * @param completion_condition The function object to be called to determine
899 * whether the read operation is complete. The signature of the function object
901 * @code std::size_t completion_condition(
902 * // Result of latest async_read_some operation.
903 * const boost::system::error_code& error,
905 * // Number of bytes transferred so far.
906 * std::size_t bytes_transferred
908 * A return value of 0 indicates that the read operation is complete. A non-zero
909 * return value indicates the maximum number of bytes to be read on the next
910 * call to the stream's async_read_some function.
912 * @param handler The handler to be called when the read operation completes.
913 * Copies will be made of the handler as required. The function signature of the
915 * @code void handler(
916 * const boost::system::error_code& error, // Result of operation.
918 * std::size_t bytes_transferred // Number of bytes copied into the
919 * // buffers. If an error occurred,
920 * // this will be the number of
921 * // bytes successfully transferred
922 * // prior to the error.
924 * Regardless of whether the asynchronous operation completes immediately or
925 * not, the handler will not be invoked from within this function. Invocation of
926 * the handler will be performed in a manner equivalent to using
927 * boost::asio::io_context::post().
929 template <typename AsyncReadStream, typename Allocator,
930 typename CompletionCondition, typename ReadHandler>
931 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
932 void (boost::system::error_code, std::size_t))
933 async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
934 CompletionCondition completion_condition,
935 BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
937 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
938 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
945 #include <boost/asio/detail/pop_options.hpp>
947 #include <boost/asio/impl/read.hpp>
949 #endif // BOOST_ASIO_READ_HPP