Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // read.hpp
0003 // ~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_READ_HPP
0012 #define BOOST_ASIO_READ_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <cstddef>
0020 #include <boost/asio/async_result.hpp>
0021 #include <boost/asio/buffer.hpp>
0022 #include <boost/asio/completion_condition.hpp>
0023 #include <boost/asio/error.hpp>
0024 
0025 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0026 # include <boost/asio/basic_streambuf_fwd.hpp>
0027 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0028 
0029 #include <boost/asio/detail/push_options.hpp>
0030 
0031 namespace boost {
0032 namespace asio {
0033 namespace detail {
0034 
0035 template <typename> class initiate_async_read;
0036 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
0037 template <typename> class initiate_async_read_dynbuf_v1;
0038 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
0039 template <typename> class initiate_async_read_dynbuf_v2;
0040 
0041 } // namespace detail
0042 
0043 /**
0044  * @defgroup read boost::asio::read
0045  *
0046  * @brief The @c read function is a composed operation that reads a certain
0047  * amount of data from a stream before returning.
0048  */
0049 /*@{*/
0050 
0051 /// Attempt to read a certain amount of data from a stream before returning.
0052 /**
0053  * This function is used to read a certain number of bytes of data from a
0054  * stream. The call will block until one of the following conditions is true:
0055  *
0056  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0057  * the sum of the buffer sizes.
0058  *
0059  * @li An error occurred.
0060  *
0061  * This operation is implemented in terms of zero or more calls to the stream's
0062  * read_some function.
0063  *
0064  * @param s The stream from which the data is to be read. The type must support
0065  * the SyncReadStream concept.
0066  *
0067  * @param buffers One or more buffers into which the data will be read. The sum
0068  * of the buffer sizes indicates the maximum number of bytes to read from the
0069  * stream.
0070  *
0071  * @returns The number of bytes transferred.
0072  *
0073  * @throws boost::system::system_error Thrown on failure.
0074  *
0075  * @par Example
0076  * To read into a single data buffer use the @ref buffer function as follows:
0077  * @code boost::asio::read(s, boost::asio::buffer(data, size)); @endcode
0078  * See the @ref buffer documentation for information on reading into multiple
0079  * buffers in one go, and how to use it with arrays, boost::array or
0080  * std::vector.
0081  *
0082  * @note This overload is equivalent to calling:
0083  * @code boost::asio::read(
0084  *     s, buffers,
0085  *     boost::asio::transfer_all()); @endcode
0086  */
0087 template <typename SyncReadStream, typename MutableBufferSequence>
0088 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
0089     constraint_t<
0090       is_mutable_buffer_sequence<MutableBufferSequence>::value
0091     > = 0);
0092 
0093 /// Attempt to read a certain amount of data from a stream before returning.
0094 /**
0095  * This function is used to read a certain number of bytes of data from a
0096  * stream. The call will block until one of the following conditions is true:
0097  *
0098  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0099  * the sum of the buffer sizes.
0100  *
0101  * @li An error occurred.
0102  *
0103  * This operation is implemented in terms of zero or more calls to the stream's
0104  * read_some function.
0105  *
0106  * @param s The stream from which the data is to be read. The type must support
0107  * the SyncReadStream concept.
0108  *
0109  * @param buffers One or more buffers into which the data will be read. The sum
0110  * of the buffer sizes indicates the maximum number of bytes to read from the
0111  * stream.
0112  *
0113  * @param ec Set to indicate what error occurred, if any.
0114  *
0115  * @returns The number of bytes transferred.
0116  *
0117  * @par Example
0118  * To read into a single data buffer use the @ref buffer function as follows:
0119  * @code boost::asio::read(s, boost::asio::buffer(data, size), ec); @endcode
0120  * See the @ref buffer documentation for information on reading into multiple
0121  * buffers in one go, and how to use it with arrays, boost::array or
0122  * std::vector.
0123  *
0124  * @note This overload is equivalent to calling:
0125  * @code boost::asio::read(
0126  *     s, buffers,
0127  *     boost::asio::transfer_all(), ec); @endcode
0128  */
0129 template <typename SyncReadStream, typename MutableBufferSequence>
0130 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
0131     boost::system::error_code& ec,
0132     constraint_t<
0133       is_mutable_buffer_sequence<MutableBufferSequence>::value
0134     > = 0);
0135 
0136 /// Attempt to read a certain amount of data from a stream before returning.
0137 /**
0138  * This function is used to read a certain number of bytes of data from a
0139  * stream. The call will block until one of the following conditions is true:
0140  *
0141  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0142  * the sum of the buffer sizes.
0143  *
0144  * @li The completion_condition function object returns 0.
0145  *
0146  * This operation is implemented in terms of zero or more calls to the stream's
0147  * read_some function.
0148  *
0149  * @param s The stream from which the data is to be read. The type must support
0150  * the SyncReadStream concept.
0151  *
0152  * @param buffers One or more buffers into which the data will be read. The sum
0153  * of the buffer sizes indicates the maximum number of bytes to read from the
0154  * stream.
0155  *
0156  * @param completion_condition The function object to be called to determine
0157  * whether the read operation is complete. The signature of the function object
0158  * must be:
0159  * @code std::size_t completion_condition(
0160  *   // Result of latest read_some operation.
0161  *   const boost::system::error_code& error,
0162  *
0163  *   // Number of bytes transferred so far.
0164  *   std::size_t bytes_transferred
0165  * ); @endcode
0166  * A return value of 0 indicates that the read operation is complete. A non-zero
0167  * return value indicates the maximum number of bytes to be read on the next
0168  * call to the stream's read_some function.
0169  *
0170  * @returns The number of bytes transferred.
0171  *
0172  * @throws boost::system::system_error Thrown on failure.
0173  *
0174  * @par Example
0175  * To read into a single data buffer use the @ref buffer function as follows:
0176  * @code boost::asio::read(s, boost::asio::buffer(data, size),
0177  *     boost::asio::transfer_at_least(32)); @endcode
0178  * See the @ref buffer documentation for information on reading into multiple
0179  * buffers in one go, and how to use it with arrays, boost::array or
0180  * std::vector.
0181  */
0182 template <typename SyncReadStream, typename MutableBufferSequence,
0183   typename CompletionCondition>
0184 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
0185     CompletionCondition completion_condition,
0186     constraint_t<
0187       is_mutable_buffer_sequence<MutableBufferSequence>::value
0188     > = 0);
0189 
0190 /// Attempt to read a certain amount of data from a stream before returning.
0191 /**
0192  * This function is used to read a certain number of bytes of data from a
0193  * stream. The call will block until one of the following conditions is true:
0194  *
0195  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0196  * the sum of the buffer sizes.
0197  *
0198  * @li The completion_condition function object returns 0.
0199  *
0200  * This operation is implemented in terms of zero or more calls to the stream's
0201  * read_some function.
0202  *
0203  * @param s The stream from which the data is to be read. The type must support
0204  * the SyncReadStream concept.
0205  *
0206  * @param buffers One or more buffers into which the data will be read. The sum
0207  * of the buffer sizes indicates the maximum number of bytes to read from the
0208  * stream.
0209  *
0210  * @param completion_condition The function object to be called to determine
0211  * whether the read operation is complete. The signature of the function object
0212  * must be:
0213  * @code std::size_t completion_condition(
0214  *   // Result of latest read_some operation.
0215  *   const boost::system::error_code& error,
0216  *
0217  *   // Number of bytes transferred so far.
0218  *   std::size_t bytes_transferred
0219  * ); @endcode
0220  * A return value of 0 indicates that the read operation is complete. A non-zero
0221  * return value indicates the maximum number of bytes to be read on the next
0222  * call to the stream's read_some function.
0223  *
0224  * @param ec Set to indicate what error occurred, if any.
0225  *
0226  * @returns The number of bytes read. If an error occurs, returns the total
0227  * number of bytes successfully transferred prior to the error.
0228  */
0229 template <typename SyncReadStream, typename MutableBufferSequence,
0230     typename CompletionCondition>
0231 std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
0232     CompletionCondition completion_condition, boost::system::error_code& ec,
0233     constraint_t<
0234       is_mutable_buffer_sequence<MutableBufferSequence>::value
0235     > = 0);
0236 
0237 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
0238 
0239 /// Attempt to read a certain amount of data from a stream before returning.
0240 /**
0241  * This function is used to read a certain number of bytes of data from a
0242  * stream. The call will block until one of the following conditions is true:
0243  *
0244  * @li The specified dynamic buffer sequence is full (that is, it has reached
0245  * maximum size).
0246  *
0247  * @li An error occurred.
0248  *
0249  * This operation is implemented in terms of zero or more calls to the stream's
0250  * read_some function.
0251  *
0252  * @param s The stream from which the data is to be read. The type must support
0253  * the SyncReadStream concept.
0254  *
0255  * @param buffers The dynamic buffer sequence into which the data will be read.
0256  *
0257  * @returns The number of bytes transferred.
0258  *
0259  * @throws boost::system::system_error Thrown on failure.
0260  *
0261  * @note This overload is equivalent to calling:
0262  * @code boost::asio::read(
0263  *     s, buffers,
0264  *     boost::asio::transfer_all()); @endcode
0265  */
0266 template <typename SyncReadStream, typename DynamicBuffer_v1>
0267 std::size_t read(SyncReadStream& s,
0268     DynamicBuffer_v1&& buffers,
0269     constraint_t<
0270       is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
0271     > = 0,
0272     constraint_t<
0273       !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
0274     > = 0);
0275 
0276 /// Attempt to read a certain amount of data from a stream before returning.
0277 /**
0278  * This function is used to read a certain number of bytes of data from a
0279  * stream. The call will block until one of the following conditions is true:
0280  *
0281  * @li The supplied buffer is full (that is, it has reached maximum size).
0282  *
0283  * @li An error occurred.
0284  *
0285  * This operation is implemented in terms of zero or more calls to the stream's
0286  * read_some function.
0287  *
0288  * @param s The stream from which the data is to be read. The type must support
0289  * the SyncReadStream concept.
0290  *
0291  * @param buffers The dynamic buffer sequence into which the data will be read.
0292  *
0293  * @param ec Set to indicate what error occurred, if any.
0294  *
0295  * @returns The number of bytes transferred.
0296  *
0297  * @note This overload is equivalent to calling:
0298  * @code boost::asio::read(
0299  *     s, buffers,
0300  *     boost::asio::transfer_all(), ec); @endcode
0301  */
0302 template <typename SyncReadStream, typename DynamicBuffer_v1>
0303 std::size_t read(SyncReadStream& s,
0304     DynamicBuffer_v1&& buffers,
0305     boost::system::error_code& ec,
0306     constraint_t<
0307       is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
0308     > = 0,
0309     constraint_t<
0310       !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
0311     > = 0);
0312 
0313 /// Attempt to read a certain amount of data from a stream before returning.
0314 /**
0315  * This function is used to read a certain number of bytes of data from a
0316  * stream. The call will block until one of the following conditions is true:
0317  *
0318  * @li The specified dynamic buffer sequence is full (that is, it has reached
0319  * maximum size).
0320  *
0321  * @li The completion_condition function object returns 0.
0322  *
0323  * This operation is implemented in terms of zero or more calls to the stream's
0324  * read_some function.
0325  *
0326  * @param s The stream from which the data is to be read. The type must support
0327  * the SyncReadStream concept.
0328  *
0329  * @param buffers The dynamic buffer sequence into which the data will be read.
0330  *
0331  * @param completion_condition The function object to be called to determine
0332  * whether the read operation is complete. The signature of the function object
0333  * must be:
0334  * @code std::size_t completion_condition(
0335  *   // Result of latest read_some operation.
0336  *   const boost::system::error_code& error,
0337  *
0338  *   // Number of bytes transferred so far.
0339  *   std::size_t bytes_transferred
0340  * ); @endcode
0341  * A return value of 0 indicates that the read operation is complete. A non-zero
0342  * return value indicates the maximum number of bytes to be read on the next
0343  * call to the stream's read_some function.
0344  *
0345  * @returns The number of bytes transferred.
0346  *
0347  * @throws boost::system::system_error Thrown on failure.
0348  */
0349 template <typename SyncReadStream, typename DynamicBuffer_v1,
0350     typename CompletionCondition>
0351 std::size_t read(SyncReadStream& s,
0352     DynamicBuffer_v1&& buffers,
0353     CompletionCondition completion_condition,
0354     constraint_t<
0355       is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
0356     > = 0,
0357     constraint_t<
0358       !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
0359     > = 0);
0360 
0361 /// Attempt to read a certain amount of data from a stream before returning.
0362 /**
0363  * This function is used to read a certain number of bytes of data from a
0364  * stream. The call will block until one of the following conditions is true:
0365  *
0366  * @li The specified dynamic buffer sequence is full (that is, it has reached
0367  * maximum size).
0368  *
0369  * @li The completion_condition function object returns 0.
0370  *
0371  * This operation is implemented in terms of zero or more calls to the stream's
0372  * read_some function.
0373  *
0374  * @param s The stream from which the data is to be read. The type must support
0375  * the SyncReadStream concept.
0376  *
0377  * @param buffers The dynamic buffer sequence into which the data will be read.
0378  *
0379  * @param completion_condition The function object to be called to determine
0380  * whether the read operation is complete. The signature of the function object
0381  * must be:
0382  * @code std::size_t completion_condition(
0383  *   // Result of latest read_some operation.
0384  *   const boost::system::error_code& error,
0385  *
0386  *   // Number of bytes transferred so far.
0387  *   std::size_t bytes_transferred
0388  * ); @endcode
0389  * A return value of 0 indicates that the read operation is complete. A non-zero
0390  * return value indicates the maximum number of bytes to be read on the next
0391  * call to the stream's read_some function.
0392  *
0393  * @param ec Set to indicate what error occurred, if any.
0394  *
0395  * @returns The number of bytes read. If an error occurs, returns the total
0396  * number of bytes successfully transferred prior to the error.
0397  */
0398 template <typename SyncReadStream, typename DynamicBuffer_v1,
0399     typename CompletionCondition>
0400 std::size_t read(SyncReadStream& s,
0401     DynamicBuffer_v1&& buffers,
0402     CompletionCondition completion_condition, boost::system::error_code& ec,
0403     constraint_t<
0404       is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
0405     > = 0,
0406     constraint_t<
0407       !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
0408     > = 0);
0409 
0410 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0411 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0412 
0413 /// Attempt to read a certain amount of data from a stream before returning.
0414 /**
0415  * This function is used to read a certain number of bytes of data from a
0416  * stream. The call will block until one of the following conditions is true:
0417  *
0418  * @li The supplied buffer is full (that is, it has reached maximum size).
0419  *
0420  * @li An error occurred.
0421  *
0422  * This operation is implemented in terms of zero or more calls to the stream's
0423  * read_some function.
0424  *
0425  * @param s The stream from which the data is to be read. The type must support
0426  * the SyncReadStream concept.
0427  *
0428  * @param b The basic_streambuf object into which the data will be read.
0429  *
0430  * @returns The number of bytes transferred.
0431  *
0432  * @throws boost::system::system_error Thrown on failure.
0433  *
0434  * @note This overload is equivalent to calling:
0435  * @code boost::asio::read(
0436  *     s, b,
0437  *     boost::asio::transfer_all()); @endcode
0438  */
0439 template <typename SyncReadStream, typename Allocator>
0440 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
0441 
0442 /// Attempt to read a certain amount of data from a stream before returning.
0443 /**
0444  * This function is used to read a certain number of bytes of data from a
0445  * stream. The call will block until one of the following conditions is true:
0446  *
0447  * @li The supplied buffer is full (that is, it has reached maximum size).
0448  *
0449  * @li An error occurred.
0450  *
0451  * This operation is implemented in terms of zero or more calls to the stream's
0452  * read_some function.
0453  *
0454  * @param s The stream from which the data is to be read. The type must support
0455  * the SyncReadStream concept.
0456  *
0457  * @param b The basic_streambuf object into which the data will be read.
0458  *
0459  * @param ec Set to indicate what error occurred, if any.
0460  *
0461  * @returns The number of bytes transferred.
0462  *
0463  * @note This overload is equivalent to calling:
0464  * @code boost::asio::read(
0465  *     s, b,
0466  *     boost::asio::transfer_all(), ec); @endcode
0467  */
0468 template <typename SyncReadStream, typename Allocator>
0469 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
0470     boost::system::error_code& ec);
0471 
0472 /// Attempt to read a certain amount of data from a stream before returning.
0473 /**
0474  * This function is used to read a certain number of bytes of data from a
0475  * stream. The call will block until one of the following conditions is true:
0476  *
0477  * @li The supplied buffer is full (that is, it has reached maximum size).
0478  *
0479  * @li The completion_condition function object returns 0.
0480  *
0481  * This operation is implemented in terms of zero or more calls to the stream's
0482  * read_some function.
0483  *
0484  * @param s The stream from which the data is to be read. The type must support
0485  * the SyncReadStream concept.
0486  *
0487  * @param b The basic_streambuf object into which the data will be read.
0488  *
0489  * @param completion_condition The function object to be called to determine
0490  * whether the read operation is complete. The signature of the function object
0491  * must be:
0492  * @code std::size_t completion_condition(
0493  *   // Result of latest read_some operation.
0494  *   const boost::system::error_code& error,
0495  *
0496  *   // Number of bytes transferred so far.
0497  *   std::size_t bytes_transferred
0498  * ); @endcode
0499  * A return value of 0 indicates that the read operation is complete. A non-zero
0500  * return value indicates the maximum number of bytes to be read on the next
0501  * call to the stream's read_some function.
0502  *
0503  * @returns The number of bytes transferred.
0504  *
0505  * @throws boost::system::system_error Thrown on failure.
0506  */
0507 template <typename SyncReadStream, typename Allocator,
0508     typename CompletionCondition>
0509 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
0510     CompletionCondition completion_condition);
0511 
0512 /// Attempt to read a certain amount of data from a stream before returning.
0513 /**
0514  * This function is used to read a certain number of bytes of data from a
0515  * stream. The call will block until one of the following conditions is true:
0516  *
0517  * @li The supplied buffer is full (that is, it has reached maximum size).
0518  *
0519  * @li The completion_condition function object returns 0.
0520  *
0521  * This operation is implemented in terms of zero or more calls to the stream's
0522  * read_some function.
0523  *
0524  * @param s The stream from which the data is to be read. The type must support
0525  * the SyncReadStream concept.
0526  *
0527  * @param b The basic_streambuf object into which the data will be read.
0528  *
0529  * @param completion_condition The function object to be called to determine
0530  * whether the read operation is complete. The signature of the function object
0531  * must be:
0532  * @code std::size_t completion_condition(
0533  *   // Result of latest read_some operation.
0534  *   const boost::system::error_code& error,
0535  *
0536  *   // Number of bytes transferred so far.
0537  *   std::size_t bytes_transferred
0538  * ); @endcode
0539  * A return value of 0 indicates that the read operation is complete. A non-zero
0540  * return value indicates the maximum number of bytes to be read on the next
0541  * call to the stream's read_some function.
0542  *
0543  * @param ec Set to indicate what error occurred, if any.
0544  *
0545  * @returns The number of bytes read. If an error occurs, returns the total
0546  * number of bytes successfully transferred prior to the error.
0547  */
0548 template <typename SyncReadStream, typename Allocator,
0549     typename CompletionCondition>
0550 std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
0551     CompletionCondition completion_condition, boost::system::error_code& ec);
0552 
0553 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0554 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0555 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
0556 
0557 /// Attempt to read a certain amount of data from a stream before returning.
0558 /**
0559  * This function is used to read a certain number of bytes of data from a
0560  * stream. The call will block until one of the following conditions is true:
0561  *
0562  * @li The specified dynamic buffer sequence is full (that is, it has reached
0563  * maximum size).
0564  *
0565  * @li An error occurred.
0566  *
0567  * This operation is implemented in terms of zero or more calls to the stream's
0568  * read_some function.
0569  *
0570  * @param s The stream from which the data is to be read. The type must support
0571  * the SyncReadStream concept.
0572  *
0573  * @param buffers The dynamic buffer sequence into which the data will be read.
0574  *
0575  * @returns The number of bytes transferred.
0576  *
0577  * @throws boost::system::system_error Thrown on failure.
0578  *
0579  * @note This overload is equivalent to calling:
0580  * @code boost::asio::read(
0581  *     s, buffers,
0582  *     boost::asio::transfer_all()); @endcode
0583  */
0584 template <typename SyncReadStream, typename DynamicBuffer_v2>
0585 std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
0586     constraint_t<
0587       is_dynamic_buffer_v2<DynamicBuffer_v2>::value
0588     > = 0);
0589 
0590 /// Attempt to read a certain amount of data from a stream before returning.
0591 /**
0592  * This function is used to read a certain number of bytes of data from a
0593  * stream. The call will block until one of the following conditions is true:
0594  *
0595  * @li The supplied buffer is full (that is, it has reached maximum size).
0596  *
0597  * @li An error occurred.
0598  *
0599  * This operation is implemented in terms of zero or more calls to the stream's
0600  * read_some function.
0601  *
0602  * @param s The stream from which the data is to be read. The type must support
0603  * the SyncReadStream concept.
0604  *
0605  * @param buffers The dynamic buffer sequence into which the data will be read.
0606  *
0607  * @param ec Set to indicate what error occurred, if any.
0608  *
0609  * @returns The number of bytes transferred.
0610  *
0611  * @note This overload is equivalent to calling:
0612  * @code boost::asio::read(
0613  *     s, buffers,
0614  *     boost::asio::transfer_all(), ec); @endcode
0615  */
0616 template <typename SyncReadStream, typename DynamicBuffer_v2>
0617 std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
0618     boost::system::error_code& ec,
0619     constraint_t<
0620       is_dynamic_buffer_v2<DynamicBuffer_v2>::value
0621     > = 0);
0622 
0623 /// Attempt to read a certain amount of data from a stream before returning.
0624 /**
0625  * This function is used to read a certain number of bytes of data from a
0626  * stream. The call will block until one of the following conditions is true:
0627  *
0628  * @li The specified dynamic buffer sequence is full (that is, it has reached
0629  * maximum size).
0630  *
0631  * @li The completion_condition function object returns 0.
0632  *
0633  * This operation is implemented in terms of zero or more calls to the stream's
0634  * read_some function.
0635  *
0636  * @param s The stream from which the data is to be read. The type must support
0637  * the SyncReadStream concept.
0638  *
0639  * @param buffers The dynamic buffer sequence into which the data will be read.
0640  *
0641  * @param completion_condition The function object to be called to determine
0642  * whether the read operation is complete. The signature of the function object
0643  * must be:
0644  * @code std::size_t completion_condition(
0645  *   // Result of latest read_some operation.
0646  *   const boost::system::error_code& error,
0647  *
0648  *   // Number of bytes transferred so far.
0649  *   std::size_t bytes_transferred
0650  * ); @endcode
0651  * A return value of 0 indicates that the read operation is complete. A non-zero
0652  * return value indicates the maximum number of bytes to be read on the next
0653  * call to the stream's read_some function.
0654  *
0655  * @returns The number of bytes transferred.
0656  *
0657  * @throws boost::system::system_error Thrown on failure.
0658  */
0659 template <typename SyncReadStream, typename DynamicBuffer_v2,
0660     typename CompletionCondition>
0661 std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
0662     CompletionCondition completion_condition,
0663     constraint_t<
0664       is_dynamic_buffer_v2<DynamicBuffer_v2>::value
0665     > = 0);
0666 
0667 /// Attempt to read a certain amount of data from a stream before returning.
0668 /**
0669  * This function is used to read a certain number of bytes of data from a
0670  * stream. The call will block until one of the following conditions is true:
0671  *
0672  * @li The specified dynamic buffer sequence is full (that is, it has reached
0673  * maximum size).
0674  *
0675  * @li The completion_condition function object returns 0.
0676  *
0677  * This operation is implemented in terms of zero or more calls to the stream's
0678  * read_some function.
0679  *
0680  * @param s The stream from which the data is to be read. The type must support
0681  * the SyncReadStream concept.
0682  *
0683  * @param buffers The dynamic buffer sequence into which the data will be read.
0684  *
0685  * @param completion_condition The function object to be called to determine
0686  * whether the read operation is complete. The signature of the function object
0687  * must be:
0688  * @code std::size_t completion_condition(
0689  *   // Result of latest read_some operation.
0690  *   const boost::system::error_code& error,
0691  *
0692  *   // Number of bytes transferred so far.
0693  *   std::size_t bytes_transferred
0694  * ); @endcode
0695  * A return value of 0 indicates that the read operation is complete. A non-zero
0696  * return value indicates the maximum number of bytes to be read on the next
0697  * call to the stream's read_some function.
0698  *
0699  * @param ec Set to indicate what error occurred, if any.
0700  *
0701  * @returns The number of bytes read. If an error occurs, returns the total
0702  * number of bytes successfully transferred prior to the error.
0703  */
0704 template <typename SyncReadStream, typename DynamicBuffer_v2,
0705     typename CompletionCondition>
0706 std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
0707     CompletionCondition completion_condition, boost::system::error_code& ec,
0708     constraint_t<
0709       is_dynamic_buffer_v2<DynamicBuffer_v2>::value
0710     > = 0);
0711 
0712 /*@}*/
0713 /**
0714  * @defgroup async_read boost::asio::async_read
0715  *
0716  * @brief The @c async_read function is a composed asynchronous operation that
0717  * reads a certain amount of data from a stream before completion.
0718  */
0719 /*@{*/
0720 
0721 /// Start an asynchronous operation to read a certain amount of data from a
0722 /// stream.
0723 /**
0724  * This function is used to asynchronously read a certain number of bytes of
0725  * data from a stream. It is an initiating function for an @ref
0726  * asynchronous_operation, and always returns immediately. The asynchronous
0727  * operation will continue until one of the following conditions is true:
0728  *
0729  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0730  * the sum of the buffer sizes.
0731  *
0732  * @li An error occurred.
0733  *
0734  * This operation is implemented in terms of zero or more calls to the stream's
0735  * async_read_some function, and is known as a <em>composed operation</em>. The
0736  * program must ensure that the stream performs no other read operations (such
0737  * as async_read, the stream's async_read_some function, or any other composed
0738  * operations that perform reads) until this operation completes.
0739  *
0740  * @param s The stream from which the data is to be read. The type must support
0741  * the AsyncReadStream concept.
0742  *
0743  * @param buffers One or more buffers into which the data will be read. The sum
0744  * of the buffer sizes indicates the maximum number of bytes to read from the
0745  * stream. Although the buffers object may be copied as necessary, ownership of
0746  * the underlying memory blocks is retained by the caller, which must guarantee
0747  * that they remain valid until the completion handler is called.
0748  *
0749  * @param token The @ref completion_token that will be used to produce a
0750  * completion handler, which will be called when the read completes.
0751  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0752  * @ref yield_context, or a function object with the correct completion
0753  * signature. The function signature of the completion handler must be:
0754  * @code void handler(
0755  *   // Result of operation.
0756  *   const boost::system::error_code& error,
0757  *
0758  *   // Number of bytes copied into the buffers. If an error
0759  *   // occurred, this will be the number of bytes successfully
0760  *   // transferred prior to the error.
0761  *   std::size_t bytes_transferred
0762  * ); @endcode
0763  * Regardless of whether the asynchronous operation completes immediately or
0764  * not, the completion handler will not be invoked from within this function.
0765  * On immediate completion, invocation of the handler will be performed in a
0766  * manner equivalent to using boost::asio::post().
0767  *
0768  * @par Completion Signature
0769  * @code void(boost::system::error_code, std::size_t) @endcode
0770  *
0771  * @par Example
0772  * To read into a single data buffer use the @ref buffer function as follows:
0773  * @code
0774  * boost::asio::async_read(s, boost::asio::buffer(data, size), handler);
0775  * @endcode
0776  * See the @ref buffer documentation for information on reading into multiple
0777  * buffers in one go, and how to use it with arrays, boost::array or
0778  * std::vector.
0779  *
0780  * @note This overload is equivalent to calling:
0781  * @code boost::asio::async_read(
0782  *     s, buffers,
0783  *     boost::asio::transfer_all(),
0784  *     handler); @endcode
0785  *
0786  * @par Per-Operation Cancellation
0787  * This asynchronous operation supports cancellation for the following
0788  * boost::asio::cancellation_type values:
0789  *
0790  * @li @c cancellation_type::terminal
0791  *
0792  * @li @c cancellation_type::partial
0793  *
0794  * if they are also supported by the @c AsyncReadStream type's
0795  * @c async_read_some operation.
0796  */
0797 template <typename AsyncReadStream, typename MutableBufferSequence,
0798     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0799       std::size_t)) ReadToken = default_completion_token_t<
0800         typename AsyncReadStream::executor_type>>
0801 auto async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
0802     ReadToken&& token = default_completion_token_t<
0803       typename AsyncReadStream::executor_type>(),
0804     constraint_t<
0805       is_mutable_buffer_sequence<MutableBufferSequence>::value
0806     > = 0)
0807   -> decltype(
0808     async_initiate<ReadToken,
0809       void (boost::system::error_code, std::size_t)>(
0810         declval<detail::initiate_async_read<AsyncReadStream>>(),
0811         token, buffers, transfer_all()));
0812 
0813 /// Start an asynchronous operation to read a certain amount of data from a
0814 /// stream.
0815 /**
0816  * This function is used to asynchronously read a certain number of bytes of
0817  * data from a stream. It is an initiating function for an @ref
0818  * asynchronous_operation, and always returns immediately. The asynchronous
0819  * operation will continue until one of the following conditions is true:
0820  *
0821  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0822  * the sum of the buffer sizes.
0823  *
0824  * @li The completion_condition function object returns 0.
0825  *
0826  * @param s The stream from which the data is to be read. The type must support
0827  * the AsyncReadStream concept.
0828  *
0829  * @param buffers One or more buffers into which the data will be read. The sum
0830  * of the buffer sizes indicates the maximum number of bytes to read from the
0831  * stream. Although the buffers object may be copied as necessary, ownership of
0832  * the underlying memory blocks is retained by the caller, which must guarantee
0833  * that they remain valid until the completion handler is called.
0834  *
0835  * @param completion_condition The function object to be called to determine
0836  * whether the read operation is complete. The signature of the function object
0837  * must be:
0838  * @code std::size_t completion_condition(
0839  *   // Result of latest async_read_some operation.
0840  *   const boost::system::error_code& error,
0841  *
0842  *   // Number of bytes transferred so far.
0843  *   std::size_t bytes_transferred
0844  * ); @endcode
0845  * A return value of 0 indicates that the read operation is complete. A non-zero
0846  * return value indicates the maximum number of bytes to be read on the next
0847  * call to the stream's async_read_some function.
0848  *
0849  * @param token The @ref completion_token that will be used to produce a
0850  * completion handler, which will be called when the read completes.
0851  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0852  * @ref yield_context, or a function object with the correct completion
0853  * signature. The function signature of the completion handler must be:
0854  * @code void handler(
0855  *   // Result of operation.
0856  *   const boost::system::error_code& error,
0857  *
0858  *   // Number of bytes copied into the buffers. If an error
0859  *   // occurred, this will be the number of bytes successfully
0860  *   // transferred prior to the error.
0861  *   std::size_t bytes_transferred
0862  * ); @endcode
0863  * Regardless of whether the asynchronous operation completes immediately or
0864  * not, the completion handler will not be invoked from within this function.
0865  * On immediate completion, invocation of the handler will be performed in a
0866  * manner equivalent to using boost::asio::post().
0867  *
0868  * @par Completion Signature
0869  * @code void(boost::system::error_code, std::size_t) @endcode
0870  *
0871  * @par Example
0872  * To read into a single data buffer use the @ref buffer function as follows:
0873  * @code boost::asio::async_read(s,
0874  *     boost::asio::buffer(data, size),
0875  *     boost::asio::transfer_at_least(32),
0876  *     handler); @endcode
0877  * See the @ref buffer documentation for information on reading into multiple
0878  * buffers in one go, and how to use it with arrays, boost::array or
0879  * std::vector.
0880  *
0881  * @par Per-Operation Cancellation
0882  * This asynchronous operation supports cancellation for the following
0883  * boost::asio::cancellation_type values:
0884  *
0885  * @li @c cancellation_type::terminal
0886  *
0887  * @li @c cancellation_type::partial
0888  *
0889  * if they are also supported by the @c AsyncReadStream type's
0890  * @c async_read_some operation.
0891  */
0892 template <typename AsyncReadStream,
0893     typename MutableBufferSequence, typename CompletionCondition,
0894     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0895       std::size_t)) ReadToken = default_completion_token_t<
0896         typename AsyncReadStream::executor_type>>
0897 auto async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
0898     CompletionCondition completion_condition,
0899     ReadToken&& token = default_completion_token_t<
0900       typename AsyncReadStream::executor_type>(),
0901     constraint_t<
0902       is_mutable_buffer_sequence<MutableBufferSequence>::value
0903     > = 0)
0904   -> decltype(
0905     async_initiate<ReadToken,
0906       void (boost::system::error_code, std::size_t)>(
0907         declval<detail::initiate_async_read<AsyncReadStream>>(),
0908         token, buffers,
0909         static_cast<CompletionCondition&&>(completion_condition)));
0910 
0911 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
0912 
0913 /// Start an asynchronous operation to read a certain amount of data from a
0914 /// stream.
0915 /**
0916  * This function is used to asynchronously read a certain number of bytes of
0917  * data from a stream. It is an initiating function for an @ref
0918  * asynchronous_operation, and always returns immediately. The asynchronous
0919  * operation will continue until one of the following conditions is true:
0920  *
0921  * @li The specified dynamic buffer sequence is full (that is, it has reached
0922  * maximum size).
0923  *
0924  * @li An error occurred.
0925  *
0926  * This operation is implemented in terms of zero or more calls to the stream's
0927  * async_read_some function, and is known as a <em>composed operation</em>. The
0928  * program must ensure that the stream performs no other read operations (such
0929  * as async_read, the stream's async_read_some function, or any other composed
0930  * operations that perform reads) until this operation completes.
0931  *
0932  * @param s The stream from which the data is to be read. The type must support
0933  * the AsyncReadStream concept.
0934  *
0935  * @param buffers The dynamic buffer sequence into which the data will be read.
0936  * Although the buffers object may be copied as necessary, ownership of the
0937  * underlying memory blocks is retained by the caller, which must guarantee
0938  * that they remain valid until the completion handler is called.
0939  *
0940  * @param token The @ref completion_token that will be used to produce a
0941  * completion handler, which will be called when the read completes.
0942  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0943  * @ref yield_context, or a function object with the correct completion
0944  * signature. The function signature of the completion handler must be:
0945  * @code void handler(
0946  *   // Result of operation.
0947  *   const boost::system::error_code& error,
0948  *
0949  *   // Number of bytes copied into the buffers. If an error
0950  *   // occurred, this will be the number of bytes successfully
0951  *   // transferred prior to the error.
0952  *   std::size_t bytes_transferred
0953  * ); @endcode
0954  * Regardless of whether the asynchronous operation completes immediately or
0955  * not, the completion handler will not be invoked from within this function.
0956  * On immediate completion, invocation of the handler will be performed in a
0957  * manner equivalent to using boost::asio::post().
0958  *
0959  * @par Completion Signature
0960  * @code void(boost::system::error_code, std::size_t) @endcode
0961  *
0962  * @note This overload is equivalent to calling:
0963  * @code boost::asio::async_read(
0964  *     s, buffers,
0965  *     boost::asio::transfer_all(),
0966  *     handler); @endcode
0967  *
0968  * @par Per-Operation Cancellation
0969  * This asynchronous operation supports cancellation for the following
0970  * boost::asio::cancellation_type values:
0971  *
0972  * @li @c cancellation_type::terminal
0973  *
0974  * @li @c cancellation_type::partial
0975  *
0976  * if they are also supported by the @c AsyncReadStream type's
0977  * @c async_read_some operation.
0978  */
0979 template <typename AsyncReadStream, typename DynamicBuffer_v1,
0980     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0981       std::size_t)) ReadToken = default_completion_token_t<
0982         typename AsyncReadStream::executor_type>>
0983 auto async_read(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
0984     ReadToken&& token = default_completion_token_t<
0985       typename AsyncReadStream::executor_type>(),
0986     constraint_t<
0987       is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
0988     > = 0,
0989     constraint_t<
0990       !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
0991     > = 0)
0992   -> decltype(
0993     async_initiate<ReadToken,
0994       void (boost::system::error_code, std::size_t)>(
0995         declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
0996         token, static_cast<DynamicBuffer_v1&&>(buffers), transfer_all()));
0997 
0998 /// Start an asynchronous operation to read a certain amount of data from a
0999 /// stream.
1000 /**
1001  * This function is used to asynchronously read a certain number of bytes of
1002  * data from a stream. It is an initiating function for an @ref
1003  * asynchronous_operation, and always returns immediately. The asynchronous
1004  * operation will continue until one of the following conditions is true:
1005  *
1006  * @li The specified dynamic buffer sequence is full (that is, it has reached
1007  * maximum size).
1008  *
1009  * @li The completion_condition function object returns 0.
1010  *
1011  * This operation is implemented in terms of zero or more calls to the stream's
1012  * async_read_some function, and is known as a <em>composed operation</em>. The
1013  * program must ensure that the stream performs no other read operations (such
1014  * as async_read, the stream's async_read_some function, or any other composed
1015  * operations that perform reads) until this operation completes.
1016  *
1017  * @param s The stream from which the data is to be read. The type must support
1018  * the AsyncReadStream concept.
1019  *
1020  * @param buffers The dynamic buffer sequence into which the data will be read.
1021  * Although the buffers object may be copied as necessary, ownership of the
1022  * underlying memory blocks is retained by the caller, which must guarantee
1023  * that they remain valid until the completion handler is called.
1024  *
1025  * @param completion_condition The function object to be called to determine
1026  * whether the read operation is complete. The signature of the function object
1027  * must be:
1028  * @code std::size_t completion_condition(
1029  *   // Result of latest async_read_some operation.
1030  *   const boost::system::error_code& error,
1031  *
1032  *   // Number of bytes transferred so far.
1033  *   std::size_t bytes_transferred
1034  * ); @endcode
1035  * A return value of 0 indicates that the read operation is complete. A non-zero
1036  * return value indicates the maximum number of bytes to be read on the next
1037  * call to the stream's async_read_some function.
1038  *
1039  * @param token The @ref completion_token that will be used to produce a
1040  * completion handler, which will be called when the read completes.
1041  * Potential completion tokens include @ref use_future, @ref use_awaitable,
1042  * @ref yield_context, or a function object with the correct completion
1043  * signature. The function signature of the completion handler must be:
1044  * @code void handler(
1045  *   // Result of operation.
1046  *   const boost::system::error_code& error,
1047  *
1048  *   // Number of bytes copied into the buffers. If an error
1049  *   // occurred, this will be the number of bytes successfully
1050  *   // transferred prior to the error.
1051  *   std::size_t bytes_transferred
1052  * ); @endcode
1053  * Regardless of whether the asynchronous operation completes immediately or
1054  * not, the completion handler will not be invoked from within this function.
1055  * On immediate completion, invocation of the handler will be performed in a
1056  * manner equivalent to using boost::asio::post().
1057  *
1058  * @par Completion Signature
1059  * @code void(boost::system::error_code, std::size_t) @endcode
1060  *
1061  * @par Per-Operation Cancellation
1062  * This asynchronous operation supports cancellation for the following
1063  * boost::asio::cancellation_type values:
1064  *
1065  * @li @c cancellation_type::terminal
1066  *
1067  * @li @c cancellation_type::partial
1068  *
1069  * if they are also supported by the @c AsyncReadStream type's
1070  * @c async_read_some operation.
1071  */
1072 template <typename AsyncReadStream,
1073     typename DynamicBuffer_v1, typename CompletionCondition,
1074     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1075       std::size_t)) ReadToken = default_completion_token_t<
1076         typename AsyncReadStream::executor_type>>
1077 auto async_read(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
1078     CompletionCondition completion_condition,
1079     ReadToken&& token = default_completion_token_t<
1080       typename AsyncReadStream::executor_type>(),
1081     constraint_t<
1082       is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
1083     > = 0,
1084     constraint_t<
1085       !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
1086     > = 0)
1087   -> decltype(
1088     async_initiate<ReadToken,
1089       void (boost::system::error_code, std::size_t)>(
1090         declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
1091         token, static_cast<DynamicBuffer_v1&&>(buffers),
1092         static_cast<CompletionCondition&&>(completion_condition)));
1093 
1094 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
1095 #if !defined(BOOST_ASIO_NO_IOSTREAM)
1096 
1097 /// Start an asynchronous operation to read a certain amount of data from a
1098 /// stream.
1099 /**
1100  * This function is used to asynchronously read a certain number of bytes of
1101  * data from a stream. It is an initiating function for an @ref
1102  * asynchronous_operation, and always returns immediately. The asynchronous
1103  * operation will continue until one of the following conditions is true:
1104  *
1105  * @li The supplied buffer is full (that is, it has reached maximum size).
1106  *
1107  * @li An error occurred.
1108  *
1109  * This operation is implemented in terms of zero or more calls to the stream's
1110  * async_read_some function, and is known as a <em>composed operation</em>. The
1111  * program must ensure that the stream performs no other read operations (such
1112  * as async_read, the stream's async_read_some function, or any other composed
1113  * operations that perform reads) until this operation completes.
1114  *
1115  * @param s The stream from which the data is to be read. The type must support
1116  * the AsyncReadStream concept.
1117  *
1118  * @param b A basic_streambuf object into which the data will be read. Ownership
1119  * of the streambuf is retained by the caller, which must guarantee that it
1120  * remains valid until the completion handler is called.
1121  *
1122  * @param token The @ref completion_token that will be used to produce a
1123  * completion handler, which will be called when the read completes.
1124  * Potential completion tokens include @ref use_future, @ref use_awaitable,
1125  * @ref yield_context, or a function object with the correct completion
1126  * signature. The function signature of the completion handler must be:
1127  * @code void handler(
1128  *   // Result of operation.
1129  *   const boost::system::error_code& error,
1130  *
1131  *   // Number of bytes copied into the buffers. If an error
1132  *   // occurred, this will be the number of bytes successfully
1133  *   // transferred prior to the error.
1134  *   std::size_t bytes_transferred
1135  * ); @endcode
1136  * Regardless of whether the asynchronous operation completes immediately or
1137  * not, the completion handler will not be invoked from within this function.
1138  * On immediate completion, invocation of the handler will be performed in a
1139  * manner equivalent to using boost::asio::post().
1140  *
1141  * @par Completion Signature
1142  * @code void(boost::system::error_code, std::size_t) @endcode
1143  *
1144  * @note This overload is equivalent to calling:
1145  * @code boost::asio::async_read(
1146  *     s, b,
1147  *     boost::asio::transfer_all(),
1148  *     handler); @endcode
1149  *
1150  * @par Per-Operation Cancellation
1151  * This asynchronous operation supports cancellation for the following
1152  * boost::asio::cancellation_type values:
1153  *
1154  * @li @c cancellation_type::terminal
1155  *
1156  * @li @c cancellation_type::partial
1157  *
1158  * if they are also supported by the @c AsyncReadStream type's
1159  * @c async_read_some operation.
1160  */
1161 template <typename AsyncReadStream, typename Allocator,
1162     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1163       std::size_t)) ReadToken = default_completion_token_t<
1164         typename AsyncReadStream::executor_type>>
1165 auto async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
1166     ReadToken&& token = default_completion_token_t<
1167       typename AsyncReadStream::executor_type>())
1168   -> decltype(
1169     async_initiate<ReadToken,
1170       void (boost::system::error_code, std::size_t)>(
1171         declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
1172         token, basic_streambuf_ref<Allocator>(b), transfer_all()));
1173 
1174 /// Start an asynchronous operation to read a certain amount of data from a
1175 /// stream.
1176 /**
1177  * This function is used to asynchronously read a certain number of bytes of
1178  * data from a stream. It is an initiating function for an @ref
1179  * asynchronous_operation, and always returns immediately. The asynchronous
1180  * operation will continue until one of the following conditions is true:
1181  *
1182  * @li The supplied buffer is full (that is, it has reached maximum size).
1183  *
1184  * @li The completion_condition function object returns 0.
1185  *
1186  * This operation is implemented in terms of zero or more calls to the stream's
1187  * async_read_some function, and is known as a <em>composed operation</em>. The
1188  * program must ensure that the stream performs no other read operations (such
1189  * as async_read, the stream's async_read_some function, or any other composed
1190  * operations that perform reads) until this operation completes.
1191  *
1192  * @param s The stream from which the data is to be read. The type must support
1193  * the AsyncReadStream concept.
1194  *
1195  * @param b A basic_streambuf object into which the data will be read. Ownership
1196  * of the streambuf is retained by the caller, which must guarantee that it
1197  * remains valid until the completion handler is called.
1198  *
1199  * @param completion_condition The function object to be called to determine
1200  * whether the read operation is complete. The signature of the function object
1201  * must be:
1202  * @code std::size_t completion_condition(
1203  *   // Result of latest async_read_some operation.
1204  *   const boost::system::error_code& error,
1205  *
1206  *   // Number of bytes transferred so far.
1207  *   std::size_t bytes_transferred
1208  * ); @endcode
1209  * A return value of 0 indicates that the read operation is complete. A non-zero
1210  * return value indicates the maximum number of bytes to be read on the next
1211  * call to the stream's async_read_some function.
1212  *
1213  * @param token The @ref completion_token that will be used to produce a
1214  * completion handler, which will be called when the read completes.
1215  * Potential completion tokens include @ref use_future, @ref use_awaitable,
1216  * @ref yield_context, or a function object with the correct completion
1217  * signature. The function signature of the completion handler must be:
1218  * @code void handler(
1219  *   // Result of operation.
1220  *   const boost::system::error_code& error,
1221  *
1222  *   // Number of bytes copied into the buffers. If an error
1223  *   // occurred, this will be the number of bytes successfully
1224  *   // transferred prior to the error.
1225  *   std::size_t bytes_transferred
1226  * ); @endcode
1227  * Regardless of whether the asynchronous operation completes immediately or
1228  * not, the completion handler will not be invoked from within this function.
1229  * On immediate completion, invocation of the handler will be performed in a
1230  * manner equivalent to using boost::asio::post().
1231  *
1232  * @par Completion Signature
1233  * @code void(boost::system::error_code, std::size_t) @endcode
1234  *
1235  * @par Per-Operation Cancellation
1236  * This asynchronous operation supports cancellation for the following
1237  * boost::asio::cancellation_type values:
1238  *
1239  * @li @c cancellation_type::terminal
1240  *
1241  * @li @c cancellation_type::partial
1242  *
1243  * if they are also supported by the @c AsyncReadStream type's
1244  * @c async_read_some operation.
1245  */
1246 template <typename AsyncReadStream,
1247     typename Allocator, typename CompletionCondition,
1248     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1249       std::size_t)) ReadToken = default_completion_token_t<
1250         typename AsyncReadStream::executor_type>>
1251 auto async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
1252     CompletionCondition completion_condition,
1253     ReadToken&& token = default_completion_token_t<
1254       typename AsyncReadStream::executor_type>())
1255   -> decltype(
1256     async_initiate<ReadToken,
1257       void (boost::system::error_code, std::size_t)>(
1258         declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
1259         token, basic_streambuf_ref<Allocator>(b),
1260         static_cast<CompletionCondition&&>(completion_condition)));
1261 
1262 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
1263 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
1264 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
1265 
1266 /// Start an asynchronous operation to read a certain amount of data from a
1267 /// stream.
1268 /**
1269  * This function is used to asynchronously read a certain number of bytes of
1270  * data from a stream. It is an initiating function for an @ref
1271  * asynchronous_operation, and always returns immediately. The asynchronous
1272  * operation will continue until one of the following conditions is true:
1273  *
1274  * @li The specified dynamic buffer sequence is full (that is, it has reached
1275  * maximum size).
1276  *
1277  * @li An error occurred.
1278  *
1279  * This operation is implemented in terms of zero or more calls to the stream's
1280  * async_read_some function, and is known as a <em>composed operation</em>. The
1281  * program must ensure that the stream performs no other read operations (such
1282  * as async_read, the stream's async_read_some function, or any other composed
1283  * operations that perform reads) until this operation completes.
1284  *
1285  * @param s The stream from which the data is to be read. The type must support
1286  * the AsyncReadStream concept.
1287  *
1288  * @param buffers The dynamic buffer sequence into which the data will be read.
1289  * Although the buffers object may be copied as necessary, ownership of the
1290  * underlying memory blocks is retained by the caller, which must guarantee
1291  * that they remain valid until the completion handler is called.
1292  *
1293  * @param token The @ref completion_token that will be used to produce a
1294  * completion handler, which will be called when the read completes.
1295  * Potential completion tokens include @ref use_future, @ref use_awaitable,
1296  * @ref yield_context, or a function object with the correct completion
1297  * signature. The function signature of the completion handler must be:
1298  * @code void handler(
1299  *   // Result of operation.
1300  *   const boost::system::error_code& error,
1301  *
1302  *   // Number of bytes copied into the buffers. If an error
1303  *   // occurred, this will be the number of bytes successfully
1304  *   // transferred prior to the error.
1305  *   std::size_t bytes_transferred
1306  * ); @endcode
1307  * Regardless of whether the asynchronous operation completes immediately or
1308  * not, the completion handler will not be invoked from within this function.
1309  * On immediate completion, invocation of the handler will be performed in a
1310  * manner equivalent to using boost::asio::post().
1311  *
1312  * @par Completion Signature
1313  * @code void(boost::system::error_code, std::size_t) @endcode
1314  *
1315  * @note This overload is equivalent to calling:
1316  * @code boost::asio::async_read(
1317  *     s, buffers,
1318  *     boost::asio::transfer_all(),
1319  *     handler); @endcode
1320  *
1321  * @par Per-Operation Cancellation
1322  * This asynchronous operation supports cancellation for the following
1323  * boost::asio::cancellation_type values:
1324  *
1325  * @li @c cancellation_type::terminal
1326  *
1327  * @li @c cancellation_type::partial
1328  *
1329  * if they are also supported by the @c AsyncReadStream type's
1330  * @c async_read_some operation.
1331  */
1332 template <typename AsyncReadStream, typename DynamicBuffer_v2,
1333     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1334       std::size_t)) ReadToken = default_completion_token_t<
1335         typename AsyncReadStream::executor_type>>
1336 auto async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
1337     ReadToken&& token = default_completion_token_t<
1338       typename AsyncReadStream::executor_type>(),
1339     constraint_t<
1340       is_dynamic_buffer_v2<DynamicBuffer_v2>::value
1341     > = 0)
1342   -> decltype(
1343     async_initiate<ReadToken,
1344       void (boost::system::error_code, std::size_t)>(
1345         declval<detail::initiate_async_read_dynbuf_v2<AsyncReadStream>>(),
1346         token, static_cast<DynamicBuffer_v2&&>(buffers), transfer_all()));
1347 
1348 /// Start an asynchronous operation to read a certain amount of data from a
1349 /// stream.
1350 /**
1351  * This function is used to asynchronously read a certain number of bytes of
1352  * data from a stream. It is an initiating function for an @ref
1353  * asynchronous_operation, and always returns immediately. The asynchronous
1354  * operation will continue until one of the following conditions is true:
1355  *
1356  * @li The specified dynamic buffer sequence is full (that is, it has reached
1357  * maximum size).
1358  *
1359  * @li The completion_condition function object returns 0.
1360  *
1361  * This operation is implemented in terms of zero or more calls to the stream's
1362  * async_read_some function, and is known as a <em>composed operation</em>. The
1363  * program must ensure that the stream performs no other read operations (such
1364  * as async_read, the stream's async_read_some function, or any other composed
1365  * operations that perform reads) until this operation completes.
1366  *
1367  * @param s The stream from which the data is to be read. The type must support
1368  * the AsyncReadStream concept.
1369  *
1370  * @param buffers The dynamic buffer sequence into which the data will be read.
1371  * Although the buffers object may be copied as necessary, ownership of the
1372  * underlying memory blocks is retained by the caller, which must guarantee
1373  * that they remain valid until the completion handler is called.
1374  *
1375  * @param completion_condition The function object to be called to determine
1376  * whether the read operation is complete. The signature of the function object
1377  * must be:
1378  * @code std::size_t completion_condition(
1379  *   // Result of latest async_read_some operation.
1380  *   const boost::system::error_code& error,
1381  *
1382  *   // Number of bytes transferred so far.
1383  *   std::size_t bytes_transferred
1384  * ); @endcode
1385  * A return value of 0 indicates that the read operation is complete. A non-zero
1386  * return value indicates the maximum number of bytes to be read on the next
1387  * call to the stream's async_read_some function.
1388  *
1389  * @param token The @ref completion_token that will be used to produce a
1390  * completion handler, which will be called when the read completes.
1391  * Potential completion tokens include @ref use_future, @ref use_awaitable,
1392  * @ref yield_context, or a function object with the correct completion
1393  * signature. The function signature of the completion handler must be:
1394  * @code void handler(
1395  *   // Result of operation.
1396  *   const boost::system::error_code& error,
1397  *
1398  *   // Number of bytes copied into the buffers. If an error
1399  *   // occurred, this will be the number of bytes successfully
1400  *   // transferred prior to the error.
1401  *   std::size_t bytes_transferred
1402  * ); @endcode
1403  * Regardless of whether the asynchronous operation completes immediately or
1404  * not, the completion handler will not be invoked from within this function.
1405  * On immediate completion, invocation of the handler will be performed in a
1406  * manner equivalent to using boost::asio::post().
1407  *
1408  * @par Completion Signature
1409  * @code void(boost::system::error_code, std::size_t) @endcode
1410  *
1411  * @par Per-Operation Cancellation
1412  * This asynchronous operation supports cancellation for the following
1413  * boost::asio::cancellation_type values:
1414  *
1415  * @li @c cancellation_type::terminal
1416  *
1417  * @li @c cancellation_type::partial
1418  *
1419  * if they are also supported by the @c AsyncReadStream type's
1420  * @c async_read_some operation.
1421  */
1422 template <typename AsyncReadStream,
1423     typename DynamicBuffer_v2, typename CompletionCondition,
1424     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1425       std::size_t)) ReadToken = default_completion_token_t<
1426         typename AsyncReadStream::executor_type>>
1427 auto async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
1428     CompletionCondition completion_condition,
1429     ReadToken&& token = default_completion_token_t<
1430       typename AsyncReadStream::executor_type>(),
1431     constraint_t<
1432       is_dynamic_buffer_v2<DynamicBuffer_v2>::value
1433     > = 0)
1434   -> decltype(
1435     async_initiate<ReadToken,
1436       void (boost::system::error_code, std::size_t)>(
1437         declval<detail::initiate_async_read_dynbuf_v2<AsyncReadStream>>(),
1438         token, static_cast<DynamicBuffer_v2&&>(buffers),
1439         static_cast<CompletionCondition&&>(completion_condition)));
1440 
1441 /*@}*/
1442 
1443 } // namespace asio
1444 } // namespace boost
1445 
1446 #include <boost/asio/detail/pop_options.hpp>
1447 
1448 #include <boost/asio/impl/read.hpp>
1449 
1450 #endif // BOOST_ASIO_READ_HPP