read.hpp 53 KB

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