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