Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

read_at.hpp 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. //
  2. // read_at.hpp
  3. // ~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. The function call
  388. * always returns immediately. The asynchronous operation will continue until
  389. * one of the following conditions is true:
  390. *
  391. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  392. * the sum of the buffer sizes.
  393. *
  394. * @li An error occurred.
  395. *
  396. * This operation is implemented in terms of zero or more calls to the device's
  397. * async_read_some_at function.
  398. *
  399. * @param d The device from which the data is to be read. The type must support
  400. * the AsyncRandomAccessReadDevice concept.
  401. *
  402. * @param offset The offset at which the data will be read.
  403. *
  404. * @param buffers One or more buffers into which the data will be read. The sum
  405. * of the buffer sizes indicates the maximum number of bytes to read from the
  406. * device. Although the buffers object may be copied as necessary, ownership of
  407. * the underlying memory blocks is retained by the caller, which must guarantee
  408. * that they remain valid until the handler is called.
  409. *
  410. * @param handler The handler to be called when the read operation completes.
  411. * Copies will be made of the handler as required. The function signature of the
  412. * handler must be:
  413. * @code void handler(
  414. * // Result of operation.
  415. * const asio::error_code& error,
  416. *
  417. * // Number of bytes copied into the buffers. If an error
  418. * // occurred, this will be the number of bytes successfully
  419. * // transferred prior to the error.
  420. * std::size_t bytes_transferred
  421. * ); @endcode
  422. * Regardless of whether the asynchronous operation completes immediately or
  423. * not, the handler will not be invoked from within this function. On
  424. * immediate completion, invocation of the handler will be performed in a
  425. * manner equivalent to using asio::post().
  426. *
  427. * @par Example
  428. * To read into a single data buffer use the @ref buffer function as follows:
  429. * @code
  430. * asio::async_read_at(d, 42, asio::buffer(data, size), handler);
  431. * @endcode
  432. * See the @ref buffer documentation for information on reading into multiple
  433. * buffers in one go, and how to use it with arrays, boost::array or
  434. * std::vector.
  435. *
  436. * @note This overload is equivalent to calling:
  437. * @code asio::async_read_at(
  438. * d, 42, buffers,
  439. * asio::transfer_all(),
  440. * handler); @endcode
  441. */
  442. template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
  443. typename ReadHandler>
  444. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  445. void (asio::error_code, std::size_t))
  446. async_read_at(AsyncRandomAccessReadDevice& d, uint64_t offset,
  447. const MutableBufferSequence& buffers,
  448. ASIO_MOVE_ARG(ReadHandler) handler);
  449. /// Start an asynchronous operation to read a certain amount of data at the
  450. /// specified offset.
  451. /**
  452. * This function is used to asynchronously read a certain number of bytes of
  453. * data from a random access device at the specified offset. The function call
  454. * always returns immediately. The asynchronous operation will continue until
  455. * one of the following conditions is true:
  456. *
  457. * @li The supplied buffers are full. That is, the bytes transferred is equal to
  458. * the sum of the buffer sizes.
  459. *
  460. * @li The completion_condition function object returns 0.
  461. *
  462. * @param d The device from which the data is to be read. The type must support
  463. * the AsyncRandomAccessReadDevice concept.
  464. *
  465. * @param offset The offset at which the data will be read.
  466. *
  467. * @param buffers One or more buffers into which the data will be read. The sum
  468. * of the buffer sizes indicates the maximum number of bytes to read from the
  469. * device. Although the buffers object may be copied as necessary, ownership of
  470. * the underlying memory blocks is retained by the caller, which must guarantee
  471. * that they remain valid until the handler is called.
  472. *
  473. * @param completion_condition The function object to be called to determine
  474. * whether the read operation is complete. The signature of the function object
  475. * must be:
  476. * @code std::size_t completion_condition(
  477. * // Result of latest async_read_some_at operation.
  478. * const asio::error_code& error,
  479. *
  480. * // Number of bytes transferred so far.
  481. * std::size_t bytes_transferred
  482. * ); @endcode
  483. * A return value of 0 indicates that the read operation is complete. A non-zero
  484. * return value indicates the maximum number of bytes to be read on the next
  485. * call to the device's async_read_some_at function.
  486. *
  487. * @param handler The handler to be called when the read operation completes.
  488. * Copies will be made of the handler as required. The function signature of the
  489. * handler must be:
  490. * @code void handler(
  491. * // Result of operation.
  492. * const asio::error_code& error,
  493. *
  494. * // Number of bytes copied into the buffers. If an error
  495. * // occurred, this will be the number of bytes successfully
  496. * // transferred prior to the error.
  497. * std::size_t bytes_transferred
  498. * ); @endcode
  499. * Regardless of whether the asynchronous operation completes immediately or
  500. * not, the handler will not be invoked from within this function. On
  501. * immediate completion, invocation of the handler will be performed in a
  502. * manner equivalent to using asio::post().
  503. *
  504. * @par Example
  505. * To read into a single data buffer use the @ref buffer function as follows:
  506. * @code asio::async_read_at(d, 42,
  507. * asio::buffer(data, size),
  508. * asio::transfer_at_least(32),
  509. * handler); @endcode
  510. * See the @ref buffer documentation for information on reading into multiple
  511. * buffers in one go, and how to use it with arrays, boost::array or
  512. * std::vector.
  513. */
  514. template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
  515. typename CompletionCondition, typename ReadHandler>
  516. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  517. void (asio::error_code, std::size_t))
  518. async_read_at(AsyncRandomAccessReadDevice& d,
  519. uint64_t offset, const MutableBufferSequence& buffers,
  520. CompletionCondition completion_condition,
  521. ASIO_MOVE_ARG(ReadHandler) handler);
  522. #if !defined(ASIO_NO_EXTENSIONS)
  523. #if !defined(ASIO_NO_IOSTREAM)
  524. /// Start an asynchronous operation to read a certain amount of data at the
  525. /// specified offset.
  526. /**
  527. * This function is used to asynchronously read a certain number of bytes of
  528. * data from a random access device at the specified offset. The function call
  529. * always returns immediately. The asynchronous operation will continue until
  530. * one of the following conditions is true:
  531. *
  532. * @li An error occurred.
  533. *
  534. * This operation is implemented in terms of zero or more calls to the device's
  535. * async_read_some_at function.
  536. *
  537. * @param d The device from which the data is to be read. The type must support
  538. * the AsyncRandomAccessReadDevice concept.
  539. *
  540. * @param offset The offset at which the data will be read.
  541. *
  542. * @param b A basic_streambuf object into which the data will be read. Ownership
  543. * of the streambuf is retained by the caller, which must guarantee that it
  544. * remains valid until the handler is called.
  545. *
  546. * @param handler The handler to be called when the read operation completes.
  547. * Copies will be made of the handler as required. The function signature of the
  548. * handler must be:
  549. * @code void handler(
  550. * // Result of operation.
  551. * const asio::error_code& error,
  552. *
  553. * // Number of bytes copied into the buffers. If an error
  554. * // occurred, this will be the number of bytes successfully
  555. * // transferred prior to the error.
  556. * std::size_t bytes_transferred
  557. * ); @endcode
  558. * Regardless of whether the asynchronous operation completes immediately or
  559. * not, the handler will not be invoked from within this function. On
  560. * immediate completion, invocation of the handler will be performed in a
  561. * manner equivalent to using asio::post().
  562. *
  563. * @note This overload is equivalent to calling:
  564. * @code asio::async_read_at(
  565. * d, 42, b,
  566. * asio::transfer_all(),
  567. * handler); @endcode
  568. */
  569. template <typename AsyncRandomAccessReadDevice, typename Allocator,
  570. typename ReadHandler>
  571. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  572. void (asio::error_code, std::size_t))
  573. async_read_at(AsyncRandomAccessReadDevice& d, uint64_t offset,
  574. basic_streambuf<Allocator>& b, ASIO_MOVE_ARG(ReadHandler) handler);
  575. /// Start an asynchronous operation to read a certain amount of data at the
  576. /// specified offset.
  577. /**
  578. * This function is used to asynchronously read a certain number of bytes of
  579. * data from a random access device at the specified offset. The function call
  580. * always returns immediately. The asynchronous operation will continue until
  581. * one of the following conditions is true:
  582. *
  583. * @li The completion_condition function object returns 0.
  584. *
  585. * This operation is implemented in terms of zero or more calls to the device's
  586. * async_read_some_at function.
  587. *
  588. * @param d The device from which the data is to be read. The type must support
  589. * the AsyncRandomAccessReadDevice concept.
  590. *
  591. * @param offset The offset at which the data will be read.
  592. *
  593. * @param b A basic_streambuf object into which the data will be read. Ownership
  594. * of the streambuf is retained by the caller, which must guarantee that it
  595. * remains valid until the handler is called.
  596. *
  597. * @param completion_condition The function object to be called to determine
  598. * whether the read operation is complete. The signature of the function object
  599. * must be:
  600. * @code std::size_t completion_condition(
  601. * // Result of latest async_read_some_at operation.
  602. * const asio::error_code& error,
  603. *
  604. * // Number of bytes transferred so far.
  605. * std::size_t bytes_transferred
  606. * ); @endcode
  607. * A return value of 0 indicates that the read operation is complete. A non-zero
  608. * return value indicates the maximum number of bytes to be read on the next
  609. * call to the device's async_read_some_at function.
  610. *
  611. * @param handler The handler to be called when the read operation completes.
  612. * Copies will be made of the handler as required. The function signature of the
  613. * handler must be:
  614. * @code void handler(
  615. * // Result of operation.
  616. * const asio::error_code& error,
  617. *
  618. * // Number of bytes copied into the buffers. If an error
  619. * // occurred, this will be the number of bytes successfully
  620. * // transferred prior to the error.
  621. * std::size_t bytes_transferred
  622. * ); @endcode
  623. * Regardless of whether the asynchronous operation completes immediately or
  624. * not, the handler will not be invoked from within this function. On
  625. * immediate completion, invocation of the handler will be performed in a
  626. * manner equivalent to using asio::post().
  627. */
  628. template <typename AsyncRandomAccessReadDevice, typename Allocator,
  629. typename CompletionCondition, typename ReadHandler>
  630. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  631. void (asio::error_code, std::size_t))
  632. async_read_at(AsyncRandomAccessReadDevice& d,
  633. uint64_t offset, basic_streambuf<Allocator>& b,
  634. CompletionCondition completion_condition,
  635. ASIO_MOVE_ARG(ReadHandler) handler);
  636. #endif // !defined(ASIO_NO_IOSTREAM)
  637. #endif // !defined(ASIO_NO_EXTENSIONS)
  638. /*@}*/
  639. } // namespace asio
  640. #include "asio/detail/pop_options.hpp"
  641. #include "asio/impl/read_at.hpp"
  642. #endif // ASIO_READ_AT_HPP