read_at.hpp 26 KB

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