basic_random_access_file.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. //
  2. // basic_random_access_file.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_BASIC_RANDOM_ACCESS_FILE_HPP
  11. #define ASIO_BASIC_RANDOM_ACCESS_FILE_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. #if defined(ASIO_HAS_FILE) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <cstddef>
  19. #include "asio/async_result.hpp"
  20. #include "asio/basic_file.hpp"
  21. #include "asio/detail/handler_type_requirements.hpp"
  22. #include "asio/detail/non_const_lvalue.hpp"
  23. #include "asio/detail/throw_error.hpp"
  24. #include "asio/error.hpp"
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. #if !defined(ASIO_BASIC_RANDOM_ACCESS_FILE_FWD_DECL)
  28. #define ASIO_BASIC_RANDOM_ACCESS_FILE_FWD_DECL
  29. // Forward declaration with defaulted arguments.
  30. template <typename Executor = any_io_executor>
  31. class basic_random_access_file;
  32. #endif // !defined(ASIO_BASIC_RANDOM_ACCESS_FILE_FWD_DECL)
  33. /// Provides random-access file functionality.
  34. /**
  35. * The basic_random_access_file class template provides asynchronous and
  36. * blocking random-access file functionality.
  37. *
  38. * @par Thread Safety
  39. * @e Distinct @e objects: Safe.@n
  40. * @e Shared @e objects: Unsafe.
  41. *
  42. * Synchronous @c read_some_at and @c write_some_at operations are thread safe
  43. * with respect to each other, if the underlying operating system calls are
  44. * also thread safe. This means that it is permitted to perform concurrent
  45. * calls to these synchronous operations on a single file object. Other
  46. * synchronous operations, such as @c open or @c close, are not thread safe.
  47. */
  48. template <typename Executor>
  49. class basic_random_access_file
  50. : public basic_file<Executor>
  51. {
  52. public:
  53. /// The type of the executor associated with the object.
  54. typedef Executor executor_type;
  55. /// Rebinds the file type to another executor.
  56. template <typename Executor1>
  57. struct rebind_executor
  58. {
  59. /// The file type when rebound to the specified executor.
  60. typedef basic_random_access_file<Executor1> other;
  61. };
  62. /// The native representation of a file.
  63. #if defined(GENERATING_DOCUMENTATION)
  64. typedef implementation_defined native_handle_type;
  65. #else
  66. typedef typename basic_file<Executor>::native_handle_type native_handle_type;
  67. #endif
  68. /// Construct a basic_random_access_file without opening it.
  69. /**
  70. * This constructor initialises a file without opening it. The file needs to
  71. * be opened before data can be read from or or written to it.
  72. *
  73. * @param ex The I/O executor that the file will use, by default, to
  74. * dispatch handlers for any asynchronous operations performed on the file.
  75. */
  76. explicit basic_random_access_file(const executor_type& ex)
  77. : basic_file<Executor>(ex)
  78. {
  79. }
  80. /// Construct a basic_random_access_file without opening it.
  81. /**
  82. * This constructor initialises a file without opening it. The file needs to
  83. * be opened before data can be read from or or written to it.
  84. *
  85. * @param context An execution context which provides the I/O executor that
  86. * the file will use, by default, to dispatch handlers for any asynchronous
  87. * operations performed on the file.
  88. */
  89. template <typename ExecutionContext>
  90. explicit basic_random_access_file(ExecutionContext& context,
  91. typename constraint<
  92. is_convertible<ExecutionContext&, execution_context&>::value,
  93. defaulted_constraint
  94. >::type = defaulted_constraint())
  95. : basic_file<Executor>(context)
  96. {
  97. }
  98. /// Construct and open a basic_random_access_file.
  99. /**
  100. * This constructor initialises and opens a file.
  101. *
  102. * @param ex The I/O executor that the file will use, by default, to
  103. * dispatch handlers for any asynchronous operations performed on the file.
  104. *
  105. * @param path The path name identifying the file to be opened.
  106. *
  107. * @param open_flags A set of flags that determine how the file should be
  108. * opened.
  109. *
  110. * @throws asio::system_error Thrown on failure.
  111. */
  112. basic_random_access_file(const executor_type& ex,
  113. const char* path, file_base::flags open_flags)
  114. : basic_file<Executor>(ex, path, open_flags)
  115. {
  116. }
  117. /// Construct and open a basic_random_access_file.
  118. /**
  119. * This constructor initialises and opens a file.
  120. *
  121. * @param context An execution context which provides the I/O executor that
  122. * the file will use, by default, to dispatch handlers for any asynchronous
  123. * operations performed on the file.
  124. *
  125. * @param path The path name identifying the file to be opened.
  126. *
  127. * @param open_flags A set of flags that determine how the file should be
  128. * opened.
  129. *
  130. * @throws asio::system_error Thrown on failure.
  131. */
  132. template <typename ExecutionContext>
  133. basic_random_access_file(ExecutionContext& context,
  134. const char* path, file_base::flags open_flags,
  135. typename constraint<
  136. is_convertible<ExecutionContext&, execution_context&>::value,
  137. defaulted_constraint
  138. >::type = defaulted_constraint())
  139. : basic_file<Executor>(context, path, open_flags)
  140. {
  141. }
  142. /// Construct and open a basic_random_access_file.
  143. /**
  144. * This constructor initialises and opens a file.
  145. *
  146. * @param ex The I/O executor that the file will use, by default, to
  147. * dispatch handlers for any asynchronous operations performed on the file.
  148. *
  149. * @param path The path name identifying the file to be opened.
  150. *
  151. * @param open_flags A set of flags that determine how the file should be
  152. * opened.
  153. *
  154. * @throws asio::system_error Thrown on failure.
  155. */
  156. basic_random_access_file(const executor_type& ex,
  157. const std::string& path, file_base::flags open_flags)
  158. : basic_file<Executor>(ex, path, open_flags)
  159. {
  160. }
  161. /// Construct and open a basic_random_access_file.
  162. /**
  163. * This constructor initialises and opens a file.
  164. *
  165. * @param context An execution context which provides the I/O executor that
  166. * the file will use, by default, to dispatch handlers for any asynchronous
  167. * operations performed on the file.
  168. *
  169. * @param path The path name identifying the file to be opened.
  170. *
  171. * @param open_flags A set of flags that determine how the file should be
  172. * opened.
  173. *
  174. * @throws asio::system_error Thrown on failure.
  175. */
  176. template <typename ExecutionContext>
  177. basic_random_access_file(ExecutionContext& context,
  178. const std::string& path, file_base::flags open_flags,
  179. typename constraint<
  180. is_convertible<ExecutionContext&, execution_context&>::value,
  181. defaulted_constraint
  182. >::type = defaulted_constraint())
  183. : basic_file<Executor>(context, path, open_flags)
  184. {
  185. }
  186. /// Construct a basic_random_access_file on an existing native file.
  187. /**
  188. * This constructor initialises a random-access file object to hold an
  189. * existing native file.
  190. *
  191. * @param ex The I/O executor that the file will use, by default, to
  192. * dispatch handlers for any asynchronous operations performed on the file.
  193. *
  194. * @param native_file The new underlying file implementation.
  195. *
  196. * @throws asio::system_error Thrown on failure.
  197. */
  198. basic_random_access_file(const executor_type& ex,
  199. const native_handle_type& native_file)
  200. : basic_file<Executor>(ex, native_file)
  201. {
  202. }
  203. /// Construct a basic_random_access_file on an existing native file.
  204. /**
  205. * This constructor initialises a random-access file object to hold an
  206. * existing native file.
  207. *
  208. * @param context An execution context which provides the I/O executor that
  209. * the file will use, by default, to dispatch handlers for any asynchronous
  210. * operations performed on the file.
  211. *
  212. * @param native_file The new underlying file implementation.
  213. *
  214. * @throws asio::system_error Thrown on failure.
  215. */
  216. template <typename ExecutionContext>
  217. basic_random_access_file(ExecutionContext& context,
  218. const native_handle_type& native_file,
  219. typename constraint<
  220. is_convertible<ExecutionContext&, execution_context&>::value,
  221. defaulted_constraint
  222. >::type = defaulted_constraint())
  223. : basic_file<Executor>(context, native_file)
  224. {
  225. }
  226. #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  227. /// Move-construct a basic_random_access_file from another.
  228. /**
  229. * This constructor moves a random-access file from one object to another.
  230. *
  231. * @param other The other basic_random_access_file object from which the move
  232. * will occur.
  233. *
  234. * @note Following the move, the moved-from object is in the same state as if
  235. * constructed using the @c basic_random_access_file(const executor_type&)
  236. * constructor.
  237. */
  238. basic_random_access_file(basic_random_access_file&& other) ASIO_NOEXCEPT
  239. : basic_file<Executor>(std::move(other))
  240. {
  241. }
  242. /// Move-assign a basic_random_access_file from another.
  243. /**
  244. * This assignment operator moves a random-access file from one object to
  245. * another.
  246. *
  247. * @param other The other basic_random_access_file object from which the move
  248. * will occur.
  249. *
  250. * @note Following the move, the moved-from object is in the same state as if
  251. * constructed using the @c basic_random_access_file(const executor_type&)
  252. * constructor.
  253. */
  254. basic_random_access_file& operator=(basic_random_access_file&& other)
  255. {
  256. basic_file<Executor>::operator=(std::move(other));
  257. return *this;
  258. }
  259. /// Move-construct a basic_random_access_file from a file of another executor
  260. /// type.
  261. /**
  262. * This constructor moves a random-access file from one object to another.
  263. *
  264. * @param other The other basic_random_access_file object from which the move
  265. * will occur.
  266. *
  267. * @note Following the move, the moved-from object is in the same state as if
  268. * constructed using the @c basic_random_access_file(const executor_type&)
  269. * constructor.
  270. */
  271. template <typename Executor1>
  272. basic_random_access_file(basic_random_access_file<Executor1>&& other,
  273. typename constraint<
  274. is_convertible<Executor1, Executor>::value,
  275. defaulted_constraint
  276. >::type = defaulted_constraint())
  277. : basic_file<Executor>(std::move(other))
  278. {
  279. }
  280. /// Move-assign a basic_random_access_file from a file of another executor
  281. /// type.
  282. /**
  283. * This assignment operator moves a random-access file from one object to
  284. * another.
  285. *
  286. * @param other The other basic_random_access_file object from which the move
  287. * will occur.
  288. *
  289. * @note Following the move, the moved-from object is in the same state as if
  290. * constructed using the @c basic_random_access_file(const executor_type&)
  291. * constructor.
  292. */
  293. template <typename Executor1>
  294. typename constraint<
  295. is_convertible<Executor1, Executor>::value,
  296. basic_random_access_file&
  297. >::type operator=(basic_random_access_file<Executor1>&& other)
  298. {
  299. basic_file<Executor>::operator=(std::move(other));
  300. return *this;
  301. }
  302. #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  303. /// Destroys the file.
  304. /**
  305. * This function destroys the file, cancelling any outstanding asynchronous
  306. * operations associated with the file as if by calling @c cancel.
  307. */
  308. ~basic_random_access_file()
  309. {
  310. }
  311. /// Write some data to the handle at the specified offset.
  312. /**
  313. * This function is used to write data to the random-access handle. The
  314. * function call will block until one or more bytes of the data has been
  315. * written successfully, or until an error occurs.
  316. *
  317. * @param offset The offset at which the data will be written.
  318. *
  319. * @param buffers One or more data buffers to be written to the handle.
  320. *
  321. * @returns The number of bytes written.
  322. *
  323. * @throws asio::system_error Thrown on failure. An error code of
  324. * asio::error::eof indicates that the end of the file was reached.
  325. *
  326. * @note The write_some_at operation may not write all of the data. Consider
  327. * using the @ref write_at function if you need to ensure that all data is
  328. * written before the blocking operation completes.
  329. *
  330. * @par Example
  331. * To write a single data buffer use the @ref buffer function as follows:
  332. * @code
  333. * handle.write_some_at(42, asio::buffer(data, size));
  334. * @endcode
  335. * See the @ref buffer documentation for information on writing multiple
  336. * buffers in one go, and how to use it with arrays, boost::array or
  337. * std::vector.
  338. */
  339. template <typename ConstBufferSequence>
  340. std::size_t write_some_at(uint64_t offset,
  341. const ConstBufferSequence& buffers)
  342. {
  343. asio::error_code ec;
  344. std::size_t s = this->impl_.get_service().write_some_at(
  345. this->impl_.get_implementation(), offset, buffers, ec);
  346. asio::detail::throw_error(ec, "write_some_at");
  347. return s;
  348. }
  349. /// Write some data to the handle at the specified offset.
  350. /**
  351. * This function is used to write data to the random-access handle. The
  352. * function call will block until one or more bytes of the data has been
  353. * written successfully, or until an error occurs.
  354. *
  355. * @param offset The offset at which the data will be written.
  356. *
  357. * @param buffers One or more data buffers to be written to the handle.
  358. *
  359. * @param ec Set to indicate what error occurred, if any.
  360. *
  361. * @returns The number of bytes written. Returns 0 if an error occurred.
  362. *
  363. * @note The write_some operation may not write all of the data to the
  364. * file. Consider using the @ref write_at function if you need to ensure that
  365. * all data is written before the blocking operation completes.
  366. */
  367. template <typename ConstBufferSequence>
  368. std::size_t write_some_at(uint64_t offset,
  369. const ConstBufferSequence& buffers, asio::error_code& ec)
  370. {
  371. return this->impl_.get_service().write_some_at(
  372. this->impl_.get_implementation(), offset, buffers, ec);
  373. }
  374. /// Start an asynchronous write at the specified offset.
  375. /**
  376. * This function is used to asynchronously write data to the random-access
  377. * handle. It is an initiating function for an @ref asynchronous_operation,
  378. * and always returns immediately.
  379. *
  380. * @param offset The offset at which the data will be written.
  381. *
  382. * @param buffers One or more data buffers to be written to the handle.
  383. * Although the buffers object may be copied as necessary, ownership of the
  384. * underlying memory blocks is retained by the caller, which must guarantee
  385. * that they remain valid until the completion handler is called.
  386. *
  387. * @param token The @ref completion_token that will be used to produce a
  388. * completion handler, which will be called when the write completes.
  389. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  390. * @ref yield_context, or a function object with the correct completion
  391. * signature. The function signature of the completion handler must be:
  392. * @code void handler(
  393. * const asio::error_code& error, // Result of operation.
  394. * std::size_t bytes_transferred // Number of bytes written.
  395. * ); @endcode
  396. * Regardless of whether the asynchronous operation completes immediately or
  397. * not, the completion handler will not be invoked from within this function.
  398. * On immediate completion, invocation of the handler will be performed in a
  399. * manner equivalent to using asio::post().
  400. *
  401. * @par Completion Signature
  402. * @code void(asio::error_code, std::size_t) @endcode
  403. *
  404. * @note The write operation may not write all of the data to the file.
  405. * Consider using the @ref async_write_at function if you need to ensure that
  406. * all data is written before the asynchronous operation completes.
  407. *
  408. * @par Example
  409. * To write a single data buffer use the @ref buffer function as follows:
  410. * @code
  411. * handle.async_write_some_at(42, asio::buffer(data, size), handler);
  412. * @endcode
  413. * See the @ref buffer documentation for information on writing multiple
  414. * buffers in one go, and how to use it with arrays, boost::array or
  415. * std::vector.
  416. *
  417. * @par Per-Operation Cancellation
  418. * This asynchronous operation supports cancellation for the following
  419. * asio::cancellation_type values:
  420. *
  421. * @li @c cancellation_type::terminal
  422. *
  423. * @li @c cancellation_type::partial
  424. *
  425. * @li @c cancellation_type::total
  426. */
  427. template <typename ConstBufferSequence,
  428. ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
  429. std::size_t)) WriteToken
  430. ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
  431. ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  432. void (asio::error_code, std::size_t))
  433. async_write_some_at(uint64_t offset,
  434. const ConstBufferSequence& buffers,
  435. ASIO_MOVE_ARG(WriteToken) token
  436. ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
  437. {
  438. return async_initiate<WriteToken,
  439. void (asio::error_code, std::size_t)>(
  440. initiate_async_write_some_at(this), token, offset, buffers);
  441. }
  442. /// Read some data from the handle at the specified offset.
  443. /**
  444. * This function is used to read data from the random-access handle. The
  445. * function call will block until one or more bytes of data has been read
  446. * successfully, or until an error occurs.
  447. *
  448. * @param offset The offset at which the data will be read.
  449. *
  450. * @param buffers One or more buffers into which the data will be read.
  451. *
  452. * @returns The number of bytes read.
  453. *
  454. * @throws asio::system_error Thrown on failure. An error code of
  455. * asio::error::eof indicates that the end of the file was reached.
  456. *
  457. * @note The read_some operation may not read all of the requested number of
  458. * bytes. Consider using the @ref read_at function if you need to ensure that
  459. * the requested amount of data is read before the blocking operation
  460. * completes.
  461. *
  462. * @par Example
  463. * To read into a single data buffer use the @ref buffer function as follows:
  464. * @code
  465. * handle.read_some_at(42, asio::buffer(data, size));
  466. * @endcode
  467. * See the @ref buffer documentation for information on reading into multiple
  468. * buffers in one go, and how to use it with arrays, boost::array or
  469. * std::vector.
  470. */
  471. template <typename MutableBufferSequence>
  472. std::size_t read_some_at(uint64_t offset,
  473. const MutableBufferSequence& buffers)
  474. {
  475. asio::error_code ec;
  476. std::size_t s = this->impl_.get_service().read_some_at(
  477. this->impl_.get_implementation(), offset, buffers, ec);
  478. asio::detail::throw_error(ec, "read_some_at");
  479. return s;
  480. }
  481. /// Read some data from the handle at the specified offset.
  482. /**
  483. * This function is used to read data from the random-access handle. The
  484. * function call will block until one or more bytes of data has been read
  485. * successfully, or until an error occurs.
  486. *
  487. * @param offset The offset at which the data will be read.
  488. *
  489. * @param buffers One or more buffers into which the data will be read.
  490. *
  491. * @param ec Set to indicate what error occurred, if any.
  492. *
  493. * @returns The number of bytes read. Returns 0 if an error occurred.
  494. *
  495. * @note The read_some operation may not read all of the requested number of
  496. * bytes. Consider using the @ref read_at function if you need to ensure that
  497. * the requested amount of data is read before the blocking operation
  498. * completes.
  499. */
  500. template <typename MutableBufferSequence>
  501. std::size_t read_some_at(uint64_t offset,
  502. const MutableBufferSequence& buffers, asio::error_code& ec)
  503. {
  504. return this->impl_.get_service().read_some_at(
  505. this->impl_.get_implementation(), offset, buffers, ec);
  506. }
  507. /// Start an asynchronous read at the specified offset.
  508. /**
  509. * This function is used to asynchronously read data from the random-access
  510. * handle. It is an initiating function for an @ref asynchronous_operation,
  511. * and always returns immediately.
  512. *
  513. * @param offset The offset at which the data will be read.
  514. *
  515. * @param buffers One or more buffers into which the data will be read.
  516. * Although the buffers object may be copied as necessary, ownership of the
  517. * underlying memory blocks is retained by the caller, which must guarantee
  518. * that they remain valid until the completion handler is called.
  519. *
  520. * @param token The @ref completion_token that will be used to produce a
  521. * completion handler, which will be called when the read completes.
  522. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  523. * @ref yield_context, or a function object with the correct completion
  524. * signature. The function signature of the completion handler must be:
  525. * @code void handler(
  526. * const asio::error_code& error, // Result of operation.
  527. * std::size_t bytes_transferred // Number of bytes read.
  528. * ); @endcode
  529. * Regardless of whether the asynchronous operation completes immediately or
  530. * not, the completion handler will not be invoked from within this function.
  531. * On immediate completion, invocation of the handler will be performed in a
  532. * manner equivalent to using asio::post().
  533. *
  534. * @par Completion Signature
  535. * @code void(asio::error_code, std::size_t) @endcode
  536. *
  537. * @note The read operation may not read all of the requested number of bytes.
  538. * Consider using the @ref async_read_at function if you need to ensure that
  539. * the requested amount of data is read before the asynchronous operation
  540. * completes.
  541. *
  542. * @par Example
  543. * To read into a single data buffer use the @ref buffer function as follows:
  544. * @code
  545. * handle.async_read_some_at(42, asio::buffer(data, size), handler);
  546. * @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. * asio::cancellation_type values:
  554. *
  555. * @li @c cancellation_type::terminal
  556. *
  557. * @li @c cancellation_type::partial
  558. *
  559. * @li @c cancellation_type::total
  560. */
  561. template <typename MutableBufferSequence,
  562. ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
  563. std::size_t)) ReadToken
  564. ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
  565. ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
  566. void (asio::error_code, std::size_t))
  567. async_read_some_at(uint64_t offset,
  568. const MutableBufferSequence& buffers,
  569. ASIO_MOVE_ARG(ReadToken) token
  570. ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
  571. {
  572. return async_initiate<ReadToken,
  573. void (asio::error_code, std::size_t)>(
  574. initiate_async_read_some_at(this), token, offset, buffers);
  575. }
  576. private:
  577. // Disallow copying and assignment.
  578. basic_random_access_file(const basic_random_access_file&) ASIO_DELETED;
  579. basic_random_access_file& operator=(
  580. const basic_random_access_file&) ASIO_DELETED;
  581. class initiate_async_write_some_at
  582. {
  583. public:
  584. typedef Executor executor_type;
  585. explicit initiate_async_write_some_at(basic_random_access_file* self)
  586. : self_(self)
  587. {
  588. }
  589. executor_type get_executor() const ASIO_NOEXCEPT
  590. {
  591. return self_->get_executor();
  592. }
  593. template <typename WriteHandler, typename ConstBufferSequence>
  594. void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
  595. uint64_t offset, const ConstBufferSequence& buffers) const
  596. {
  597. // If you get an error on the following line it means that your handler
  598. // does not meet the documented type requirements for a WriteHandler.
  599. ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
  600. detail::non_const_lvalue<WriteHandler> handler2(handler);
  601. self_->impl_.get_service().async_write_some_at(
  602. self_->impl_.get_implementation(), offset, buffers,
  603. handler2.value, self_->impl_.get_executor());
  604. }
  605. private:
  606. basic_random_access_file* self_;
  607. };
  608. class initiate_async_read_some_at
  609. {
  610. public:
  611. typedef Executor executor_type;
  612. explicit initiate_async_read_some_at(basic_random_access_file* self)
  613. : self_(self)
  614. {
  615. }
  616. executor_type get_executor() const ASIO_NOEXCEPT
  617. {
  618. return self_->get_executor();
  619. }
  620. template <typename ReadHandler, typename MutableBufferSequence>
  621. void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
  622. uint64_t offset, const MutableBufferSequence& buffers) const
  623. {
  624. // If you get an error on the following line it means that your handler
  625. // does not meet the documented type requirements for a ReadHandler.
  626. ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
  627. detail::non_const_lvalue<ReadHandler> handler2(handler);
  628. self_->impl_.get_service().async_read_some_at(
  629. self_->impl_.get_implementation(), offset, buffers,
  630. handler2.value, self_->impl_.get_executor());
  631. }
  632. private:
  633. basic_random_access_file* self_;
  634. };
  635. };
  636. } // namespace asio
  637. #include "asio/detail/pop_options.hpp"
  638. #endif // defined(ASIO_HAS_FILE)
  639. // || defined(GENERATING_DOCUMENTATION)
  640. #endif // ASIO_BASIC_RANDOM_ACCESS_FILE_HPP