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 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. //
  2. // read.hpp
  3. // ~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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/basic_streambuf_fwd.hpp"
  19. #include "asio/buffer.hpp"
  20. #include "asio/error.hpp"
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. /**
  24. * @defgroup read asio::read
  25. *
  26. * @brief Attempt to read a certain amount of data from a stream before
  27. * returning.
  28. */
  29. /*@{*/
  30. /// Attempt to read a certain amount of data from a stream before returning.
  31. /**
  32. * This function is used to read a certain number of bytes of data from a
  33. * stream. The call will block until one of the following conditions is true:
  34. *
  35. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  36. * the sum of the buffer sizes.
  37. *
  38. * @li An error occurred.
  39. *
  40. * This operation is implemented in terms of zero or more calls to the stream's
  41. * read_some function.
  42. *
  43. * @param s The stream from which the data is to be read. The type must support
  44. * the SyncReadStream concept.
  45. *
  46. * @param buffers One or more buffers into which the data will be read. The sum
  47. * of the buffer sizes indicates the maximum number of bytes to read from the
  48. * stream.
  49. *
  50. * @returns The number of bytes transferred.
  51. *
  52. * @throws asio::system_error Thrown on failure.
  53. *
  54. * @par Example
  55. * To read into a single data buffer use the @ref buffer function as follows:
  56. * @code asio::read(s, asio::buffer(data, size)); @endcode
  57. * See the @ref buffer documentation for information on reading into multiple
  58. * buffers in one go, and how to use it with arrays, boost::array or
  59. * std::vector.
  60. *
  61. * @note This overload is equivalent to calling:
  62. * @code asio::read(
  63. * s, buffers,
  64. * asio::transfer_all()); @endcode
  65. */
  66. template <typename SyncReadStream, typename MutableBufferSequence>
  67. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  68. typename enable_if<
  69. is_mutable_buffer_sequence<MutableBufferSequence>::value
  70. >::type* = 0);
  71. /// Attempt to read a certain amount of data from a stream before returning.
  72. /**
  73. * This function is used to read a certain number of bytes of data from a
  74. * stream. The call will block until one of the following conditions is true:
  75. *
  76. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  77. * the sum of the buffer sizes.
  78. *
  79. * @li An error occurred.
  80. *
  81. * This operation is implemented in terms of zero or more calls to the stream's
  82. * read_some function.
  83. *
  84. * @param s The stream from which the data is to be read. The type must support
  85. * the SyncReadStream concept.
  86. *
  87. * @param buffers One or more buffers into which the data will be read. The sum
  88. * of the buffer sizes indicates the maximum number of bytes to read from the
  89. * stream.
  90. *
  91. * @param ec Set to indicate what error occurred, if any.
  92. *
  93. * @returns The number of bytes transferred.
  94. *
  95. * @par Example
  96. * To read into a single data buffer use the @ref buffer function as follows:
  97. * @code asio::read(s, asio::buffer(data, size), ec); @endcode
  98. * See the @ref buffer documentation for information on reading into multiple
  99. * buffers in one go, and how to use it with arrays, boost::array or
  100. * std::vector.
  101. *
  102. * @note This overload is equivalent to calling:
  103. * @code asio::read(
  104. * s, buffers,
  105. * asio::transfer_all(), ec); @endcode
  106. */
  107. template <typename SyncReadStream, typename MutableBufferSequence>
  108. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  109. asio::error_code& ec,
  110. typename enable_if<
  111. is_mutable_buffer_sequence<MutableBufferSequence>::value
  112. >::type* = 0);
  113. /// Attempt to read a certain amount of data from a stream before returning.
  114. /**
  115. * This function is used to read a certain number of bytes of data from a
  116. * stream. The call will block until one of the following conditions is true:
  117. *
  118. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  119. * the sum of the buffer sizes.
  120. *
  121. * @li The completion_condition function object returns 0.
  122. *
  123. * This operation is implemented in terms of zero or more calls to the stream's
  124. * read_some function.
  125. *
  126. * @param s The stream from which the data is to be read. The type must support
  127. * the SyncReadStream concept.
  128. *
  129. * @param buffers One or more buffers into which the data will be read. The sum
  130. * of the buffer sizes indicates the maximum number of bytes to read from the
  131. * stream.
  132. *
  133. * @param completion_condition The function object to be called to determine
  134. * whether the read operation is complete. The signature of the function object
  135. * must be:
  136. * @code std::size_t completion_condition(
  137. * // Result of latest read_some operation.
  138. * const asio::error_code& error,
  139. *
  140. * // Number of bytes transferred so far.
  141. * std::size_t bytes_transferred
  142. * ); @endcode
  143. * A return value of 0 indicates that the read operation is complete. A non-zero
  144. * return value indicates the maximum number of bytes to be read on the next
  145. * call to the stream's read_some function.
  146. *
  147. * @returns The number of bytes transferred.
  148. *
  149. * @throws asio::system_error Thrown on failure.
  150. *
  151. * @par Example
  152. * To read into a single data buffer use the @ref buffer function as follows:
  153. * @code asio::read(s, asio::buffer(data, size),
  154. * asio::transfer_at_least(32)); @endcode
  155. * See the @ref buffer documentation for information on reading into multiple
  156. * buffers in one go, and how to use it with arrays, boost::array or
  157. * std::vector.
  158. */
  159. template <typename SyncReadStream, typename MutableBufferSequence,
  160. typename CompletionCondition>
  161. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  162. CompletionCondition completion_condition,
  163. typename enable_if<
  164. is_mutable_buffer_sequence<MutableBufferSequence>::value
  165. >::type* = 0);
  166. /// Attempt to read a certain amount of data from a stream before returning.
  167. /**
  168. * This function is used to read a certain number of bytes of data from a
  169. * stream. The call will block until one of the following conditions is true:
  170. *
  171. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  172. * the sum of the buffer sizes.
  173. *
  174. * @li The completion_condition function object returns 0.
  175. *
  176. * This operation is implemented in terms of zero or more calls to the stream's
  177. * read_some function.
  178. *
  179. * @param s The stream from which the data is to be read. The type must support
  180. * the SyncReadStream concept.
  181. *
  182. * @param buffers One or more buffers into which the data will be read. The sum
  183. * of the buffer sizes indicates the maximum number of bytes to read from the
  184. * stream.
  185. *
  186. * @param completion_condition The function object to be called to determine
  187. * whether the read operation is complete. The signature of the function object
  188. * must be:
  189. * @code std::size_t completion_condition(
  190. * // Result of latest read_some operation.
  191. * const asio::error_code& error,
  192. *
  193. * // Number of bytes transferred so far.
  194. * std::size_t bytes_transferred
  195. * ); @endcode
  196. * A return value of 0 indicates that the read operation is complete. A non-zero
  197. * return value indicates the maximum number of bytes to be read on the next
  198. * call to the stream's read_some function.
  199. *
  200. * @param ec Set to indicate what error occurred, if any.
  201. *
  202. * @returns The number of bytes read. If an error occurs, returns the total
  203. * number of bytes successfully transferred prior to the error.
  204. */
  205. template <typename SyncReadStream, typename MutableBufferSequence,
  206. typename CompletionCondition>
  207. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  208. CompletionCondition completion_condition, asio::error_code& ec,
  209. typename enable_if<
  210. is_mutable_buffer_sequence<MutableBufferSequence>::value
  211. >::type* = 0);
  212. /// Attempt to read a certain amount of data from a stream before returning.
  213. /**
  214. * This function is used to read a certain number of bytes of data from a
  215. * stream. The call will block until one of the following conditions is true:
  216. *
  217. * @li The specified dynamic buffer sequence is full (that is, it has reached
  218. * maximum size).
  219. *
  220. * @li An error occurred.
  221. *
  222. * This operation is implemented in terms of zero or more calls to the stream's
  223. * read_some function.
  224. *
  225. * @param s The stream from which the data is to be read. The type must support
  226. * the SyncReadStream concept.
  227. *
  228. * @param buffers The dynamic buffer sequence into which the data will be read.
  229. *
  230. * @returns The number of bytes transferred.
  231. *
  232. * @throws asio::system_error Thrown on failure.
  233. *
  234. * @note This overload is equivalent to calling:
  235. * @code asio::read(
  236. * s, buffers,
  237. * asio::transfer_all()); @endcode
  238. */
  239. template <typename SyncReadStream, typename DynamicBufferSequence>
  240. std::size_t read(SyncReadStream& s,
  241. ASIO_MOVE_ARG(DynamicBufferSequence) buffers,
  242. typename enable_if<
  243. is_dynamic_buffer_sequence<DynamicBufferSequence>::value
  244. >::type* = 0);
  245. /// Attempt to read a certain amount of data from a stream before returning.
  246. /**
  247. * This function is used to read a certain number of bytes of data from a
  248. * stream. The call will block until one of the following conditions is true:
  249. *
  250. * @li The supplied buffer is full (that is, it has reached maximum size).
  251. *
  252. * @li An error occurred.
  253. *
  254. * This operation is implemented in terms of zero or more calls to the stream's
  255. * read_some function.
  256. *
  257. * @param s The stream from which the data is to be read. The type must support
  258. * the SyncReadStream concept.
  259. *
  260. * @param buffers The dynamic buffer sequence into which the data will be read.
  261. *
  262. * @param ec Set to indicate what error occurred, if any.
  263. *
  264. * @returns The number of bytes transferred.
  265. *
  266. * @note This overload is equivalent to calling:
  267. * @code asio::read(
  268. * s, buffers,
  269. * asio::transfer_all(), ec); @endcode
  270. */
  271. template <typename SyncReadStream, typename DynamicBufferSequence>
  272. std::size_t read(SyncReadStream& s,
  273. ASIO_MOVE_ARG(DynamicBufferSequence) buffers,
  274. asio::error_code& ec,
  275. typename enable_if<
  276. is_dynamic_buffer_sequence<DynamicBufferSequence>::value
  277. >::type* = 0);
  278. /// Attempt to read a certain amount of data from a stream before returning.
  279. /**
  280. * This function is used to read a certain number of bytes of data from a
  281. * stream. The call will block until one of the following conditions is true:
  282. *
  283. * @li The specified dynamic buffer sequence is full (that is, it has reached
  284. * maximum size).
  285. *
  286. * @li The completion_condition function object returns 0.
  287. *
  288. * This operation is implemented in terms of zero or more calls to the stream's
  289. * read_some function.
  290. *
  291. * @param s The stream from which the data is to be read. The type must support
  292. * the SyncReadStream concept.
  293. *
  294. * @param buffers The dynamic buffer sequence into which the data will be read.
  295. *
  296. * @param completion_condition The function object to be called to determine
  297. * whether the read operation is complete. The signature of the function object
  298. * must be:
  299. * @code std::size_t completion_condition(
  300. * // Result of latest read_some operation.
  301. * const asio::error_code& error,
  302. *
  303. * // Number of bytes transferred so far.
  304. * std::size_t bytes_transferred
  305. * ); @endcode
  306. * A return value of 0 indicates that the read operation is complete. A non-zero
  307. * return value indicates the maximum number of bytes to be read on the next
  308. * call to the stream's read_some function.
  309. *
  310. * @returns The number of bytes transferred.
  311. *
  312. * @throws asio::system_error Thrown on failure.
  313. */
  314. template <typename SyncReadStream, typename DynamicBufferSequence,
  315. typename CompletionCondition>
  316. std::size_t read(SyncReadStream& s,
  317. ASIO_MOVE_ARG(DynamicBufferSequence) buffers,
  318. CompletionCondition completion_condition,
  319. typename enable_if<
  320. is_dynamic_buffer_sequence<DynamicBufferSequence>::value
  321. >::type* = 0);
  322. /// Attempt to read a certain amount of data from a stream before returning.
  323. /**
  324. * This function is used to read a certain number of bytes of data from a
  325. * stream. The call will block until one of the following conditions is true:
  326. *
  327. * @li The specified dynamic buffer sequence is full (that is, it has reached
  328. * maximum size).
  329. *
  330. * @li The completion_condition function object returns 0.
  331. *
  332. * This operation is implemented in terms of zero or more calls to the stream's
  333. * read_some function.
  334. *
  335. * @param s The stream from which the data is to be read. The type must support
  336. * the SyncReadStream concept.
  337. *
  338. * @param buffers The dynamic buffer sequence into which the data will be read.
  339. *
  340. * @param completion_condition The function object to be called to determine
  341. * whether the read operation is complete. The signature of the function object
  342. * must be:
  343. * @code std::size_t completion_condition(
  344. * // Result of latest read_some operation.
  345. * const asio::error_code& error,
  346. *
  347. * // Number of bytes transferred so far.
  348. * std::size_t bytes_transferred
  349. * ); @endcode
  350. * A return value of 0 indicates that the read operation is complete. A non-zero
  351. * return value indicates the maximum number of bytes to be read on the next
  352. * call to the stream's read_some function.
  353. *
  354. * @param ec Set to indicate what error occurred, if any.
  355. *
  356. * @returns The number of bytes read. If an error occurs, returns the total
  357. * number of bytes successfully transferred prior to the error.
  358. */
  359. template <typename SyncReadStream, typename DynamicBufferSequence,
  360. typename CompletionCondition>
  361. std::size_t read(SyncReadStream& s,
  362. ASIO_MOVE_ARG(DynamicBufferSequence) buffers,
  363. CompletionCondition completion_condition, asio::error_code& ec,
  364. typename enable_if<
  365. is_dynamic_buffer_sequence<DynamicBufferSequence>::value
  366. >::type* = 0);
  367. #if !defined(ASIO_NO_IOSTREAM)
  368. /// Attempt to read a certain amount of data from a stream before returning.
  369. /**
  370. * This function is used to read a certain number of bytes of data from a
  371. * stream. The call will block until one of the following conditions is true:
  372. *
  373. * @li The supplied buffer is full (that is, it has reached maximum size).
  374. *
  375. * @li An error occurred.
  376. *
  377. * This operation is implemented in terms of zero or more calls to the stream's
  378. * read_some function.
  379. *
  380. * @param s The stream from which the data is to be read. The type must support
  381. * the SyncReadStream concept.
  382. *
  383. * @param b The basic_streambuf object into which the data will be read.
  384. *
  385. * @returns The number of bytes transferred.
  386. *
  387. * @throws asio::system_error Thrown on failure.
  388. *
  389. * @note This overload is equivalent to calling:
  390. * @code asio::read(
  391. * s, b,
  392. * asio::transfer_all()); @endcode
  393. */
  394. template <typename SyncReadStream, typename Allocator>
  395. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
  396. /// Attempt to read a certain amount of data from a stream before returning.
  397. /**
  398. * This function is used to read a certain number of bytes of data from a
  399. * stream. The call will block until one of the following conditions is true:
  400. *
  401. * @li The supplied buffer is full (that is, it has reached maximum size).
  402. *
  403. * @li An error occurred.
  404. *
  405. * This operation is implemented in terms of zero or more calls to the stream's
  406. * read_some function.
  407. *
  408. * @param s The stream from which the data is to be read. The type must support
  409. * the SyncReadStream concept.
  410. *
  411. * @param b The basic_streambuf object into which the data will be read.
  412. *
  413. * @param ec Set to indicate what error occurred, if any.
  414. *
  415. * @returns The number of bytes transferred.
  416. *
  417. * @note This overload is equivalent to calling:
  418. * @code asio::read(
  419. * s, b,
  420. * asio::transfer_all(), ec); @endcode
  421. */
  422. template <typename SyncReadStream, typename Allocator>
  423. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  424. asio::error_code& ec);
  425. /// Attempt to read a certain amount of data from a stream before returning.
  426. /**
  427. * This function is used to read a certain number of bytes of data from a
  428. * stream. The call will block until one of the following conditions is true:
  429. *
  430. * @li The supplied buffer is full (that is, it has reached maximum size).
  431. *
  432. * @li The completion_condition function object returns 0.
  433. *
  434. * This operation is implemented in terms of zero or more calls to the stream's
  435. * read_some function.
  436. *
  437. * @param s The stream from which the data is to be read. The type must support
  438. * the SyncReadStream concept.
  439. *
  440. * @param b The basic_streambuf object into which the data will be read.
  441. *
  442. * @param completion_condition The function object to be called to determine
  443. * whether the read operation is complete. The signature of the function object
  444. * must be:
  445. * @code std::size_t completion_condition(
  446. * // Result of latest read_some operation.
  447. * const asio::error_code& error,
  448. *
  449. * // Number of bytes transferred so far.
  450. * std::size_t bytes_transferred
  451. * ); @endcode
  452. * A return value of 0 indicates that the read operation is complete. A non-zero
  453. * return value indicates the maximum number of bytes to be read on the next
  454. * call to the stream's read_some function.
  455. *
  456. * @returns The number of bytes transferred.
  457. *
  458. * @throws asio::system_error Thrown on failure.
  459. */
  460. template <typename SyncReadStream, typename Allocator,
  461. typename CompletionCondition>
  462. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  463. CompletionCondition completion_condition);
  464. /// Attempt to read a certain amount of data from a stream before returning.
  465. /**
  466. * This function is used to read a certain number of bytes of data from a
  467. * stream. The call will block until one of the following conditions is true:
  468. *
  469. * @li The supplied buffer is full (that is, it has reached maximum size).
  470. *
  471. * @li The completion_condition function object returns 0.
  472. *
  473. * This operation is implemented in terms of zero or more calls to the stream's
  474. * read_some function.
  475. *
  476. * @param s The stream from which the data is to be read. The type must support
  477. * the SyncReadStream concept.
  478. *
  479. * @param b The basic_streambuf object into which the data will be read.
  480. *
  481. * @param completion_condition The function object to be called to determine
  482. * whether the read operation is complete. The signature of the function object
  483. * must be:
  484. * @code std::size_t completion_condition(
  485. * // Result of latest read_some operation.
  486. * const asio::error_code& error,
  487. *
  488. * // Number of bytes transferred so far.
  489. * std::size_t bytes_transferred
  490. * ); @endcode
  491. * A return value of 0 indicates that the read operation is complete. A non-zero
  492. * return value indicates the maximum number of bytes to be read on the next
  493. * call to the stream's read_some function.
  494. *
  495. * @param ec Set to indicate what error occurred, if any.
  496. *
  497. * @returns The number of bytes read. If an error occurs, returns the total
  498. * number of bytes successfully transferred prior to the error.
  499. */
  500. template <typename SyncReadStream, typename Allocator,
  501. typename CompletionCondition>
  502. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  503. CompletionCondition completion_condition, asio::error_code& ec);
  504. #endif // !defined(ASIO_NO_IOSTREAM)
  505. /*@}*/
  506. /**
  507. * @defgroup async_read asio::async_read
  508. *
  509. * @brief Start an asynchronous operation to read a certain amount of data from
  510. * a stream.
  511. */
  512. /*@{*/
  513. /// Start an asynchronous operation to read a certain amount of data from a
  514. /// stream.
  515. /**
  516. * This function is used to asynchronously read a certain number of bytes of
  517. * data from a stream. The function call always returns immediately. The
  518. * asynchronous operation will continue until one of the following conditions is
  519. * true:
  520. *
  521. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  522. * the sum of the buffer sizes.
  523. *
  524. * @li An error occurred.
  525. *
  526. * This operation is implemented in terms of zero or more calls to the stream's
  527. * async_read_some function, and is known as a <em>composed operation</em>. The
  528. * program must ensure that the stream performs no other read operations (such
  529. * as async_read, the stream's async_read_some function, or any other composed
  530. * operations that perform reads) until this operation completes.
  531. *
  532. * @param s The stream from which the data is to be read. The type must support
  533. * the AsyncReadStream concept.
  534. *
  535. * @param buffers One or more buffers into which the data will be read. The sum
  536. * of the buffer sizes indicates the maximum number of bytes to read from the
  537. * stream. Although the buffers object may be copied as necessary, ownership of
  538. * the underlying memory blocks is retained by the caller, which must guarantee
  539. * that they remain valid until the handler is called.
  540. *
  541. * @param handler The handler to be called when the read operation completes.
  542. * Copies will be made of the handler as required. The function signature of the
  543. * handler must be:
  544. * @code void handler(
  545. * const asio::error_code& error, // Result of operation.
  546. *
  547. * std::size_t bytes_transferred // Number of bytes copied into the
  548. * // buffers. If an error occurred,
  549. * // this will be the number of
  550. * // bytes successfully transferred
  551. * // prior to the error.
  552. * ); @endcode
  553. * Regardless of whether the asynchronous operation completes immediately or
  554. * not, the handler will not be invoked from within this function. Invocation of
  555. * the handler will be performed in a manner equivalent to using
  556. * asio::io_context::post().
  557. *
  558. * @par Example
  559. * To read into a single data buffer use the @ref buffer function as follows:
  560. * @code
  561. * asio::async_read(s, asio::buffer(data, size), handler);
  562. * @endcode
  563. * See the @ref buffer documentation for information on reading into multiple
  564. * buffers in one go, and how to use it with arrays, boost::array or
  565. * std::vector.
  566. *
  567. * @note This overload is equivalent to calling:
  568. * @code asio::async_read(
  569. * s, buffers,
  570. * asio::transfer_all(),
  571. * handler); @endcode
  572. */
  573. template <typename AsyncReadStream, typename MutableBufferSequence,
  574. typename ReadHandler>
  575. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  576. void (asio::error_code, std::size_t))
  577. async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
  578. ASIO_MOVE_ARG(ReadHandler) handler,
  579. typename enable_if<
  580. is_mutable_buffer_sequence<MutableBufferSequence>::value
  581. >::type* = 0);
  582. /// Start an asynchronous operation to read a certain amount of data from a
  583. /// stream.
  584. /**
  585. * This function is used to asynchronously read a certain number of bytes of
  586. * data from a stream. The function call always returns immediately. The
  587. * asynchronous operation will continue until one of the following conditions is
  588. * true:
  589. *
  590. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  591. * the sum of the buffer sizes.
  592. *
  593. * @li The completion_condition function object returns 0.
  594. *
  595. * @param s The stream from which the data is to be read. The type must support
  596. * the AsyncReadStream concept.
  597. *
  598. * @param buffers One or more buffers into which the data will be read. The sum
  599. * of the buffer sizes indicates the maximum number of bytes to read from the
  600. * stream. Although the buffers object may be copied as necessary, ownership of
  601. * the underlying memory blocks is retained by the caller, which must guarantee
  602. * that they remain valid until the handler is called.
  603. *
  604. * @param completion_condition The function object to be called to determine
  605. * whether the read operation is complete. The signature of the function object
  606. * must be:
  607. * @code std::size_t completion_condition(
  608. * // Result of latest async_read_some operation.
  609. * const asio::error_code& error,
  610. *
  611. * // Number of bytes transferred so far.
  612. * std::size_t bytes_transferred
  613. * ); @endcode
  614. * A return value of 0 indicates that the read operation is complete. A non-zero
  615. * return value indicates the maximum number of bytes to be read on the next
  616. * call to the stream's async_read_some function.
  617. *
  618. * @param handler The handler to be called when the read operation completes.
  619. * Copies will be made of the handler as required. The function signature of the
  620. * handler must be:
  621. * @code void handler(
  622. * const asio::error_code& error, // Result of operation.
  623. *
  624. * std::size_t bytes_transferred // Number of bytes copied into the
  625. * // buffers. If an error occurred,
  626. * // this will be the number of
  627. * // bytes successfully transferred
  628. * // prior to the error.
  629. * ); @endcode
  630. * Regardless of whether the asynchronous operation completes immediately or
  631. * not, the handler will not be invoked from within this function. Invocation of
  632. * the handler will be performed in a manner equivalent to using
  633. * asio::io_context::post().
  634. *
  635. * @par Example
  636. * To read into a single data buffer use the @ref buffer function as follows:
  637. * @code asio::async_read(s,
  638. * asio::buffer(data, size),
  639. * asio::transfer_at_least(32),
  640. * handler); @endcode
  641. * See the @ref buffer documentation for information on reading into multiple
  642. * buffers in one go, and how to use it with arrays, boost::array or
  643. * std::vector.
  644. */
  645. template <typename AsyncReadStream, typename MutableBufferSequence,
  646. typename CompletionCondition, typename ReadHandler>
  647. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  648. void (asio::error_code, std::size_t))
  649. async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
  650. CompletionCondition completion_condition,
  651. ASIO_MOVE_ARG(ReadHandler) handler,
  652. typename enable_if<
  653. is_mutable_buffer_sequence<MutableBufferSequence>::value
  654. >::type* = 0);
  655. /// Start an asynchronous operation to read a certain amount of data from a
  656. /// stream.
  657. /**
  658. * This function is used to asynchronously read a certain number of bytes of
  659. * data from a stream. The function call always returns immediately. The
  660. * asynchronous operation will continue until one of the following conditions is
  661. * true:
  662. *
  663. * @li The specified dynamic buffer sequence is full (that is, it has reached
  664. * maximum size).
  665. *
  666. * @li An error occurred.
  667. *
  668. * This operation is implemented in terms of zero or more calls to the stream's
  669. * async_read_some function, and is known as a <em>composed operation</em>. The
  670. * program must ensure that the stream performs no other read operations (such
  671. * as async_read, the stream's async_read_some function, or any other composed
  672. * operations that perform reads) until this operation completes.
  673. *
  674. * @param s The stream from which the data is to be read. The type must support
  675. * the AsyncReadStream concept.
  676. *
  677. * @param buffers The dynamic buffer sequence into which the data will be read.
  678. * Although the buffers object may be copied as necessary, ownership of the
  679. * underlying memory blocks is retained by the caller, which must guarantee
  680. * that they remain valid until the handler is called.
  681. *
  682. * @param handler The handler to be called when the read operation completes.
  683. * Copies will be made of the handler as required. The function signature of the
  684. * handler must be:
  685. * @code void handler(
  686. * const asio::error_code& error, // Result of operation.
  687. *
  688. * std::size_t bytes_transferred // Number of bytes copied into the
  689. * // buffers. If an error occurred,
  690. * // this will be the number of
  691. * // bytes successfully transferred
  692. * // prior to the error.
  693. * ); @endcode
  694. * Regardless of whether the asynchronous operation completes immediately or
  695. * not, the handler will not be invoked from within this function. Invocation of
  696. * the handler will be performed in a manner equivalent to using
  697. * asio::io_context::post().
  698. *
  699. * @note This overload is equivalent to calling:
  700. * @code asio::async_read(
  701. * s, buffers,
  702. * asio::transfer_all(),
  703. * handler); @endcode
  704. */
  705. template <typename AsyncReadStream,
  706. typename DynamicBufferSequence, typename ReadHandler>
  707. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  708. void (asio::error_code, std::size_t))
  709. async_read(AsyncReadStream& s,
  710. ASIO_MOVE_ARG(DynamicBufferSequence) buffers,
  711. ASIO_MOVE_ARG(ReadHandler) handler,
  712. typename enable_if<
  713. is_dynamic_buffer_sequence<DynamicBufferSequence>::value
  714. >::type* = 0);
  715. /// Start an asynchronous operation to read a certain amount of data from a
  716. /// stream.
  717. /**
  718. * This function is used to asynchronously read a certain number of bytes of
  719. * data from a stream. The function call always returns immediately. The
  720. * asynchronous operation will continue until one of the following conditions is
  721. * true:
  722. *
  723. * @li The specified dynamic buffer sequence is full (that is, it has reached
  724. * maximum size).
  725. *
  726. * @li The completion_condition function object returns 0.
  727. *
  728. * This operation is implemented in terms of zero or more calls to the stream's
  729. * async_read_some function, and is known as a <em>composed operation</em>. The
  730. * program must ensure that the stream performs no other read operations (such
  731. * as async_read, the stream's async_read_some function, or any other composed
  732. * operations that perform reads) until this operation completes.
  733. *
  734. * @param s The stream from which the data is to be read. The type must support
  735. * the AsyncReadStream concept.
  736. *
  737. * @param buffers The dynamic buffer sequence into which the data will be read.
  738. * Although the buffers object may be copied as necessary, ownership of the
  739. * underlying memory blocks is retained by the caller, which must guarantee
  740. * that they remain valid until the handler is called.
  741. *
  742. * @param completion_condition The function object to be called to determine
  743. * whether the read operation is complete. The signature of the function object
  744. * must be:
  745. * @code std::size_t completion_condition(
  746. * // Result of latest async_read_some operation.
  747. * const asio::error_code& error,
  748. *
  749. * // Number of bytes transferred so far.
  750. * std::size_t bytes_transferred
  751. * ); @endcode
  752. * A return value of 0 indicates that the read operation is complete. A non-zero
  753. * return value indicates the maximum number of bytes to be read on the next
  754. * call to the stream's async_read_some function.
  755. *
  756. * @param handler The handler to be called when the read operation completes.
  757. * Copies will be made of the handler as required. The function signature of the
  758. * handler must be:
  759. * @code void handler(
  760. * const asio::error_code& error, // Result of operation.
  761. *
  762. * std::size_t bytes_transferred // Number of bytes copied into the
  763. * // buffers. If an error occurred,
  764. * // this will be the number of
  765. * // bytes successfully transferred
  766. * // prior to the error.
  767. * ); @endcode
  768. * Regardless of whether the asynchronous operation completes immediately or
  769. * not, the handler will not be invoked from within this function. Invocation of
  770. * the handler will be performed in a manner equivalent to using
  771. * asio::io_context::post().
  772. */
  773. template <typename AsyncReadStream, typename DynamicBufferSequence,
  774. typename CompletionCondition, typename ReadHandler>
  775. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  776. void (asio::error_code, std::size_t))
  777. async_read(AsyncReadStream& s,
  778. ASIO_MOVE_ARG(DynamicBufferSequence) buffers,
  779. CompletionCondition completion_condition,
  780. ASIO_MOVE_ARG(ReadHandler) handler,
  781. typename enable_if<
  782. is_dynamic_buffer_sequence<DynamicBufferSequence>::value
  783. >::type* = 0);
  784. #if !defined(ASIO_NO_IOSTREAM)
  785. /// Start an asynchronous operation to read a certain amount of data from a
  786. /// stream.
  787. /**
  788. * This function is used to asynchronously read a certain number of bytes of
  789. * data from a stream. The function call always returns immediately. The
  790. * asynchronous operation will continue until one of the following conditions is
  791. * true:
  792. *
  793. * @li The supplied buffer is full (that is, it has reached maximum size).
  794. *
  795. * @li An error occurred.
  796. *
  797. * This operation is implemented in terms of zero or more calls to the stream's
  798. * async_read_some function, and is known as a <em>composed operation</em>. The
  799. * program must ensure that the stream performs no other read operations (such
  800. * as async_read, the stream's async_read_some function, or any other composed
  801. * operations that perform reads) until this operation completes.
  802. *
  803. * @param s The stream from which the data is to be read. The type must support
  804. * the AsyncReadStream concept.
  805. *
  806. * @param b A basic_streambuf object into which the data will be read. Ownership
  807. * of the streambuf is retained by the caller, which must guarantee that it
  808. * remains valid until the handler is called.
  809. *
  810. * @param handler The handler to be called when the read operation completes.
  811. * Copies will be made of the handler as required. The function signature of the
  812. * handler must be:
  813. * @code void handler(
  814. * const asio::error_code& error, // Result of operation.
  815. *
  816. * std::size_t bytes_transferred // Number of bytes copied into the
  817. * // buffers. If an error occurred,
  818. * // this will be the number of
  819. * // bytes successfully transferred
  820. * // prior to the error.
  821. * ); @endcode
  822. * Regardless of whether the asynchronous operation completes immediately or
  823. * not, the handler will not be invoked from within this function. Invocation of
  824. * the handler will be performed in a manner equivalent to using
  825. * asio::io_context::post().
  826. *
  827. * @note This overload is equivalent to calling:
  828. * @code asio::async_read(
  829. * s, b,
  830. * asio::transfer_all(),
  831. * handler); @endcode
  832. */
  833. template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
  834. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  835. void (asio::error_code, std::size_t))
  836. async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
  837. ASIO_MOVE_ARG(ReadHandler) handler);
  838. /// Start an asynchronous operation to read a certain amount of data from a
  839. /// stream.
  840. /**
  841. * This function is used to asynchronously read a certain number of bytes of
  842. * data from a stream. The function call always returns immediately. The
  843. * asynchronous operation will continue until one of the following conditions is
  844. * true:
  845. *
  846. * @li The supplied buffer is full (that is, it has reached maximum size).
  847. *
  848. * @li The completion_condition function object returns 0.
  849. *
  850. * This operation is implemented in terms of zero or more calls to the stream's
  851. * async_read_some function, and is known as a <em>composed operation</em>. The
  852. * program must ensure that the stream performs no other read operations (such
  853. * as async_read, the stream's async_read_some function, or any other composed
  854. * operations that perform reads) until this operation completes.
  855. *
  856. * @param s The stream from which the data is to be read. The type must support
  857. * the AsyncReadStream concept.
  858. *
  859. * @param b A basic_streambuf object into which the data will be read. Ownership
  860. * of the streambuf is retained by the caller, which must guarantee that it
  861. * remains valid until the handler is called.
  862. *
  863. * @param completion_condition The function object to be called to determine
  864. * whether the read operation is complete. The signature of the function object
  865. * must be:
  866. * @code std::size_t completion_condition(
  867. * // Result of latest async_read_some operation.
  868. * const asio::error_code& error,
  869. *
  870. * // Number of bytes transferred so far.
  871. * std::size_t bytes_transferred
  872. * ); @endcode
  873. * A return value of 0 indicates that the read operation is complete. A non-zero
  874. * return value indicates the maximum number of bytes to be read on the next
  875. * call to the stream's async_read_some function.
  876. *
  877. * @param handler The handler to be called when the read operation completes.
  878. * Copies will be made of the handler as required. The function signature of the
  879. * handler must be:
  880. * @code void handler(
  881. * const asio::error_code& error, // Result of operation.
  882. *
  883. * std::size_t bytes_transferred // Number of bytes copied into the
  884. * // buffers. If an error occurred,
  885. * // this will be the number of
  886. * // bytes successfully transferred
  887. * // prior to the error.
  888. * ); @endcode
  889. * Regardless of whether the asynchronous operation completes immediately or
  890. * not, the handler will not be invoked from within this function. Invocation of
  891. * the handler will be performed in a manner equivalent to using
  892. * asio::io_context::post().
  893. */
  894. template <typename AsyncReadStream, typename Allocator,
  895. typename CompletionCondition, typename ReadHandler>
  896. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  897. void (asio::error_code, std::size_t))
  898. async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
  899. CompletionCondition completion_condition,
  900. ASIO_MOVE_ARG(ReadHandler) handler);
  901. #endif // !defined(ASIO_NO_IOSTREAM)
  902. /*@}*/
  903. } // namespace asio
  904. #include "asio/detail/pop_options.hpp"
  905. #include "asio/impl/read.hpp"
  906. #endif // ASIO_READ_HPP