read_at.hpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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 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 The @c read_at function is a composed operation that reads a certain
  30. * amount of data at the specified offset 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 The @c async_read_at function is a composed asynchronous operation
  381. * that reads a certain amount of data at 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. It is an
  389. * initiating function for an @ref asynchronous_operation, and always returns
  390. * immediately. The asynchronous operation will continue until one of the
  391. * following conditions is true:
  392. *
  393. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  394. * the sum of the buffer sizes.
  395. *
  396. * @li An error occurred.
  397. *
  398. * This operation is implemented in terms of zero or more calls to the device's
  399. * async_read_some_at function.
  400. *
  401. * @param d The device from which the data is to be read. The type must support
  402. * the AsyncRandomAccessReadDevice concept.
  403. *
  404. * @param offset The offset at which the data will be read.
  405. *
  406. * @param buffers One or more buffers into which the data will be read. The sum
  407. * of the buffer sizes indicates the maximum number of bytes to read from the
  408. * device. Although the buffers object may be copied as necessary, ownership of
  409. * the underlying memory blocks is retained by the caller, which must guarantee
  410. * that they remain valid until the completion handler is called.
  411. *
  412. * @param token The @ref completion_token that will be used to produce a
  413. * completion handler, which will be called when the read completes.
  414. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  415. * @ref yield_context, or a function object with the correct completion
  416. * signature. The function signature of the completion handler must be:
  417. * @code void handler(
  418. * // Result of operation.
  419. * const boost::system::error_code& error,
  420. *
  421. * // Number of bytes copied into the buffers. If an error
  422. * // occurred, this will be the number of bytes successfully
  423. * // transferred prior to the error.
  424. * std::size_t bytes_transferred
  425. * ); @endcode
  426. * Regardless of whether the asynchronous operation completes immediately or
  427. * not, the completion handler will not be invoked from within this function.
  428. * On immediate completion, invocation of the handler will be performed in a
  429. * manner equivalent to using boost::asio::post().
  430. *
  431. * @par Completion Signature
  432. * @code void(boost::system::error_code, std::size_t) @endcode
  433. *
  434. * @par Example
  435. * To read into a single data buffer use the @ref buffer function as follows:
  436. * @code
  437. * boost::asio::async_read_at(d, 42, boost::asio::buffer(data, size), handler);
  438. * @endcode
  439. * See the @ref buffer documentation for information on reading into multiple
  440. * buffers in one go, and how to use it with arrays, boost::array or
  441. * std::vector.
  442. *
  443. * @note This overload is equivalent to calling:
  444. * @code boost::asio::async_read_at(
  445. * d, 42, buffers,
  446. * boost::asio::transfer_all(),
  447. * handler); @endcode
  448. *
  449. * @par Per-Operation Cancellation
  450. * This asynchronous operation supports cancellation for the following
  451. * boost::asio::cancellation_type values:
  452. *
  453. * @li @c cancellation_type::terminal
  454. *
  455. * @li @c cancellation_type::partial
  456. *
  457. * if they are also supported by the @c AsyncRandomAccessReadDevice type's
  458. * async_read_some_at operation.
  459. */
  460. template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
  461. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  462. std::size_t)) ReadToken
  463. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  464. typename AsyncRandomAccessReadDevice::executor_type)>
  465. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
  466. void (boost::system::error_code, std::size_t))
  467. async_read_at(AsyncRandomAccessReadDevice& d, uint64_t offset,
  468. const MutableBufferSequence& buffers,
  469. BOOST_ASIO_MOVE_ARG(ReadToken) token
  470. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  471. typename AsyncRandomAccessReadDevice::executor_type));
  472. /// Start an asynchronous operation to read a certain amount of data at the
  473. /// specified offset.
  474. /**
  475. * This function is used to asynchronously read a certain number of bytes of
  476. * data from a random access device at the specified offset. It is an
  477. * initiating function for an @ref asynchronous_operation, and always returns
  478. * immediately. The asynchronous operation will continue until one of the
  479. * following conditions is true:
  480. *
  481. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  482. * the sum of the buffer sizes.
  483. *
  484. * @li The completion_condition function object returns 0.
  485. *
  486. * @param d The device from which the data is to be read. The type must support
  487. * the AsyncRandomAccessReadDevice concept.
  488. *
  489. * @param offset The offset at which the data will be read.
  490. *
  491. * @param buffers One or more buffers into which the data will be read. The sum
  492. * of the buffer sizes indicates the maximum number of bytes to read from the
  493. * device. Although the buffers object may be copied as necessary, ownership of
  494. * the underlying memory blocks is retained by the caller, which must guarantee
  495. * that they remain valid until the completion handler is called.
  496. *
  497. * @param completion_condition The function object to be called to determine
  498. * whether the read operation is complete. The signature of the function object
  499. * must be:
  500. * @code std::size_t completion_condition(
  501. * // Result of latest async_read_some_at operation.
  502. * const boost::system::error_code& error,
  503. *
  504. * // Number of bytes transferred so far.
  505. * std::size_t bytes_transferred
  506. * ); @endcode
  507. * A return value of 0 indicates that the read operation is complete. A non-zero
  508. * return value indicates the maximum number of bytes to be read on the next
  509. * call to the device's async_read_some_at function.
  510. *
  511. * @param token The @ref completion_token that will be used to produce a
  512. * completion handler, which will be called when the read completes.
  513. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  514. * @ref yield_context, or a function object with the correct completion
  515. * signature. The function signature of the completion handler must be:
  516. * @code void handler(
  517. * // Result of operation.
  518. * const boost::system::error_code& error,
  519. *
  520. * // Number of bytes copied into the buffers. If an error
  521. * // occurred, this will be the number of bytes successfully
  522. * // transferred prior to the error.
  523. * std::size_t bytes_transferred
  524. * ); @endcode
  525. * Regardless of whether the asynchronous operation completes immediately or
  526. * not, the completion handler will not be invoked from within this function.
  527. * On immediate completion, invocation of the handler will be performed in a
  528. * manner equivalent to using boost::asio::post().
  529. *
  530. * @par Completion Signature
  531. * @code void(boost::system::error_code, std::size_t) @endcode
  532. *
  533. * @par Example
  534. * To read into a single data buffer use the @ref buffer function as follows:
  535. * @code boost::asio::async_read_at(d, 42,
  536. * boost::asio::buffer(data, size),
  537. * boost::asio::transfer_at_least(32),
  538. * handler); @endcode
  539. * See the @ref buffer documentation for information on reading into multiple
  540. * buffers in one go, and how to use it with arrays, boost::array or
  541. * std::vector.
  542. *
  543. * @par Per-Operation Cancellation
  544. * This asynchronous operation supports cancellation for the following
  545. * boost::asio::cancellation_type values:
  546. *
  547. * @li @c cancellation_type::terminal
  548. *
  549. * @li @c cancellation_type::partial
  550. *
  551. * if they are also supported by the @c AsyncRandomAccessReadDevice type's
  552. * async_read_some_at operation.
  553. */
  554. template <typename AsyncRandomAccessReadDevice,
  555. typename MutableBufferSequence, typename CompletionCondition,
  556. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  557. std::size_t)) ReadToken
  558. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  559. typename AsyncRandomAccessReadDevice::executor_type)>
  560. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
  561. void (boost::system::error_code, std::size_t))
  562. async_read_at(AsyncRandomAccessReadDevice& d,
  563. uint64_t offset, const MutableBufferSequence& buffers,
  564. CompletionCondition completion_condition,
  565. BOOST_ASIO_MOVE_ARG(ReadToken) token
  566. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  567. typename AsyncRandomAccessReadDevice::executor_type));
  568. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  569. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  570. /// Start an asynchronous operation to read a certain amount of data at the
  571. /// specified offset.
  572. /**
  573. * This function is used to asynchronously read a certain number of bytes of
  574. * data from a random access device at the specified offset. It is an
  575. * initiating function for an @ref asynchronous_operation, and always returns
  576. * immediately. The asynchronous operation will continue until one of the
  577. * following conditions is true:
  578. *
  579. * @li An error occurred.
  580. *
  581. * This operation is implemented in terms of zero or more calls to the device's
  582. * async_read_some_at function.
  583. *
  584. * @param d The device from which the data is to be read. The type must support
  585. * the AsyncRandomAccessReadDevice concept.
  586. *
  587. * @param offset The offset at which the data will be read.
  588. *
  589. * @param b A basic_streambuf object into which the data will be read. Ownership
  590. * of the streambuf is retained by the caller, which must guarantee that it
  591. * remains valid until the completion handler is called.
  592. *
  593. * @param token The @ref completion_token that will be used to produce a
  594. * completion handler, which will be called when the read completes.
  595. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  596. * @ref yield_context, or a function object with the correct completion
  597. * signature. The function signature of the completion handler must be:
  598. * @code void handler(
  599. * // Result of operation.
  600. * const boost::system::error_code& error,
  601. *
  602. * // Number of bytes copied into the buffers. If an error
  603. * // occurred, this will be the number of bytes successfully
  604. * // transferred prior to the error.
  605. * std::size_t bytes_transferred
  606. * ); @endcode
  607. * Regardless of whether the asynchronous operation completes immediately or
  608. * not, the completion handler will not be invoked from within this function.
  609. * On immediate completion, invocation of the handler will be performed in a
  610. * manner equivalent to using boost::asio::post().
  611. *
  612. * @par Completion Signature
  613. * @code void(boost::system::error_code, std::size_t) @endcode
  614. *
  615. * @note This overload is equivalent to calling:
  616. * @code boost::asio::async_read_at(
  617. * d, 42, b,
  618. * boost::asio::transfer_all(),
  619. * handler); @endcode
  620. *
  621. * @par Per-Operation Cancellation
  622. * This asynchronous operation supports cancellation for the following
  623. * boost::asio::cancellation_type values:
  624. *
  625. * @li @c cancellation_type::terminal
  626. *
  627. * @li @c cancellation_type::partial
  628. *
  629. * if they are also supported by the @c AsyncRandomAccessReadDevice type's
  630. * async_read_some_at operation.
  631. */
  632. template <typename AsyncRandomAccessReadDevice, typename Allocator,
  633. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  634. std::size_t)) ReadToken
  635. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  636. typename AsyncRandomAccessReadDevice::executor_type)>
  637. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
  638. void (boost::system::error_code, std::size_t))
  639. async_read_at(AsyncRandomAccessReadDevice& d,
  640. uint64_t offset, basic_streambuf<Allocator>& b,
  641. BOOST_ASIO_MOVE_ARG(ReadToken) token
  642. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  643. typename AsyncRandomAccessReadDevice::executor_type));
  644. /// Start an asynchronous operation to read a certain amount of data at the
  645. /// specified offset.
  646. /**
  647. * This function is used to asynchronously read a certain number of bytes of
  648. * data from a random access device at the specified offset. It is an
  649. * initiating function for an @ref asynchronous_operation, and always returns
  650. * immediately. The asynchronous operation will continue until one of the
  651. * following conditions is true:
  652. *
  653. * @li The completion_condition function object returns 0.
  654. *
  655. * This operation is implemented in terms of zero or more calls to the device's
  656. * async_read_some_at function.
  657. *
  658. * @param d The device from which the data is to be read. The type must support
  659. * the AsyncRandomAccessReadDevice concept.
  660. *
  661. * @param offset The offset at which the data will be read.
  662. *
  663. * @param b A basic_streambuf object into which the data will be read. Ownership
  664. * of the streambuf is retained by the caller, which must guarantee that it
  665. * remains valid until the completion handler is called.
  666. *
  667. * @param completion_condition The function object to be called to determine
  668. * whether the read operation is complete. The signature of the function object
  669. * must be:
  670. * @code std::size_t completion_condition(
  671. * // Result of latest async_read_some_at operation.
  672. * const boost::system::error_code& error,
  673. *
  674. * // Number of bytes transferred so far.
  675. * std::size_t bytes_transferred
  676. * ); @endcode
  677. * A return value of 0 indicates that the read operation is complete. A non-zero
  678. * return value indicates the maximum number of bytes to be read on the next
  679. * call to the device's async_read_some_at function.
  680. *
  681. * @param token The @ref completion_token that will be used to produce a
  682. * completion handler, which will be called when the read completes.
  683. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  684. * @ref yield_context, or a function object with the correct completion
  685. * signature. The function signature of the completion handler must be:
  686. * @code void handler(
  687. * // Result of operation.
  688. * const boost::system::error_code& error,
  689. *
  690. * // Number of bytes copied into the buffers. If an error
  691. * // occurred, this will be the number of bytes successfully
  692. * // transferred prior to the error.
  693. * std::size_t bytes_transferred
  694. * ); @endcode
  695. * Regardless of whether the asynchronous operation completes immediately or
  696. * not, the completion handler will not be invoked from within this function.
  697. * On immediate completion, invocation of the handler will be performed in a
  698. * manner equivalent to using boost::asio::post().
  699. *
  700. * @par Completion Signature
  701. * @code void(boost::system::error_code, std::size_t) @endcode
  702. *
  703. * @par Per-Operation Cancellation
  704. * This asynchronous operation supports cancellation for the following
  705. * boost::asio::cancellation_type values:
  706. *
  707. * @li @c cancellation_type::terminal
  708. *
  709. * @li @c cancellation_type::partial
  710. *
  711. * if they are also supported by the @c AsyncRandomAccessReadDevice type's
  712. * async_read_some_at operation.
  713. */
  714. template <typename AsyncRandomAccessReadDevice,
  715. typename Allocator, typename CompletionCondition,
  716. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  717. std::size_t)) ReadToken
  718. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  719. typename AsyncRandomAccessReadDevice::executor_type)>
  720. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
  721. void (boost::system::error_code, std::size_t))
  722. async_read_at(AsyncRandomAccessReadDevice& d,
  723. uint64_t offset, basic_streambuf<Allocator>& b,
  724. CompletionCondition completion_condition,
  725. BOOST_ASIO_MOVE_ARG(ReadToken) token
  726. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  727. typename AsyncRandomAccessReadDevice::executor_type));
  728. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  729. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  730. /*@}*/
  731. } // namespace asio
  732. } // namespace boost
  733. #include <boost/asio/detail/pop_options.hpp>
  734. #include <boost/asio/impl/read_at.hpp>
  735. #endif // BOOST_ASIO_READ_AT_HPP