read.hpp 50 KB

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