read.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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/error.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. /**
  23. * @defgroup read asio::read
  24. *
  25. * @brief Attempt to read a certain amount of data from a stream before
  26. * returning.
  27. */
  28. /*@{*/
  29. /// Attempt to read a certain amount of data from a stream before returning.
  30. /**
  31. * This function is used to read a certain number of bytes of data from a
  32. * stream. The call will block until one of the following conditions is true:
  33. *
  34. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  35. * the sum of the buffer sizes.
  36. *
  37. * @li An error occurred.
  38. *
  39. * This operation is implemented in terms of zero or more calls to the stream's
  40. * read_some function.
  41. *
  42. * @param s The stream from which the data is to be read. The type must support
  43. * the SyncReadStream concept.
  44. *
  45. * @param buffers One or more buffers into which the data will be read. The sum
  46. * of the buffer sizes indicates the maximum number of bytes to read from the
  47. * stream.
  48. *
  49. * @returns The number of bytes transferred.
  50. *
  51. * @throws asio::system_error Thrown on failure.
  52. *
  53. * @par Example
  54. * To read into a single data buffer use the @ref buffer function as follows:
  55. * @code asio::read(s, asio::buffer(data, size)); @endcode
  56. * See the @ref buffer documentation for information on reading into multiple
  57. * buffers in one go, and how to use it with arrays, boost::array or
  58. * std::vector.
  59. *
  60. * @note This overload is equivalent to calling:
  61. * @code asio::read(
  62. * s, buffers,
  63. * asio::transfer_all()); @endcode
  64. */
  65. template <typename SyncReadStream, typename MutableBufferSequence>
  66. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers);
  67. /// Attempt to read a certain amount of data from a stream before returning.
  68. /**
  69. * This function is used to read a certain number of bytes of data from a
  70. * stream. The call will block until one of the following conditions is true:
  71. *
  72. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  73. * the sum of the buffer sizes.
  74. *
  75. * @li An error occurred.
  76. *
  77. * This operation is implemented in terms of zero or more calls to the stream's
  78. * read_some function.
  79. *
  80. * @param s The stream from which the data is to be read. The type must support
  81. * the SyncReadStream concept.
  82. *
  83. * @param buffers One or more buffers into which the data will be read. The sum
  84. * of the buffer sizes indicates the maximum number of bytes to read from the
  85. * stream.
  86. *
  87. * @param ec Set to indicate what error occurred, if any.
  88. *
  89. * @returns The number of bytes transferred.
  90. *
  91. * @par Example
  92. * To read into a single data buffer use the @ref buffer function as follows:
  93. * @code asio::read(s, asio::buffer(data, size), ec); @endcode
  94. * See the @ref buffer documentation for information on reading into multiple
  95. * buffers in one go, and how to use it with arrays, boost::array or
  96. * std::vector.
  97. *
  98. * @note This overload is equivalent to calling:
  99. * @code asio::read(
  100. * s, buffers,
  101. * asio::transfer_all(), ec); @endcode
  102. */
  103. template <typename SyncReadStream, typename MutableBufferSequence>
  104. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  105. asio::error_code& ec);
  106. /// Attempt to read a certain amount of data from a stream before returning.
  107. /**
  108. * This function is used to read a certain number of bytes of data from a
  109. * stream. The call will block until one of the following conditions is true:
  110. *
  111. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  112. * the sum of the buffer sizes.
  113. *
  114. * @li The completion_condition function object returns 0.
  115. *
  116. * This operation is implemented in terms of zero or more calls to the stream's
  117. * read_some function.
  118. *
  119. * @param s The stream from which the data is to be read. The type must support
  120. * the SyncReadStream concept.
  121. *
  122. * @param buffers One or more buffers into which the data will be read. The sum
  123. * of the buffer sizes indicates the maximum number of bytes to read from the
  124. * stream.
  125. *
  126. * @param completion_condition The function object to be called to determine
  127. * whether the read operation is complete. The signature of the function object
  128. * must be:
  129. * @code std::size_t completion_condition(
  130. * // Result of latest read_some operation.
  131. * const asio::error_code& error,
  132. *
  133. * // Number of bytes transferred so far.
  134. * std::size_t bytes_transferred
  135. * ); @endcode
  136. * A return value of 0 indicates that the read operation is complete. A non-zero
  137. * return value indicates the maximum number of bytes to be read on the next
  138. * call to the stream's read_some function.
  139. *
  140. * @returns The number of bytes transferred.
  141. *
  142. * @throws asio::system_error Thrown on failure.
  143. *
  144. * @par Example
  145. * To read into a single data buffer use the @ref buffer function as follows:
  146. * @code asio::read(s, asio::buffer(data, size),
  147. * asio::transfer_at_least(32)); @endcode
  148. * See the @ref buffer documentation for information on reading into multiple
  149. * buffers in one go, and how to use it with arrays, boost::array or
  150. * std::vector.
  151. */
  152. template <typename SyncReadStream, typename MutableBufferSequence,
  153. typename CompletionCondition>
  154. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  155. CompletionCondition completion_condition);
  156. /// Attempt to read a certain amount of data from a stream before returning.
  157. /**
  158. * This function is used to read a certain number of bytes of data from a
  159. * stream. The call will block until one of the following conditions is true:
  160. *
  161. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  162. * the sum of the buffer sizes.
  163. *
  164. * @li The completion_condition function object returns 0.
  165. *
  166. * This operation is implemented in terms of zero or more calls to the stream's
  167. * read_some function.
  168. *
  169. * @param s The stream from which the data is to be read. The type must support
  170. * the SyncReadStream concept.
  171. *
  172. * @param buffers One or more buffers into which the data will be read. The sum
  173. * of the buffer sizes indicates the maximum number of bytes to read from the
  174. * stream.
  175. *
  176. * @param completion_condition The function object to be called to determine
  177. * whether the read operation is complete. The signature of the function object
  178. * must be:
  179. * @code std::size_t completion_condition(
  180. * // Result of latest read_some operation.
  181. * const asio::error_code& error,
  182. *
  183. * // Number of bytes transferred so far.
  184. * std::size_t bytes_transferred
  185. * ); @endcode
  186. * A return value of 0 indicates that the read operation is complete. A non-zero
  187. * return value indicates the maximum number of bytes to be read on the next
  188. * call to the stream's read_some function.
  189. *
  190. * @param ec Set to indicate what error occurred, if any.
  191. *
  192. * @returns The number of bytes read. If an error occurs, returns the total
  193. * number of bytes successfully transferred prior to the error.
  194. */
  195. template <typename SyncReadStream, typename MutableBufferSequence,
  196. typename CompletionCondition>
  197. std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
  198. CompletionCondition completion_condition, asio::error_code& ec);
  199. #if !defined(ASIO_NO_IOSTREAM)
  200. /// Attempt to read a certain amount of data from a stream before returning.
  201. /**
  202. * This function is used to read a certain number of bytes of data from a
  203. * stream. The call will block until one of the following conditions is true:
  204. *
  205. * @li The supplied buffer is full (that is, it has reached maximum size).
  206. *
  207. * @li An error occurred.
  208. *
  209. * This operation is implemented in terms of zero or more calls to the stream's
  210. * read_some function.
  211. *
  212. * @param s The stream from which the data is to be read. The type must support
  213. * the SyncReadStream concept.
  214. *
  215. * @param b The basic_streambuf object into which the data will be read.
  216. *
  217. * @returns The number of bytes transferred.
  218. *
  219. * @throws asio::system_error Thrown on failure.
  220. *
  221. * @note This overload is equivalent to calling:
  222. * @code asio::read(
  223. * s, b,
  224. * asio::transfer_all()); @endcode
  225. */
  226. template <typename SyncReadStream, typename Allocator>
  227. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);
  228. /// Attempt to read a certain amount of data from a stream before returning.
  229. /**
  230. * This function is used to read a certain number of bytes of data from a
  231. * stream. The call will block until one of the following conditions is true:
  232. *
  233. * @li The supplied buffer is full (that is, it has reached maximum size).
  234. *
  235. * @li An error occurred.
  236. *
  237. * This operation is implemented in terms of zero or more calls to the stream's
  238. * read_some function.
  239. *
  240. * @param s The stream from which the data is to be read. The type must support
  241. * the SyncReadStream concept.
  242. *
  243. * @param b The basic_streambuf object into which the data will be read.
  244. *
  245. * @param ec Set to indicate what error occurred, if any.
  246. *
  247. * @returns The number of bytes transferred.
  248. *
  249. * @note This overload is equivalent to calling:
  250. * @code asio::read(
  251. * s, b,
  252. * asio::transfer_all(), ec); @endcode
  253. */
  254. template <typename SyncReadStream, typename Allocator>
  255. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  256. asio::error_code& ec);
  257. /// Attempt to read a certain amount of data from a stream before returning.
  258. /**
  259. * This function is used to read a certain number of bytes of data from a
  260. * stream. The call will block until one of the following conditions is true:
  261. *
  262. * @li The supplied buffer is full (that is, it has reached maximum size).
  263. *
  264. * @li The completion_condition function object returns 0.
  265. *
  266. * This operation is implemented in terms of zero or more calls to the stream's
  267. * read_some function.
  268. *
  269. * @param s The stream from which the data is to be read. The type must support
  270. * the SyncReadStream concept.
  271. *
  272. * @param b The basic_streambuf object into which the data will be read.
  273. *
  274. * @param completion_condition The function object to be called to determine
  275. * whether the read operation is complete. The signature of the function object
  276. * must be:
  277. * @code std::size_t completion_condition(
  278. * // Result of latest read_some operation.
  279. * const asio::error_code& error,
  280. *
  281. * // Number of bytes transferred so far.
  282. * std::size_t bytes_transferred
  283. * ); @endcode
  284. * A return value of 0 indicates that the read operation is complete. A non-zero
  285. * return value indicates the maximum number of bytes to be read on the next
  286. * call to the stream's read_some function.
  287. *
  288. * @returns The number of bytes transferred.
  289. *
  290. * @throws asio::system_error Thrown on failure.
  291. */
  292. template <typename SyncReadStream, typename Allocator,
  293. typename CompletionCondition>
  294. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  295. CompletionCondition completion_condition);
  296. /// Attempt to read a certain amount of data from a stream before returning.
  297. /**
  298. * This function is used to read a certain number of bytes of data from a
  299. * stream. The call will block until one of the following conditions is true:
  300. *
  301. * @li The supplied buffer is full (that is, it has reached maximum size).
  302. *
  303. * @li The completion_condition function object returns 0.
  304. *
  305. * This operation is implemented in terms of zero or more calls to the stream's
  306. * read_some function.
  307. *
  308. * @param s The stream from which the data is to be read. The type must support
  309. * the SyncReadStream concept.
  310. *
  311. * @param b The basic_streambuf object into which the data will be read.
  312. *
  313. * @param completion_condition The function object to be called to determine
  314. * whether the read operation is complete. The signature of the function object
  315. * must be:
  316. * @code std::size_t completion_condition(
  317. * // Result of latest read_some operation.
  318. * const asio::error_code& error,
  319. *
  320. * // Number of bytes transferred so far.
  321. * std::size_t bytes_transferred
  322. * ); @endcode
  323. * A return value of 0 indicates that the read operation is complete. A non-zero
  324. * return value indicates the maximum number of bytes to be read on the next
  325. * call to the stream's read_some function.
  326. *
  327. * @param ec Set to indicate what error occurred, if any.
  328. *
  329. * @returns The number of bytes read. If an error occurs, returns the total
  330. * number of bytes successfully transferred prior to the error.
  331. */
  332. template <typename SyncReadStream, typename Allocator,
  333. typename CompletionCondition>
  334. std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
  335. CompletionCondition completion_condition, asio::error_code& ec);
  336. #endif // !defined(ASIO_NO_IOSTREAM)
  337. /*@}*/
  338. /**
  339. * @defgroup async_read asio::async_read
  340. *
  341. * @brief Start an asynchronous operation to read a certain amount of data from
  342. * a stream.
  343. */
  344. /*@{*/
  345. /// Start an asynchronous operation to read a certain amount of data from a
  346. /// stream.
  347. /**
  348. * This function is used to asynchronously read a certain number of bytes of
  349. * data from a stream. The function call always returns immediately. The
  350. * asynchronous operation will continue until one of the following conditions is
  351. * true:
  352. *
  353. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  354. * the sum of the buffer sizes.
  355. *
  356. * @li An error occurred.
  357. *
  358. * This operation is implemented in terms of zero or more calls to the stream's
  359. * async_read_some function, and is known as a <em>composed operation</em>. The
  360. * program must ensure that the stream performs no other read operations (such
  361. * as async_read, the stream's async_read_some function, or any other composed
  362. * operations that perform reads) until this operation completes.
  363. *
  364. * @param s The stream from which the data is to be read. The type must support
  365. * the AsyncReadStream concept.
  366. *
  367. * @param buffers One or more buffers into which the data will be read. The sum
  368. * of the buffer sizes indicates the maximum number of bytes to read from the
  369. * stream. Although the buffers object may be copied as necessary, ownership of
  370. * the underlying memory blocks is retained by the caller, which must guarantee
  371. * that they remain valid until the handler is called.
  372. *
  373. * @param handler The handler to be called when the read operation completes.
  374. * Copies will be made of the handler as required. The function signature of the
  375. * handler must be:
  376. * @code void handler(
  377. * const asio::error_code& error, // Result of operation.
  378. *
  379. * std::size_t bytes_transferred // Number of bytes copied into the
  380. * // buffers. If an error occurred,
  381. * // this will be the number of
  382. * // bytes successfully transferred
  383. * // prior to the error.
  384. * ); @endcode
  385. * Regardless of whether the asynchronous operation completes immediately or
  386. * not, the handler will not be invoked from within this function. Invocation of
  387. * the handler will be performed in a manner equivalent to using
  388. * asio::io_service::post().
  389. *
  390. * @par Example
  391. * To read into a single data buffer use the @ref buffer function as follows:
  392. * @code
  393. * asio::async_read(s, asio::buffer(data, size), handler);
  394. * @endcode
  395. * See the @ref buffer documentation for information on reading into multiple
  396. * buffers in one go, and how to use it with arrays, boost::array or
  397. * std::vector.
  398. *
  399. * @note This overload is equivalent to calling:
  400. * @code asio::async_read(
  401. * s, buffers,
  402. * asio::transfer_all(),
  403. * handler); @endcode
  404. */
  405. template <typename AsyncReadStream, typename MutableBufferSequence,
  406. typename ReadHandler>
  407. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  408. void (asio::error_code, std::size_t))
  409. async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
  410. ASIO_MOVE_ARG(ReadHandler) handler);
  411. /// Start an asynchronous operation to read a certain amount of data from a
  412. /// stream.
  413. /**
  414. * This function is used to asynchronously read a certain number of bytes of
  415. * data from a stream. The function call always returns immediately. The
  416. * asynchronous operation will continue until one of the following conditions is
  417. * true:
  418. *
  419. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  420. * the sum of the buffer sizes.
  421. *
  422. * @li The completion_condition function object returns 0.
  423. *
  424. * @param s The stream from which the data is to be read. The type must support
  425. * the AsyncReadStream concept.
  426. *
  427. * @param buffers One or more buffers into which the data will be read. The sum
  428. * of the buffer sizes indicates the maximum number of bytes to read from the
  429. * stream. Although the buffers object may be copied as necessary, ownership of
  430. * the underlying memory blocks is retained by the caller, which must guarantee
  431. * that they remain valid until the handler is called.
  432. *
  433. * @param completion_condition The function object to be called to determine
  434. * whether the read operation is complete. The signature of the function object
  435. * must be:
  436. * @code std::size_t completion_condition(
  437. * // Result of latest async_read_some operation.
  438. * const asio::error_code& error,
  439. *
  440. * // Number of bytes transferred so far.
  441. * std::size_t bytes_transferred
  442. * ); @endcode
  443. * A return value of 0 indicates that the read operation is complete. A non-zero
  444. * return value indicates the maximum number of bytes to be read on the next
  445. * call to the stream's async_read_some function.
  446. *
  447. * @param handler The handler to be called when the read operation completes.
  448. * Copies will be made of the handler as required. The function signature of the
  449. * handler must be:
  450. * @code void handler(
  451. * const asio::error_code& error, // Result of operation.
  452. *
  453. * std::size_t bytes_transferred // Number of bytes copied into the
  454. * // buffers. If an error occurred,
  455. * // this will be the number of
  456. * // bytes successfully transferred
  457. * // prior to the error.
  458. * ); @endcode
  459. * Regardless of whether the asynchronous operation completes immediately or
  460. * not, the handler will not be invoked from within this function. Invocation of
  461. * the handler will be performed in a manner equivalent to using
  462. * asio::io_service::post().
  463. *
  464. * @par Example
  465. * To read into a single data buffer use the @ref buffer function as follows:
  466. * @code asio::async_read(s,
  467. * asio::buffer(data, size),
  468. * asio::transfer_at_least(32),
  469. * handler); @endcode
  470. * See the @ref buffer documentation for information on reading into multiple
  471. * buffers in one go, and how to use it with arrays, boost::array or
  472. * std::vector.
  473. */
  474. template <typename AsyncReadStream, typename MutableBufferSequence,
  475. typename CompletionCondition, typename ReadHandler>
  476. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  477. void (asio::error_code, std::size_t))
  478. async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
  479. CompletionCondition completion_condition,
  480. ASIO_MOVE_ARG(ReadHandler) handler);
  481. #if !defined(ASIO_NO_IOSTREAM)
  482. /// Start an asynchronous operation to read a certain amount of data from a
  483. /// stream.
  484. /**
  485. * This function is used to asynchronously read a certain number of bytes of
  486. * data from a stream. The function call always returns immediately. The
  487. * asynchronous operation will continue until one of the following conditions is
  488. * true:
  489. *
  490. * @li The supplied buffer is full (that is, it has reached maximum size).
  491. *
  492. * @li An error occurred.
  493. *
  494. * This operation is implemented in terms of zero or more calls to the stream's
  495. * async_read_some function, and is known as a <em>composed operation</em>. The
  496. * program must ensure that the stream performs no other read operations (such
  497. * as async_read, the stream's async_read_some function, or any other composed
  498. * operations that perform reads) until this operation completes.
  499. *
  500. * @param s The stream from which the data is to be read. The type must support
  501. * the AsyncReadStream concept.
  502. *
  503. * @param b A basic_streambuf object into which the data will be read. Ownership
  504. * of the streambuf is retained by the caller, which must guarantee that it
  505. * remains valid until the handler is called.
  506. *
  507. * @param handler The handler to be called when the read operation completes.
  508. * Copies will be made of the handler as required. The function signature of the
  509. * handler must be:
  510. * @code void handler(
  511. * const asio::error_code& error, // Result of operation.
  512. *
  513. * std::size_t bytes_transferred // Number of bytes copied into the
  514. * // buffers. If an error occurred,
  515. * // this will be the number of
  516. * // bytes successfully transferred
  517. * // prior to the error.
  518. * ); @endcode
  519. * Regardless of whether the asynchronous operation completes immediately or
  520. * not, the handler will not be invoked from within this function. Invocation of
  521. * the handler will be performed in a manner equivalent to using
  522. * asio::io_service::post().
  523. *
  524. * @note This overload is equivalent to calling:
  525. * @code asio::async_read(
  526. * s, b,
  527. * asio::transfer_all(),
  528. * handler); @endcode
  529. */
  530. template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
  531. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  532. void (asio::error_code, std::size_t))
  533. async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
  534. ASIO_MOVE_ARG(ReadHandler) handler);
  535. /// Start an asynchronous operation to read a certain amount of data from a
  536. /// stream.
  537. /**
  538. * This function is used to asynchronously read a certain number of bytes of
  539. * data from a stream. The function call always returns immediately. The
  540. * asynchronous operation will continue until one of the following conditions is
  541. * true:
  542. *
  543. * @li The supplied buffer is full (that is, it has reached maximum size).
  544. *
  545. * @li The completion_condition function object returns 0.
  546. *
  547. * This operation is implemented in terms of zero or more calls to the stream's
  548. * async_read_some function, and is known as a <em>composed operation</em>. The
  549. * program must ensure that the stream performs no other read operations (such
  550. * as async_read, the stream's async_read_some function, or any other composed
  551. * operations that perform reads) until this operation completes.
  552. *
  553. * @param s The stream from which the data is to be read. The type must support
  554. * the AsyncReadStream concept.
  555. *
  556. * @param b A basic_streambuf object into which the data will be read. Ownership
  557. * of the streambuf is retained by the caller, which must guarantee that it
  558. * remains valid until the handler is called.
  559. *
  560. * @param completion_condition The function object to be called to determine
  561. * whether the read operation is complete. The signature of the function object
  562. * must be:
  563. * @code std::size_t completion_condition(
  564. * // Result of latest async_read_some operation.
  565. * const asio::error_code& error,
  566. *
  567. * // Number of bytes transferred so far.
  568. * std::size_t bytes_transferred
  569. * ); @endcode
  570. * A return value of 0 indicates that the read operation is complete. A non-zero
  571. * return value indicates the maximum number of bytes to be read on the next
  572. * call to the stream's async_read_some function.
  573. *
  574. * @param handler The handler to be called when the read operation completes.
  575. * Copies will be made of the handler as required. The function signature of the
  576. * handler must be:
  577. * @code void handler(
  578. * const asio::error_code& error, // Result of operation.
  579. *
  580. * std::size_t bytes_transferred // Number of bytes copied into the
  581. * // buffers. If an error occurred,
  582. * // this will be the number of
  583. * // bytes successfully transferred
  584. * // prior to the error.
  585. * ); @endcode
  586. * Regardless of whether the asynchronous operation completes immediately or
  587. * not, the handler will not be invoked from within this function. Invocation of
  588. * the handler will be performed in a manner equivalent to using
  589. * asio::io_service::post().
  590. */
  591. template <typename AsyncReadStream, typename Allocator,
  592. typename CompletionCondition, typename ReadHandler>
  593. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  594. void (asio::error_code, std::size_t))
  595. async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
  596. CompletionCondition completion_condition,
  597. ASIO_MOVE_ARG(ReadHandler) handler);
  598. #endif // !defined(ASIO_NO_IOSTREAM)
  599. /*@}*/
  600. } // namespace asio
  601. #include "asio/detail/pop_options.hpp"
  602. #include "asio/impl/read.hpp"
  603. #endif // ASIO_READ_HPP