Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

read.hpp 49KB

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