read_at.hpp 29 KB

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