read_at.hpp 31 KB

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