read.hpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. //
  2. // read.hpp
  3. // ~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_READ_HPP
  11. #define BOOST_ASIO_READ_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <cstddef>
  17. #include <boost/asio/async_result.hpp>
  18. #include <boost/asio/buffer.hpp>
  19. #include <boost/asio/completion_condition.hpp>
  20. #include <boost/asio/error.hpp>
  21. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  22. # include <boost/asio/basic_streambuf_fwd.hpp>
  23. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  24. #include <boost/asio/detail/push_options.hpp>
  25. namespace boost {
  26. namespace asio {
  27. namespace detail {
  28. template <typename> class initiate_async_read;
  29. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  30. template <typename> class initiate_async_read_dynbuf_v1;
  31. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  32. template <typename> class initiate_async_read_dynbuf_v2;
  33. } // namespace detail
  34. /**
  35. * @defgroup read boost::asio::read
  36. *
  37. * @brief The @c read function is a composed operation that reads a certain
  38. * amount of data from a stream before returning.
  39. */
  40. /*@{*/
  41. /// Attempt to read a certain amount of data from a stream before returning.
  42. /**
  43. * This function is used to read a certain number of bytes of data from a
  44. * stream. The call will block until one of the following conditions is true:
  45. *
  46. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  47. * the sum of the buffer sizes.
  48. *
  49. * @li An error occurred.
  50. *
  51. * This operation is implemented in terms of zero or more calls to the stream's
  52. * read_some function.
  53. *
  54. * @param s The stream from which the data is to be read. The type must support
  55. * the SyncReadStream concept.
  56. *
  57. * @param buffers One or more buffers into which the data will be read. The sum
  58. * of the buffer sizes indicates the maximum number of bytes to read from the
  59. * stream.
  60. *
  61. * @returns The number of bytes transferred.
  62. *
  63. * @throws boost::system::system_error Thrown on failure.
  64. *
  65. * @par Example
  66. * To read into a single data buffer use the @ref buffer function as follows:
  67. * @code boost::asio::read(s, boost::asio::buffer(data, size)); @endcode
  68. * See the @ref buffer documentation for information on reading into multiple
  69. * buffers in one go, and how to use it with arrays, boost::array or
  70. * std::vector.
  71. *
  72. * @note This overload is equivalent to calling:
  73. * @code boost::asio::read(
  74. * s, buffers,
  75. * boost::asio::transfer_all()); @endcode
  76. */
  77. template <typename SyncReadStream, typename MutableBufferSequence>
  78. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  79. typename constraint<
  80. is_mutable_buffer_sequence<MutableBufferSequence>::value
  81. >::type = 0);
  82. /// Attempt to read a certain amount of data from a stream before returning.
  83. /**
  84. * This function is used to read a certain number of bytes of data from a
  85. * stream. The call will block until one of the following conditions is true:
  86. *
  87. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  88. * the sum of the buffer sizes.
  89. *
  90. * @li An error occurred.
  91. *
  92. * This operation is implemented in terms of zero or more calls to the stream's
  93. * read_some function.
  94. *
  95. * @param s The stream from which the data is to be read. The type must support
  96. * the SyncReadStream concept.
  97. *
  98. * @param buffers One or more buffers into which the data will be read. The sum
  99. * of the buffer sizes indicates the maximum number of bytes to read from the
  100. * stream.
  101. *
  102. * @param ec Set to indicate what error occurred, if any.
  103. *
  104. * @returns The number of bytes transferred.
  105. *
  106. * @par Example
  107. * To read into a single data buffer use the @ref buffer function as follows:
  108. * @code boost::asio::read(s, boost::asio::buffer(data, size), ec); @endcode
  109. * See the @ref buffer documentation for information on reading into multiple
  110. * buffers in one go, and how to use it with arrays, boost::array or
  111. * std::vector.
  112. *
  113. * @note This overload is equivalent to calling:
  114. * @code boost::asio::read(
  115. * s, buffers,
  116. * boost::asio::transfer_all(), ec); @endcode
  117. */
  118. template <typename SyncReadStream, typename MutableBufferSequence>
  119. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  120. boost::system::error_code& ec,
  121. typename constraint<
  122. is_mutable_buffer_sequence<MutableBufferSequence>::value
  123. >::type = 0);
  124. /// Attempt to read a certain amount of data from a stream before returning.
  125. /**
  126. * This function is used to read a certain number of bytes of data from a
  127. * stream. The call will block until one of the following conditions is true:
  128. *
  129. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  130. * the sum of the buffer sizes.
  131. *
  132. * @li The completion_condition function object returns 0.
  133. *
  134. * This operation is implemented in terms of zero or more calls to the stream's
  135. * read_some function.
  136. *
  137. * @param s The stream from which the data is to be read. The type must support
  138. * the SyncReadStream concept.
  139. *
  140. * @param buffers One or more buffers into which the data will be read. The sum
  141. * of the buffer sizes indicates the maximum number of bytes to read from the
  142. * stream.
  143. *
  144. * @param completion_condition The function object to be called to determine
  145. * whether the read operation is complete. The signature of the function object
  146. * must be:
  147. * @code std::size_t completion_condition(
  148. * // Result of latest read_some operation.
  149. * const boost::system::error_code& error,
  150. *
  151. * // Number of bytes transferred so far.
  152. * std::size_t bytes_transferred
  153. * ); @endcode
  154. * A return value of 0 indicates that the read operation is complete. A non-zero
  155. * return value indicates the maximum number of bytes to be read on the next
  156. * call to the stream's read_some function.
  157. *
  158. * @returns The number of bytes transferred.
  159. *
  160. * @throws boost::system::system_error Thrown on failure.
  161. *
  162. * @par Example
  163. * To read into a single data buffer use the @ref buffer function as follows:
  164. * @code boost::asio::read(s, boost::asio::buffer(data, size),
  165. * boost::asio::transfer_at_least(32)); @endcode
  166. * See the @ref buffer documentation for information on reading into multiple
  167. * buffers in one go, and how to use it with arrays, boost::array or
  168. * std::vector.
  169. */
  170. template <typename SyncReadStream, typename MutableBufferSequence,
  171. typename CompletionCondition>
  172. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  173. CompletionCondition completion_condition,
  174. typename constraint<
  175. is_mutable_buffer_sequence<MutableBufferSequence>::value
  176. >::type = 0);
  177. /// Attempt to read a certain amount of data from a stream before returning.
  178. /**
  179. * This function is used to read a certain number of bytes of data from a
  180. * stream. The call will block until one of the following conditions is true:
  181. *
  182. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  183. * the sum of the buffer sizes.
  184. *
  185. * @li The completion_condition function object returns 0.
  186. *
  187. * This operation is implemented in terms of zero or more calls to the stream's
  188. * read_some function.
  189. *
  190. * @param s The stream from which the data is to be read. The type must support
  191. * the SyncReadStream concept.
  192. *
  193. * @param buffers One or more buffers into which the data will be read. The sum
  194. * of the buffer sizes indicates the maximum number of bytes to read from the
  195. * stream.
  196. *
  197. * @param completion_condition The function object to be called to determine
  198. * whether the read operation is complete. The signature of the function object
  199. * must be:
  200. * @code std::size_t completion_condition(
  201. * // Result of latest read_some operation.
  202. * const boost::system::error_code& error,
  203. *
  204. * // Number of bytes transferred so far.
  205. * std::size_t bytes_transferred
  206. * ); @endcode
  207. * A return value of 0 indicates that the read operation is complete. A non-zero
  208. * return value indicates the maximum number of bytes to be read on the next
  209. * call to the stream's read_some function.
  210. *
  211. * @param ec Set to indicate what error occurred, if any.
  212. *
  213. * @returns The number of bytes read. If an error occurs, returns the total
  214. * number of bytes successfully transferred prior to the error.
  215. */
  216. template <typename SyncReadStream, typename MutableBufferSequence,
  217. typename CompletionCondition>
  218. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  219. CompletionCondition completion_condition, boost::system::error_code& ec,
  220. typename constraint<
  221. is_mutable_buffer_sequence<MutableBufferSequence>::value
  222. >::type = 0);
  223. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  224. /// Attempt to read a certain amount of data from a stream before returning.
  225. /**
  226. * This function is used to read a certain number of bytes of data from a
  227. * stream. The call will block until one of the following conditions is true:
  228. *
  229. * @li The specified dynamic buffer sequence is full (that is, it has reached
  230. * maximum size).
  231. *
  232. * @li An error occurred.
  233. *
  234. * This operation is implemented in terms of zero or more calls to the stream's
  235. * read_some function.
  236. *
  237. * @param s The stream from which the data is to be read. The type must support
  238. * the SyncReadStream concept.
  239. *
  240. * @param buffers The dynamic buffer sequence into which the data will be read.
  241. *
  242. * @returns The number of bytes transferred.
  243. *
  244. * @throws boost::system::system_error Thrown on failure.
  245. *
  246. * @note This overload is equivalent to calling:
  247. * @code boost::asio::read(
  248. * s, buffers,
  249. * boost::asio::transfer_all()); @endcode
  250. */
  251. template <typename SyncReadStream, typename DynamicBuffer_v1>
  252. std::size_t read(SyncReadStream& s,
  253. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  254. typename constraint<
  255. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  256. >::type = 0,
  257. typename constraint<
  258. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  259. >::type = 0);
  260. /// Attempt to read a certain amount of data from a stream before returning.
  261. /**
  262. * This function is used to read a certain number of bytes of data from a
  263. * stream. The call will block until one of the following conditions is true:
  264. *
  265. * @li The supplied buffer is full (that is, it has reached maximum size).
  266. *
  267. * @li An error occurred.
  268. *
  269. * This operation is implemented in terms of zero or more calls to the stream's
  270. * read_some function.
  271. *
  272. * @param s The stream from which the data is to be read. The type must support
  273. * the SyncReadStream concept.
  274. *
  275. * @param buffers The dynamic buffer sequence into which the data will be read.
  276. *
  277. * @param ec Set to indicate what error occurred, if any.
  278. *
  279. * @returns The number of bytes transferred.
  280. *
  281. * @note This overload is equivalent to calling:
  282. * @code boost::asio::read(
  283. * s, buffers,
  284. * boost::asio::transfer_all(), ec); @endcode
  285. */
  286. template <typename SyncReadStream, typename DynamicBuffer_v1>
  287. std::size_t read(SyncReadStream& s,
  288. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  289. boost::system::error_code& ec,
  290. typename constraint<
  291. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  292. >::type = 0,
  293. typename constraint<
  294. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  295. >::type = 0);
  296. /// Attempt to read a certain amount of data from a stream before returning.
  297. /**
  298. * This function is used to read a certain number of bytes of data from a
  299. * stream. The call will block until one of the following conditions is true:
  300. *
  301. * @li The specified dynamic buffer sequence is full (that is, it has reached
  302. * maximum size).
  303. *
  304. * @li The completion_condition function object returns 0.
  305. *
  306. * This operation is implemented in terms of zero or more calls to the stream's
  307. * read_some function.
  308. *
  309. * @param s The stream from which the data is to be read. The type must support
  310. * the SyncReadStream concept.
  311. *
  312. * @param buffers The dynamic buffer sequence into which the data will be read.
  313. *
  314. * @param completion_condition The function object to be called to determine
  315. * whether the read operation is complete. The signature of the function object
  316. * must be:
  317. * @code std::size_t completion_condition(
  318. * // Result of latest read_some operation.
  319. * const boost::system::error_code& error,
  320. *
  321. * // Number of bytes transferred so far.
  322. * std::size_t bytes_transferred
  323. * ); @endcode
  324. * A return value of 0 indicates that the read operation is complete. A non-zero
  325. * return value indicates the maximum number of bytes to be read on the next
  326. * call to the stream's read_some function.
  327. *
  328. * @returns The number of bytes transferred.
  329. *
  330. * @throws boost::system::system_error Thrown on failure.
  331. */
  332. template <typename SyncReadStream, typename DynamicBuffer_v1,
  333. typename CompletionCondition>
  334. std::size_t read(SyncReadStream& s,
  335. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  336. CompletionCondition completion_condition,
  337. typename constraint<
  338. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  339. >::type = 0,
  340. typename constraint<
  341. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  342. >::type = 0);
  343. /// Attempt to read a certain amount of data from a stream before returning.
  344. /**
  345. * This function is used to read a certain number of bytes of data from a
  346. * stream. The call will block until one of the following conditions is true:
  347. *
  348. * @li The specified dynamic buffer sequence is full (that is, it has reached
  349. * maximum size).
  350. *
  351. * @li The completion_condition function object returns 0.
  352. *
  353. * This operation is implemented in terms of zero or more calls to the stream's
  354. * read_some function.
  355. *
  356. * @param s The stream from which the data is to be read. The type must support
  357. * the SyncReadStream concept.
  358. *
  359. * @param buffers The dynamic buffer sequence into which the data will be read.
  360. *
  361. * @param completion_condition The function object to be called to determine
  362. * whether the read operation is complete. The signature of the function object
  363. * must be:
  364. * @code std::size_t completion_condition(
  365. * // Result of latest read_some operation.
  366. * const boost::system::error_code& error,
  367. *
  368. * // Number of bytes transferred so far.
  369. * std::size_t bytes_transferred
  370. * ); @endcode
  371. * A return value of 0 indicates that the read operation is complete. A non-zero
  372. * return value indicates the maximum number of bytes to be read on the next
  373. * call to the stream's read_some function.
  374. *
  375. * @param ec Set to indicate what error occurred, if any.
  376. *
  377. * @returns The number of bytes read. If an error occurs, returns the total
  378. * number of bytes successfully transferred prior to the error.
  379. */
  380. template <typename SyncReadStream, typename DynamicBuffer_v1,
  381. typename CompletionCondition>
  382. std::size_t read(SyncReadStream& s,
  383. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  384. CompletionCondition completion_condition, boost::system::error_code& ec,
  385. typename constraint<
  386. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  387. >::type = 0,
  388. typename constraint<
  389. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  390. >::type = 0);
  391. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  392. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  393. /// Attempt to read a certain amount of data from a stream before returning.
  394. /**
  395. * This function is used to read a certain number of bytes of data from a
  396. * stream. The call will block until one of the following conditions is true:
  397. *
  398. * @li The supplied buffer is full (that is, it has reached maximum size).
  399. *
  400. * @li An error occurred.
  401. *
  402. * This operation is implemented in terms of zero or more calls to the stream's
  403. * read_some function.
  404. *
  405. * @param s The stream from which the data is to be read. The type must support
  406. * the SyncReadStream concept.
  407. *
  408. * @param b The basic_streambuf object into which the data will be read.
  409. *
  410. * @returns The number of bytes transferred.
  411. *
  412. * @throws boost::system::system_error Thrown on failure.
  413. *
  414. * @note This overload is equivalent to calling:
  415. * @code boost::asio::read(
  416. * s, b,
  417. * boost::asio::transfer_all()); @endcode
  418. */
  419. template <typename SyncReadStream, typename Allocator>
  420. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
  421. /// Attempt to read a certain amount of data from a stream before returning.
  422. /**
  423. * This function is used to read a certain number of bytes of data from a
  424. * stream. The call will block until one of the following conditions is true:
  425. *
  426. * @li The supplied buffer is full (that is, it has reached maximum size).
  427. *
  428. * @li An error occurred.
  429. *
  430. * This operation is implemented in terms of zero or more calls to the stream's
  431. * read_some function.
  432. *
  433. * @param s The stream from which the data is to be read. The type must support
  434. * the SyncReadStream concept.
  435. *
  436. * @param b The basic_streambuf object into which the data will be read.
  437. *
  438. * @param ec Set to indicate what error occurred, if any.
  439. *
  440. * @returns The number of bytes transferred.
  441. *
  442. * @note This overload is equivalent to calling:
  443. * @code boost::asio::read(
  444. * s, b,
  445. * boost::asio::transfer_all(), ec); @endcode
  446. */
  447. template <typename SyncReadStream, typename Allocator>
  448. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  449. boost::system::error_code& ec);
  450. /// Attempt to read a certain amount of data from a stream before returning.
  451. /**
  452. * This function is used to read a certain number of bytes of data from a
  453. * stream. The call will block until one of the following conditions is true:
  454. *
  455. * @li The supplied buffer is full (that is, it has reached maximum size).
  456. *
  457. * @li The completion_condition function object returns 0.
  458. *
  459. * This operation is implemented in terms of zero or more calls to the stream's
  460. * read_some function.
  461. *
  462. * @param s The stream from which the data is to be read. The type must support
  463. * the SyncReadStream concept.
  464. *
  465. * @param b The basic_streambuf object into which the data will be read.
  466. *
  467. * @param completion_condition The function object to be called to determine
  468. * whether the read operation is complete. The signature of the function object
  469. * must be:
  470. * @code std::size_t completion_condition(
  471. * // Result of latest read_some operation.
  472. * const boost::system::error_code& error,
  473. *
  474. * // Number of bytes transferred so far.
  475. * std::size_t bytes_transferred
  476. * ); @endcode
  477. * A return value of 0 indicates that the read operation is complete. A non-zero
  478. * return value indicates the maximum number of bytes to be read on the next
  479. * call to the stream's read_some function.
  480. *
  481. * @returns The number of bytes transferred.
  482. *
  483. * @throws boost::system::system_error Thrown on failure.
  484. */
  485. template <typename SyncReadStream, typename Allocator,
  486. typename CompletionCondition>
  487. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  488. CompletionCondition completion_condition);
  489. /// Attempt to read a certain amount of data from a stream before returning.
  490. /**
  491. * This function is used to read a certain number of bytes of data from a
  492. * stream. The call will block until one of the following conditions is true:
  493. *
  494. * @li The supplied buffer is full (that is, it has reached maximum size).
  495. *
  496. * @li The completion_condition function object returns 0.
  497. *
  498. * This operation is implemented in terms of zero or more calls to the stream's
  499. * read_some function.
  500. *
  501. * @param s The stream from which the data is to be read. The type must support
  502. * the SyncReadStream concept.
  503. *
  504. * @param b The basic_streambuf object into which the data will be read.
  505. *
  506. * @param completion_condition The function object to be called to determine
  507. * whether the read operation is complete. The signature of the function object
  508. * must be:
  509. * @code std::size_t completion_condition(
  510. * // Result of latest read_some operation.
  511. * const boost::system::error_code& error,
  512. *
  513. * // Number of bytes transferred so far.
  514. * std::size_t bytes_transferred
  515. * ); @endcode
  516. * A return value of 0 indicates that the read operation is complete. A non-zero
  517. * return value indicates the maximum number of bytes to be read on the next
  518. * call to the stream's read_some function.
  519. *
  520. * @param ec Set to indicate what error occurred, if any.
  521. *
  522. * @returns The number of bytes read. If an error occurs, returns the total
  523. * number of bytes successfully transferred prior to the error.
  524. */
  525. template <typename SyncReadStream, typename Allocator,
  526. typename CompletionCondition>
  527. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  528. CompletionCondition completion_condition, boost::system::error_code& ec);
  529. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  530. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  531. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  532. /// Attempt to read a certain amount of data from a stream before returning.
  533. /**
  534. * This function is used to read a certain number of bytes of data from a
  535. * stream. The call will block until one of the following conditions is true:
  536. *
  537. * @li The specified dynamic buffer sequence is full (that is, it has reached
  538. * maximum size).
  539. *
  540. * @li An error occurred.
  541. *
  542. * This operation is implemented in terms of zero or more calls to the stream's
  543. * read_some function.
  544. *
  545. * @param s The stream from which the data is to be read. The type must support
  546. * the SyncReadStream concept.
  547. *
  548. * @param buffers The dynamic buffer sequence into which the data will be read.
  549. *
  550. * @returns The number of bytes transferred.
  551. *
  552. * @throws boost::system::system_error Thrown on failure.
  553. *
  554. * @note This overload is equivalent to calling:
  555. * @code boost::asio::read(
  556. * s, buffers,
  557. * boost::asio::transfer_all()); @endcode
  558. */
  559. template <typename SyncReadStream, typename DynamicBuffer_v2>
  560. std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
  561. typename constraint<
  562. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  563. >::type = 0);
  564. /// Attempt to read a certain amount of data from a stream before returning.
  565. /**
  566. * This function is used to read a certain number of bytes of data from a
  567. * stream. The call will block until one of the following conditions is true:
  568. *
  569. * @li The supplied buffer is full (that is, it has reached maximum size).
  570. *
  571. * @li An error occurred.
  572. *
  573. * This operation is implemented in terms of zero or more calls to the stream's
  574. * read_some function.
  575. *
  576. * @param s The stream from which the data is to be read. The type must support
  577. * the SyncReadStream concept.
  578. *
  579. * @param buffers The dynamic buffer sequence into which the data will be read.
  580. *
  581. * @param ec Set to indicate what error occurred, if any.
  582. *
  583. * @returns The number of bytes transferred.
  584. *
  585. * @note This overload is equivalent to calling:
  586. * @code boost::asio::read(
  587. * s, buffers,
  588. * boost::asio::transfer_all(), ec); @endcode
  589. */
  590. template <typename SyncReadStream, typename DynamicBuffer_v2>
  591. std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
  592. boost::system::error_code& ec,
  593. typename constraint<
  594. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  595. >::type = 0);
  596. /// Attempt to read a certain amount of data from a stream before returning.
  597. /**
  598. * This function is used to read a certain number of bytes of data from a
  599. * stream. The call will block until one of the following conditions is true:
  600. *
  601. * @li The specified dynamic buffer sequence is full (that is, it has reached
  602. * maximum size).
  603. *
  604. * @li The completion_condition function object returns 0.
  605. *
  606. * This operation is implemented in terms of zero or more calls to the stream's
  607. * read_some function.
  608. *
  609. * @param s The stream from which the data is to be read. The type must support
  610. * the SyncReadStream concept.
  611. *
  612. * @param buffers The dynamic buffer sequence into which the data will be read.
  613. *
  614. * @param completion_condition The function object to be called to determine
  615. * whether the read operation is complete. The signature of the function object
  616. * must be:
  617. * @code std::size_t completion_condition(
  618. * // Result of latest read_some operation.
  619. * const boost::system::error_code& error,
  620. *
  621. * // Number of bytes transferred so far.
  622. * std::size_t bytes_transferred
  623. * ); @endcode
  624. * A return value of 0 indicates that the read operation is complete. A non-zero
  625. * return value indicates the maximum number of bytes to be read on the next
  626. * call to the stream's read_some function.
  627. *
  628. * @returns The number of bytes transferred.
  629. *
  630. * @throws boost::system::system_error Thrown on failure.
  631. */
  632. template <typename SyncReadStream, typename DynamicBuffer_v2,
  633. typename CompletionCondition>
  634. std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
  635. CompletionCondition completion_condition,
  636. typename constraint<
  637. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  638. >::type = 0);
  639. /// Attempt to read a certain amount of data from a stream before returning.
  640. /**
  641. * This function is used to read a certain number of bytes of data from a
  642. * stream. The call will block until one of the following conditions is true:
  643. *
  644. * @li The specified dynamic buffer sequence is full (that is, it has reached
  645. * maximum size).
  646. *
  647. * @li The completion_condition function object returns 0.
  648. *
  649. * This operation is implemented in terms of zero or more calls to the stream's
  650. * read_some function.
  651. *
  652. * @param s The stream from which the data is to be read. The type must support
  653. * the SyncReadStream concept.
  654. *
  655. * @param buffers The dynamic buffer sequence into which the data will be read.
  656. *
  657. * @param completion_condition The function object to be called to determine
  658. * whether the read operation is complete. The signature of the function object
  659. * must be:
  660. * @code std::size_t completion_condition(
  661. * // Result of latest read_some operation.
  662. * const boost::system::error_code& error,
  663. *
  664. * // Number of bytes transferred so far.
  665. * std::size_t bytes_transferred
  666. * ); @endcode
  667. * A return value of 0 indicates that the read operation is complete. A non-zero
  668. * return value indicates the maximum number of bytes to be read on the next
  669. * call to the stream's read_some function.
  670. *
  671. * @param ec Set to indicate what error occurred, if any.
  672. *
  673. * @returns The number of bytes read. If an error occurs, returns the total
  674. * number of bytes successfully transferred prior to the error.
  675. */
  676. template <typename SyncReadStream, typename DynamicBuffer_v2,
  677. typename CompletionCondition>
  678. std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
  679. CompletionCondition completion_condition, boost::system::error_code& ec,
  680. typename constraint<
  681. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  682. >::type = 0);
  683. /*@}*/
  684. /**
  685. * @defgroup async_read boost::asio::async_read
  686. *
  687. * @brief The @c async_read function is a composed asynchronous operation that
  688. * reads a certain amount of data from a stream before completion.
  689. */
  690. /*@{*/
  691. /// Start an asynchronous operation to read a certain amount of data from a
  692. /// stream.
  693. /**
  694. * This function is used to asynchronously read a certain number of bytes of
  695. * data from a stream. It is an initiating function for an @ref
  696. * asynchronous_operation, and always returns immediately. The asynchronous
  697. * operation will continue until one of the following conditions is true:
  698. *
  699. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  700. * the sum of the buffer sizes.
  701. *
  702. * @li An error occurred.
  703. *
  704. * This operation is implemented in terms of zero or more calls to the stream's
  705. * async_read_some function, and is known as a <em>composed operation</em>. The
  706. * program must ensure that the stream performs no other read operations (such
  707. * as async_read, the stream's async_read_some function, or any other composed
  708. * operations that perform reads) until this operation completes.
  709. *
  710. * @param s The stream from which the data is to be read. The type must support
  711. * the AsyncReadStream concept.
  712. *
  713. * @param buffers One or more buffers into which the data will be read. The sum
  714. * of the buffer sizes indicates the maximum number of bytes to read from the
  715. * stream. Although the buffers object may be copied as necessary, ownership of
  716. * the underlying memory blocks is retained by the caller, which must guarantee
  717. * that they remain valid until the completion handler is called.
  718. *
  719. * @param token The @ref completion_token that will be used to produce a
  720. * completion handler, which will be called when the read completes.
  721. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  722. * @ref yield_context, or a function object with the correct completion
  723. * signature. The function signature of the completion handler must be:
  724. * @code void handler(
  725. * // Result of operation.
  726. * const boost::system::error_code& error,
  727. *
  728. * // Number of bytes copied into the buffers. If an error
  729. * // occurred, this will be the number of bytes successfully
  730. * // transferred prior to the error.
  731. * std::size_t bytes_transferred
  732. * ); @endcode
  733. * Regardless of whether the asynchronous operation completes immediately or
  734. * not, the completion handler will not be invoked from within this function.
  735. * On immediate completion, invocation of the handler will be performed in a
  736. * manner equivalent to using boost::asio::post().
  737. *
  738. * @par Completion Signature
  739. * @code void(boost::system::error_code, std::size_t) @endcode
  740. *
  741. * @par Example
  742. * To read into a single data buffer use the @ref buffer function as follows:
  743. * @code
  744. * boost::asio::async_read(s, boost::asio::buffer(data, size), handler);
  745. * @endcode
  746. * See the @ref buffer documentation for information on reading into multiple
  747. * buffers in one go, and how to use it with arrays, boost::array or
  748. * std::vector.
  749. *
  750. * @note This overload is equivalent to calling:
  751. * @code boost::asio::async_read(
  752. * s, buffers,
  753. * boost::asio::transfer_all(),
  754. * handler); @endcode
  755. *
  756. * @par Per-Operation Cancellation
  757. * This asynchronous operation supports cancellation for the following
  758. * boost::asio::cancellation_type values:
  759. *
  760. * @li @c cancellation_type::terminal
  761. *
  762. * @li @c cancellation_type::partial
  763. *
  764. * if they are also supported by the @c AsyncReadStream type's
  765. * @c async_read_some operation.
  766. */
  767. template <typename AsyncReadStream, typename MutableBufferSequence,
  768. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  769. std::size_t)) ReadToken
  770. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  771. typename AsyncReadStream::executor_type)>
  772. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  773. void (boost::system::error_code, std::size_t))
  774. async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
  775. BOOST_ASIO_MOVE_ARG(ReadToken) token
  776. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  777. typename AsyncReadStream::executor_type),
  778. typename constraint<
  779. is_mutable_buffer_sequence<MutableBufferSequence>::value
  780. >::type = 0)
  781. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  782. async_initiate<ReadToken,
  783. void (boost::system::error_code, std::size_t)>(
  784. declval<detail::initiate_async_read<AsyncReadStream> >(),
  785. token, buffers, transfer_all())));
  786. /// Start an asynchronous operation to read a certain amount of data from a
  787. /// stream.
  788. /**
  789. * This function is used to asynchronously read a certain number of bytes of
  790. * data from a stream. It is an initiating function for an @ref
  791. * asynchronous_operation, and always returns immediately. The asynchronous
  792. * operation will continue until one of the following conditions is true:
  793. *
  794. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  795. * the sum of the buffer sizes.
  796. *
  797. * @li The completion_condition function object returns 0.
  798. *
  799. * @param s The stream from which the data is to be read. The type must support
  800. * the AsyncReadStream concept.
  801. *
  802. * @param buffers One or more buffers into which the data will be read. The sum
  803. * of the buffer sizes indicates the maximum number of bytes to read from the
  804. * stream. Although the buffers object may be copied as necessary, ownership of
  805. * the underlying memory blocks is retained by the caller, which must guarantee
  806. * that they remain valid until the completion handler is called.
  807. *
  808. * @param completion_condition The function object to be called to determine
  809. * whether the read operation is complete. The signature of the function object
  810. * must be:
  811. * @code std::size_t completion_condition(
  812. * // Result of latest async_read_some operation.
  813. * const boost::system::error_code& error,
  814. *
  815. * // Number of bytes transferred so far.
  816. * std::size_t bytes_transferred
  817. * ); @endcode
  818. * A return value of 0 indicates that the read operation is complete. A non-zero
  819. * return value indicates the maximum number of bytes to be read on the next
  820. * call to the stream's async_read_some function.
  821. *
  822. * @param token The @ref completion_token that will be used to produce a
  823. * completion handler, which will be called when the read completes.
  824. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  825. * @ref yield_context, or a function object with the correct completion
  826. * signature. The function signature of the completion handler must be:
  827. * @code void handler(
  828. * // Result of operation.
  829. * const boost::system::error_code& error,
  830. *
  831. * // Number of bytes copied into the buffers. If an error
  832. * // occurred, this will be the number of bytes successfully
  833. * // transferred prior to the error.
  834. * std::size_t bytes_transferred
  835. * ); @endcode
  836. * Regardless of whether the asynchronous operation completes immediately or
  837. * not, the completion handler will not be invoked from within this function.
  838. * On immediate completion, invocation of the handler will be performed in a
  839. * manner equivalent to using boost::asio::post().
  840. *
  841. * @par Completion Signature
  842. * @code void(boost::system::error_code, std::size_t) @endcode
  843. *
  844. * @par Example
  845. * To read into a single data buffer use the @ref buffer function as follows:
  846. * @code boost::asio::async_read(s,
  847. * boost::asio::buffer(data, size),
  848. * boost::asio::transfer_at_least(32),
  849. * handler); @endcode
  850. * See the @ref buffer documentation for information on reading into multiple
  851. * buffers in one go, and how to use it with arrays, boost::array or
  852. * std::vector.
  853. *
  854. * @par Per-Operation Cancellation
  855. * This asynchronous operation supports cancellation for the following
  856. * boost::asio::cancellation_type values:
  857. *
  858. * @li @c cancellation_type::terminal
  859. *
  860. * @li @c cancellation_type::partial
  861. *
  862. * if they are also supported by the @c AsyncReadStream type's
  863. * @c async_read_some operation.
  864. */
  865. template <typename AsyncReadStream,
  866. typename MutableBufferSequence, typename CompletionCondition,
  867. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  868. std::size_t)) ReadToken
  869. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  870. typename AsyncReadStream::executor_type)>
  871. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  872. void (boost::system::error_code, std::size_t))
  873. async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
  874. CompletionCondition completion_condition,
  875. BOOST_ASIO_MOVE_ARG(ReadToken) token
  876. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  877. typename AsyncReadStream::executor_type),
  878. typename constraint<
  879. is_mutable_buffer_sequence<MutableBufferSequence>::value
  880. >::type = 0)
  881. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  882. async_initiate<ReadToken,
  883. void (boost::system::error_code, std::size_t)>(
  884. declval<detail::initiate_async_read<AsyncReadStream> >(),
  885. token, buffers,
  886. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition))));
  887. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  888. /// Start an asynchronous operation to read a certain amount of data from a
  889. /// stream.
  890. /**
  891. * This function is used to asynchronously read a certain number of bytes of
  892. * data from a stream. It is an initiating function for an @ref
  893. * asynchronous_operation, and always returns immediately. The asynchronous
  894. * operation will continue until one of the following conditions is true:
  895. *
  896. * @li The specified dynamic buffer sequence is full (that is, it has reached
  897. * maximum size).
  898. *
  899. * @li An error occurred.
  900. *
  901. * This operation is implemented in terms of zero or more calls to the stream's
  902. * async_read_some function, and is known as a <em>composed operation</em>. The
  903. * program must ensure that the stream performs no other read operations (such
  904. * as async_read, the stream's async_read_some function, or any other composed
  905. * operations that perform reads) until this operation completes.
  906. *
  907. * @param s The stream from which the data is to be read. The type must support
  908. * the AsyncReadStream concept.
  909. *
  910. * @param buffers The dynamic buffer sequence into which the data will be read.
  911. * Although the buffers object may be copied as necessary, ownership of the
  912. * underlying memory blocks is retained by the caller, which must guarantee
  913. * that they remain valid until the completion handler is called.
  914. *
  915. * @param token The @ref completion_token that will be used to produce a
  916. * completion handler, which will be called when the read completes.
  917. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  918. * @ref yield_context, or a function object with the correct completion
  919. * signature. The function signature of the completion handler must be:
  920. * @code void handler(
  921. * // Result of operation.
  922. * const boost::system::error_code& error,
  923. *
  924. * // Number of bytes copied into the buffers. If an error
  925. * // occurred, this will be the number of bytes successfully
  926. * // transferred prior to the error.
  927. * std::size_t bytes_transferred
  928. * ); @endcode
  929. * Regardless of whether the asynchronous operation completes immediately or
  930. * not, the completion handler will not be invoked from within this function.
  931. * On immediate completion, invocation of the handler will be performed in a
  932. * manner equivalent to using boost::asio::post().
  933. *
  934. * @par Completion Signature
  935. * @code void(boost::system::error_code, std::size_t) @endcode
  936. *
  937. * @note This overload is equivalent to calling:
  938. * @code boost::asio::async_read(
  939. * s, buffers,
  940. * boost::asio::transfer_all(),
  941. * handler); @endcode
  942. *
  943. * @par Per-Operation Cancellation
  944. * This asynchronous operation supports cancellation for the following
  945. * boost::asio::cancellation_type values:
  946. *
  947. * @li @c cancellation_type::terminal
  948. *
  949. * @li @c cancellation_type::partial
  950. *
  951. * if they are also supported by the @c AsyncReadStream type's
  952. * @c async_read_some operation.
  953. */
  954. template <typename AsyncReadStream, typename DynamicBuffer_v1,
  955. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  956. std::size_t)) ReadToken
  957. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  958. typename AsyncReadStream::executor_type)>
  959. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  960. void (boost::system::error_code, std::size_t))
  961. async_read(AsyncReadStream& s,
  962. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  963. BOOST_ASIO_MOVE_ARG(ReadToken) token
  964. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  965. typename AsyncReadStream::executor_type),
  966. typename constraint<
  967. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  968. >::type = 0,
  969. typename constraint<
  970. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  971. >::type = 0)
  972. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  973. async_initiate<ReadToken,
  974. void (boost::system::error_code, std::size_t)>(
  975. declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream> >(),
  976. token, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  977. transfer_all())));
  978. /// Start an asynchronous operation to read a certain amount of data from a
  979. /// stream.
  980. /**
  981. * This function is used to asynchronously read a certain number of bytes of
  982. * data from a stream. It is an initiating function for an @ref
  983. * asynchronous_operation, and always returns immediately. The asynchronous
  984. * operation will continue until one of the following conditions is true:
  985. *
  986. * @li The specified dynamic buffer sequence is full (that is, it has reached
  987. * maximum size).
  988. *
  989. * @li The completion_condition function object returns 0.
  990. *
  991. * This operation is implemented in terms of zero or more calls to the stream's
  992. * async_read_some function, and is known as a <em>composed operation</em>. The
  993. * program must ensure that the stream performs no other read operations (such
  994. * as async_read, the stream's async_read_some function, or any other composed
  995. * operations that perform reads) until this operation completes.
  996. *
  997. * @param s The stream from which the data is to be read. The type must support
  998. * the AsyncReadStream concept.
  999. *
  1000. * @param buffers The dynamic buffer sequence into which the data will be read.
  1001. * Although the buffers object may be copied as necessary, ownership of the
  1002. * underlying memory blocks is retained by the caller, which must guarantee
  1003. * that they remain valid until the completion handler is called.
  1004. *
  1005. * @param completion_condition The function object to be called to determine
  1006. * whether the read operation is complete. The signature of the function object
  1007. * must be:
  1008. * @code std::size_t completion_condition(
  1009. * // Result of latest async_read_some operation.
  1010. * const boost::system::error_code& error,
  1011. *
  1012. * // Number of bytes transferred so far.
  1013. * std::size_t bytes_transferred
  1014. * ); @endcode
  1015. * A return value of 0 indicates that the read operation is complete. A non-zero
  1016. * return value indicates the maximum number of bytes to be read on the next
  1017. * call to the stream's async_read_some function.
  1018. *
  1019. * @param token The @ref completion_token that will be used to produce a
  1020. * completion handler, which will be called when the read completes.
  1021. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1022. * @ref yield_context, or a function object with the correct completion
  1023. * signature. The function signature of the completion handler must be:
  1024. * @code void handler(
  1025. * // Result of operation.
  1026. * const boost::system::error_code& error,
  1027. *
  1028. * // Number of bytes copied into the buffers. If an error
  1029. * // occurred, this will be the number of bytes successfully
  1030. * // transferred prior to the error.
  1031. * std::size_t bytes_transferred
  1032. * ); @endcode
  1033. * Regardless of whether the asynchronous operation completes immediately or
  1034. * not, the completion handler will not be invoked from within this function.
  1035. * On immediate completion, invocation of the handler will be performed in a
  1036. * manner equivalent to using boost::asio::post().
  1037. *
  1038. * @par Completion Signature
  1039. * @code void(boost::system::error_code, std::size_t) @endcode
  1040. *
  1041. * @par Per-Operation Cancellation
  1042. * This asynchronous operation supports cancellation for the following
  1043. * boost::asio::cancellation_type values:
  1044. *
  1045. * @li @c cancellation_type::terminal
  1046. *
  1047. * @li @c cancellation_type::partial
  1048. *
  1049. * if they are also supported by the @c AsyncReadStream type's
  1050. * @c async_read_some operation.
  1051. */
  1052. template <typename AsyncReadStream,
  1053. typename DynamicBuffer_v1, typename CompletionCondition,
  1054. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1055. std::size_t)) ReadToken
  1056. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1057. typename AsyncReadStream::executor_type)>
  1058. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  1059. void (boost::system::error_code, std::size_t))
  1060. async_read(AsyncReadStream& s,
  1061. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  1062. CompletionCondition completion_condition,
  1063. BOOST_ASIO_MOVE_ARG(ReadToken) token
  1064. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1065. typename AsyncReadStream::executor_type),
  1066. typename constraint<
  1067. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  1068. >::type = 0,
  1069. typename constraint<
  1070. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  1071. >::type = 0)
  1072. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  1073. async_initiate<ReadToken,
  1074. void (boost::system::error_code, std::size_t)>(
  1075. declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream> >(),
  1076. token, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  1077. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition))));
  1078. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  1079. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  1080. /// Start an asynchronous operation to read a certain amount of data from a
  1081. /// stream.
  1082. /**
  1083. * This function is used to asynchronously read a certain number of bytes of
  1084. * data from a stream. It is an initiating function for an @ref
  1085. * asynchronous_operation, and always returns immediately. The asynchronous
  1086. * operation will continue until one of the following conditions is true:
  1087. *
  1088. * @li The supplied buffer is full (that is, it has reached maximum size).
  1089. *
  1090. * @li An error occurred.
  1091. *
  1092. * This operation is implemented in terms of zero or more calls to the stream's
  1093. * async_read_some function, and is known as a <em>composed operation</em>. The
  1094. * program must ensure that the stream performs no other read operations (such
  1095. * as async_read, the stream's async_read_some function, or any other composed
  1096. * operations that perform reads) until this operation completes.
  1097. *
  1098. * @param s The stream from which the data is to be read. The type must support
  1099. * the AsyncReadStream concept.
  1100. *
  1101. * @param b A basic_streambuf object into which the data will be read. Ownership
  1102. * of the streambuf is retained by the caller, which must guarantee that it
  1103. * remains valid until the completion handler is called.
  1104. *
  1105. * @param token The @ref completion_token that will be used to produce a
  1106. * completion handler, which will be called when the read completes.
  1107. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1108. * @ref yield_context, or a function object with the correct completion
  1109. * signature. The function signature of the completion handler must be:
  1110. * @code void handler(
  1111. * // Result of operation.
  1112. * const boost::system::error_code& error,
  1113. *
  1114. * // Number of bytes copied into the buffers. If an error
  1115. * // occurred, this will be the number of bytes successfully
  1116. * // transferred prior to the error.
  1117. * std::size_t bytes_transferred
  1118. * ); @endcode
  1119. * Regardless of whether the asynchronous operation completes immediately or
  1120. * not, the completion handler will not be invoked from within this function.
  1121. * On immediate completion, invocation of the handler will be performed in a
  1122. * manner equivalent to using boost::asio::post().
  1123. *
  1124. * @par Completion Signature
  1125. * @code void(boost::system::error_code, std::size_t) @endcode
  1126. *
  1127. * @note This overload is equivalent to calling:
  1128. * @code boost::asio::async_read(
  1129. * s, b,
  1130. * boost::asio::transfer_all(),
  1131. * handler); @endcode
  1132. *
  1133. * @par Per-Operation Cancellation
  1134. * This asynchronous operation supports cancellation for the following
  1135. * boost::asio::cancellation_type values:
  1136. *
  1137. * @li @c cancellation_type::terminal
  1138. *
  1139. * @li @c cancellation_type::partial
  1140. *
  1141. * if they are also supported by the @c AsyncReadStream type's
  1142. * @c async_read_some operation.
  1143. */
  1144. template <typename AsyncReadStream, typename Allocator,
  1145. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1146. std::size_t)) ReadToken
  1147. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1148. typename AsyncReadStream::executor_type)>
  1149. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  1150. void (boost::system::error_code, std::size_t))
  1151. async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
  1152. BOOST_ASIO_MOVE_ARG(ReadToken) token
  1153. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1154. typename AsyncReadStream::executor_type))
  1155. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  1156. async_read(s, basic_streambuf_ref<Allocator>(b),
  1157. BOOST_ASIO_MOVE_CAST(ReadToken)(token))));
  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 The completion_condition function object returns 0.
  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 completion_condition The function object to be called to determine
  1184. * whether the read operation is complete. The signature of the function object
  1185. * must be:
  1186. * @code std::size_t completion_condition(
  1187. * // Result of latest async_read_some operation.
  1188. * const boost::system::error_code& error,
  1189. *
  1190. * // Number of bytes transferred so far.
  1191. * std::size_t bytes_transferred
  1192. * ); @endcode
  1193. * A return value of 0 indicates that the read operation is complete. A non-zero
  1194. * return value indicates the maximum number of bytes to be read on the next
  1195. * call to the stream's async_read_some function.
  1196. *
  1197. * @param token The @ref completion_token that will be used to produce a
  1198. * completion handler, which will be called when the read completes.
  1199. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1200. * @ref yield_context, or a function object with the correct completion
  1201. * signature. The function signature of the completion handler must be:
  1202. * @code void handler(
  1203. * // Result of operation.
  1204. * const boost::system::error_code& error,
  1205. *
  1206. * // Number of bytes copied into the buffers. If an error
  1207. * // occurred, this will be the number of bytes successfully
  1208. * // transferred prior to the error.
  1209. * std::size_t bytes_transferred
  1210. * ); @endcode
  1211. * Regardless of whether the asynchronous operation completes immediately or
  1212. * not, the completion handler will not be invoked from within this function.
  1213. * On immediate completion, invocation of the handler will be performed in a
  1214. * manner equivalent to using boost::asio::post().
  1215. *
  1216. * @par Completion Signature
  1217. * @code void(boost::system::error_code, std::size_t) @endcode
  1218. *
  1219. * @par Per-Operation Cancellation
  1220. * This asynchronous operation supports cancellation for the following
  1221. * boost::asio::cancellation_type values:
  1222. *
  1223. * @li @c cancellation_type::terminal
  1224. *
  1225. * @li @c cancellation_type::partial
  1226. *
  1227. * if they are also supported by the @c AsyncReadStream type's
  1228. * @c async_read_some operation.
  1229. */
  1230. template <typename AsyncReadStream,
  1231. typename Allocator, typename CompletionCondition,
  1232. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1233. std::size_t)) ReadToken
  1234. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1235. typename AsyncReadStream::executor_type)>
  1236. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  1237. void (boost::system::error_code, std::size_t))
  1238. async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
  1239. CompletionCondition completion_condition,
  1240. BOOST_ASIO_MOVE_ARG(ReadToken) token
  1241. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1242. typename AsyncReadStream::executor_type))
  1243. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  1244. async_read(s, basic_streambuf_ref<Allocator>(b),
  1245. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition),
  1246. BOOST_ASIO_MOVE_CAST(ReadToken)(token))));
  1247. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  1248. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  1249. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  1250. /// Start an asynchronous operation to read a certain amount of data from a
  1251. /// stream.
  1252. /**
  1253. * This function is used to asynchronously read a certain number of bytes of
  1254. * data from a stream. It is an initiating function for an @ref
  1255. * asynchronous_operation, and always returns immediately. The asynchronous
  1256. * operation will continue until one of the following conditions is true:
  1257. *
  1258. * @li The specified dynamic buffer sequence is full (that is, it has reached
  1259. * maximum size).
  1260. *
  1261. * @li An error occurred.
  1262. *
  1263. * This operation is implemented in terms of zero or more calls to the stream's
  1264. * async_read_some function, and is known as a <em>composed operation</em>. The
  1265. * program must ensure that the stream performs no other read operations (such
  1266. * as async_read, the stream's async_read_some function, or any other composed
  1267. * operations that perform reads) until this operation completes.
  1268. *
  1269. * @param s The stream from which the data is to be read. The type must support
  1270. * the AsyncReadStream concept.
  1271. *
  1272. * @param buffers The dynamic buffer sequence into which the data will be read.
  1273. * Although the buffers object may be copied as necessary, ownership of the
  1274. * underlying memory blocks is retained by the caller, which must guarantee
  1275. * that they remain valid until the completion handler is called.
  1276. *
  1277. * @param token The @ref completion_token that will be used to produce a
  1278. * completion handler, which will be called when the read completes.
  1279. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1280. * @ref yield_context, or a function object with the correct completion
  1281. * signature. The function signature of the completion handler must be:
  1282. * @code void handler(
  1283. * // Result of operation.
  1284. * const boost::system::error_code& error,
  1285. *
  1286. * // Number of bytes copied into the buffers. If an error
  1287. * // occurred, this will be the number of bytes successfully
  1288. * // transferred prior to the error.
  1289. * std::size_t bytes_transferred
  1290. * ); @endcode
  1291. * Regardless of whether the asynchronous operation completes immediately or
  1292. * not, the completion handler will not be invoked from within this function.
  1293. * On immediate completion, invocation of the handler will be performed in a
  1294. * manner equivalent to using boost::asio::post().
  1295. *
  1296. * @par Completion Signature
  1297. * @code void(boost::system::error_code, std::size_t) @endcode
  1298. *
  1299. * @note This overload is equivalent to calling:
  1300. * @code boost::asio::async_read(
  1301. * s, buffers,
  1302. * boost::asio::transfer_all(),
  1303. * handler); @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, typename DynamicBuffer_v2,
  1317. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1318. std::size_t)) ReadToken
  1319. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1320. typename AsyncReadStream::executor_type)>
  1321. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  1322. void (boost::system::error_code, std::size_t))
  1323. async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
  1324. BOOST_ASIO_MOVE_ARG(ReadToken) token
  1325. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1326. typename AsyncReadStream::executor_type),
  1327. typename constraint<
  1328. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  1329. >::type = 0)
  1330. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  1331. async_initiate<ReadToken,
  1332. void (boost::system::error_code, std::size_t)>(
  1333. declval<detail::initiate_async_read_dynbuf_v2<AsyncReadStream> >(),
  1334. token, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  1335. transfer_all())));
  1336. /// Start an asynchronous operation to read a certain amount of data from a
  1337. /// stream.
  1338. /**
  1339. * This function is used to asynchronously read a certain number of bytes of
  1340. * data from a stream. It is an initiating function for an @ref
  1341. * asynchronous_operation, and always returns immediately. The asynchronous
  1342. * operation will continue until one of the following conditions is true:
  1343. *
  1344. * @li The specified dynamic buffer sequence is full (that is, it has reached
  1345. * maximum size).
  1346. *
  1347. * @li The completion_condition function object returns 0.
  1348. *
  1349. * This operation is implemented in terms of zero or more calls to the stream's
  1350. * async_read_some function, and is known as a <em>composed operation</em>. The
  1351. * program must ensure that the stream performs no other read operations (such
  1352. * as async_read, the stream's async_read_some function, or any other composed
  1353. * operations that perform reads) until this operation completes.
  1354. *
  1355. * @param s The stream from which the data is to be read. The type must support
  1356. * the AsyncReadStream concept.
  1357. *
  1358. * @param buffers The dynamic buffer sequence into which the data will be read.
  1359. * Although the buffers object may be copied as necessary, ownership of the
  1360. * underlying memory blocks is retained by the caller, which must guarantee
  1361. * that they remain valid until the completion handler is called.
  1362. *
  1363. * @param completion_condition The function object to be called to determine
  1364. * whether the read operation is complete. The signature of the function object
  1365. * must be:
  1366. * @code std::size_t completion_condition(
  1367. * // Result of latest async_read_some operation.
  1368. * const boost::system::error_code& error,
  1369. *
  1370. * // Number of bytes transferred so far.
  1371. * std::size_t bytes_transferred
  1372. * ); @endcode
  1373. * A return value of 0 indicates that the read operation is complete. A non-zero
  1374. * return value indicates the maximum number of bytes to be read on the next
  1375. * call to the stream's async_read_some function.
  1376. *
  1377. * @param token The @ref completion_token that will be used to produce a
  1378. * completion handler, which will be called when the read completes.
  1379. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1380. * @ref yield_context, or a function object with the correct completion
  1381. * signature. The function signature of the completion handler must be:
  1382. * @code void handler(
  1383. * // Result of operation.
  1384. * const boost::system::error_code& error,
  1385. *
  1386. * // Number of bytes copied into the buffers. If an error
  1387. * // occurred, this will be the number of bytes successfully
  1388. * // transferred prior to the error.
  1389. * std::size_t bytes_transferred
  1390. * ); @endcode
  1391. * Regardless of whether the asynchronous operation completes immediately or
  1392. * not, the completion handler will not be invoked from within this function.
  1393. * On immediate completion, invocation of the handler will be performed in a
  1394. * manner equivalent to using boost::asio::post().
  1395. *
  1396. * @par Completion Signature
  1397. * @code void(boost::system::error_code, std::size_t) @endcode
  1398. *
  1399. * @par Per-Operation Cancellation
  1400. * This asynchronous operation supports cancellation for the following
  1401. * boost::asio::cancellation_type values:
  1402. *
  1403. * @li @c cancellation_type::terminal
  1404. *
  1405. * @li @c cancellation_type::partial
  1406. *
  1407. * if they are also supported by the @c AsyncReadStream type's
  1408. * @c async_read_some operation.
  1409. */
  1410. template <typename AsyncReadStream,
  1411. typename DynamicBuffer_v2, typename CompletionCondition,
  1412. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1413. std::size_t)) ReadToken
  1414. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1415. typename AsyncReadStream::executor_type)>
  1416. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(ReadToken,
  1417. void (boost::system::error_code, std::size_t))
  1418. async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
  1419. CompletionCondition completion_condition,
  1420. BOOST_ASIO_MOVE_ARG(ReadToken) token
  1421. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1422. typename AsyncReadStream::executor_type),
  1423. typename constraint<
  1424. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  1425. >::type = 0)
  1426. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX((
  1427. async_initiate<ReadToken,
  1428. void (boost::system::error_code, std::size_t)>(
  1429. declval<detail::initiate_async_read_dynbuf_v2<AsyncReadStream> >(),
  1430. token, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  1431. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition))));
  1432. /*@}*/
  1433. } // namespace asio
  1434. } // namespace boost
  1435. #include <boost/asio/detail/pop_options.hpp>
  1436. #include <boost/asio/impl/read.hpp>
  1437. #endif // BOOST_ASIO_READ_HPP