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.

680 lines
27KB

  1. //
  2. // write_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_WRITE_AT_HPP
  11. #define ASIO_WRITE_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 write_at asio::write_at
  27. *
  28. * @brief The @c write_at function is a composed operation that writes a
  29. * certain amount of data at a specified offset before returning.
  30. */
  31. /*@{*/
  32. /// Write all of the supplied data at the specified offset before returning.
  33. /**
  34. * This function is used to write a certain number of bytes of data to a random
  35. * access device at a specified offset. The call will block until one of the
  36. * following conditions is true:
  37. *
  38. * @li All of the data in the supplied buffers has been written. That is, the
  39. * bytes transferred is equal to the sum of the buffer sizes.
  40. *
  41. * @li An error occurred.
  42. *
  43. * This operation is implemented in terms of zero or more calls to the device's
  44. * write_some_at function.
  45. *
  46. * @param d The device to which the data is to be written. The type must support
  47. * the SyncRandomAccessWriteDevice concept.
  48. *
  49. * @param offset The offset at which the data will be written.
  50. *
  51. * @param buffers One or more buffers containing the data to be written. The sum
  52. * of the buffer sizes indicates the maximum number of bytes to write to the
  53. * device.
  54. *
  55. * @returns The number of bytes transferred.
  56. *
  57. * @throws asio::system_error Thrown on failure.
  58. *
  59. * @par Example
  60. * To write a single data buffer use the @ref buffer function as follows:
  61. * @code asio::write_at(d, 42, asio::buffer(data, size)); @endcode
  62. * See the @ref buffer documentation for information on writing multiple
  63. * buffers in one go, and how to use it with arrays, boost::array or
  64. * std::vector.
  65. *
  66. * @note This overload is equivalent to calling:
  67. * @code asio::write_at(
  68. * d, offset, buffers,
  69. * asio::transfer_all()); @endcode
  70. */
  71. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
  72. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  73. uint64_t offset, const ConstBufferSequence& buffers);
  74. /// Write all of the supplied data at the specified offset before returning.
  75. /**
  76. * This function is used to write a certain number of bytes of data to a random
  77. * access device at a specified offset. The call will block until one of the
  78. * following conditions is true:
  79. *
  80. * @li All of the data in the supplied buffers has been written. That is, the
  81. * bytes transferred is equal to the sum of the buffer sizes.
  82. *
  83. * @li An error occurred.
  84. *
  85. * This operation is implemented in terms of zero or more calls to the device's
  86. * write_some_at function.
  87. *
  88. * @param d The device to which the data is to be written. The type must support
  89. * the SyncRandomAccessWriteDevice concept.
  90. *
  91. * @param offset The offset at which the data will be written.
  92. *
  93. * @param buffers One or more buffers containing the data to be written. The sum
  94. * of the buffer sizes indicates the maximum number of bytes to write to the
  95. * device.
  96. *
  97. * @param ec Set to indicate what error occurred, if any.
  98. *
  99. * @returns The number of bytes transferred.
  100. *
  101. * @par Example
  102. * To write a single data buffer use the @ref buffer function as follows:
  103. * @code asio::write_at(d, 42,
  104. * asio::buffer(data, size), ec); @endcode
  105. * See the @ref buffer documentation for information on writing multiple
  106. * buffers in one go, and how to use it with arrays, boost::array or
  107. * std::vector.
  108. *
  109. * @note This overload is equivalent to calling:
  110. * @code asio::write_at(
  111. * d, offset, buffers,
  112. * asio::transfer_all(), ec); @endcode
  113. */
  114. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
  115. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  116. uint64_t offset, const ConstBufferSequence& buffers,
  117. asio::error_code& ec);
  118. /// Write a certain amount of data at a specified offset before returning.
  119. /**
  120. * This function is used to write a certain number of bytes of data to a random
  121. * access device at a specified offset. The call will block until one of the
  122. * following conditions is true:
  123. *
  124. * @li All of the data in the supplied buffers has been written. That is, the
  125. * bytes transferred is equal to the sum of the buffer sizes.
  126. *
  127. * @li The completion_condition function object returns 0.
  128. *
  129. * This operation is implemented in terms of zero or more calls to the device's
  130. * write_some_at function.
  131. *
  132. * @param d The device to which the data is to be written. The type must support
  133. * the SyncRandomAccessWriteDevice concept.
  134. *
  135. * @param offset The offset at which the data will be written.
  136. *
  137. * @param buffers One or more buffers containing the data to be written. The sum
  138. * of the buffer sizes indicates the maximum number of bytes to write to the
  139. * device.
  140. *
  141. * @param completion_condition The function object to be called to determine
  142. * whether the write operation is complete. The signature of the function object
  143. * must be:
  144. * @code std::size_t completion_condition(
  145. * // Result of latest write_some_at operation.
  146. * const asio::error_code& error,
  147. *
  148. * // Number of bytes transferred so far.
  149. * std::size_t bytes_transferred
  150. * ); @endcode
  151. * A return value of 0 indicates that the write operation is complete. A
  152. * non-zero return value indicates the maximum number of bytes to be written on
  153. * the next call to the device's write_some_at function.
  154. *
  155. * @returns The number of bytes transferred.
  156. *
  157. * @throws asio::system_error Thrown on failure.
  158. *
  159. * @par Example
  160. * To write a single data buffer use the @ref buffer function as follows:
  161. * @code asio::write_at(d, 42, asio::buffer(data, size),
  162. * asio::transfer_at_least(32)); @endcode
  163. * See the @ref buffer documentation for information on writing multiple
  164. * buffers in one go, and how to use it with arrays, boost::array or
  165. * std::vector.
  166. */
  167. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
  168. typename CompletionCondition>
  169. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  170. uint64_t offset, const ConstBufferSequence& buffers,
  171. CompletionCondition completion_condition);
  172. /// Write a certain amount of data at a specified offset before returning.
  173. /**
  174. * This function is used to write a certain number of bytes of data to a random
  175. * access device at a specified offset. The call will block until one of the
  176. * following conditions is true:
  177. *
  178. * @li All of the data in the supplied buffers has been written. That is, the
  179. * bytes transferred is equal to the sum of the buffer sizes.
  180. *
  181. * @li The completion_condition function object returns 0.
  182. *
  183. * This operation is implemented in terms of zero or more calls to the device's
  184. * write_some_at function.
  185. *
  186. * @param d The device to which the data is to be written. The type must support
  187. * the SyncRandomAccessWriteDevice concept.
  188. *
  189. * @param offset The offset at which the data will be written.
  190. *
  191. * @param buffers One or more buffers containing the data to be written. The sum
  192. * of the buffer sizes indicates the maximum number of bytes to write to the
  193. * device.
  194. *
  195. * @param completion_condition The function object to be called to determine
  196. * whether the write operation is complete. The signature of the function object
  197. * must be:
  198. * @code std::size_t completion_condition(
  199. * // Result of latest write_some_at operation.
  200. * const asio::error_code& error,
  201. *
  202. * // Number of bytes transferred so far.
  203. * std::size_t bytes_transferred
  204. * ); @endcode
  205. * A return value of 0 indicates that the write operation is complete. A
  206. * non-zero return value indicates the maximum number of bytes to be written on
  207. * the next call to the device's write_some_at function.
  208. *
  209. * @param ec Set to indicate what error occurred, if any.
  210. *
  211. * @returns The number of bytes written. If an error occurs, returns the total
  212. * number of bytes successfully transferred prior to the error.
  213. */
  214. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
  215. typename CompletionCondition>
  216. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  217. uint64_t offset, const ConstBufferSequence& buffers,
  218. CompletionCondition completion_condition, asio::error_code& ec);
  219. #if !defined(ASIO_NO_EXTENSIONS)
  220. #if !defined(ASIO_NO_IOSTREAM)
  221. /// Write all of the supplied data at the specified offset before returning.
  222. /**
  223. * This function is used to write a certain number of bytes of data to a random
  224. * access device at a specified offset. The call will block until one of the
  225. * following conditions is true:
  226. *
  227. * @li All of the data in the supplied basic_streambuf has been written.
  228. *
  229. * @li An error occurred.
  230. *
  231. * This operation is implemented in terms of zero or more calls to the device's
  232. * write_some_at function.
  233. *
  234. * @param d The device to which the data is to be written. The type must support
  235. * the SyncRandomAccessWriteDevice concept.
  236. *
  237. * @param offset The offset at which the data will be written.
  238. *
  239. * @param b The basic_streambuf object from which data will be written.
  240. *
  241. * @returns The number of bytes transferred.
  242. *
  243. * @throws asio::system_error Thrown on failure.
  244. *
  245. * @note This overload is equivalent to calling:
  246. * @code asio::write_at(
  247. * d, 42, b,
  248. * asio::transfer_all()); @endcode
  249. */
  250. template <typename SyncRandomAccessWriteDevice, typename Allocator>
  251. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  252. uint64_t offset, basic_streambuf<Allocator>& b);
  253. /// Write all of the supplied data at the specified offset before returning.
  254. /**
  255. * This function is used to write a certain number of bytes of data to a random
  256. * access device at a specified offset. The call will block until one of the
  257. * following conditions is true:
  258. *
  259. * @li All of the data in the supplied basic_streambuf has been written.
  260. *
  261. * @li An error occurred.
  262. *
  263. * This operation is implemented in terms of zero or more calls to the device's
  264. * write_some_at function.
  265. *
  266. * @param d The device to which the data is to be written. The type must support
  267. * the SyncRandomAccessWriteDevice concept.
  268. *
  269. * @param offset The offset at which the data will be written.
  270. *
  271. * @param b The basic_streambuf object from which data will be written.
  272. *
  273. * @param ec Set to indicate what error occurred, if any.
  274. *
  275. * @returns The number of bytes transferred.
  276. *
  277. * @note This overload is equivalent to calling:
  278. * @code asio::write_at(
  279. * d, 42, b,
  280. * asio::transfer_all(), ec); @endcode
  281. */
  282. template <typename SyncRandomAccessWriteDevice, typename Allocator>
  283. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  284. uint64_t offset, basic_streambuf<Allocator>& b,
  285. asio::error_code& ec);
  286. /// Write a certain amount of data at a specified offset before returning.
  287. /**
  288. * This function is used to write a certain number of bytes of data to a random
  289. * access device at a specified offset. The call will block until one of the
  290. * following conditions is true:
  291. *
  292. * @li All of the data in the supplied basic_streambuf has been written.
  293. *
  294. * @li The completion_condition function object returns 0.
  295. *
  296. * This operation is implemented in terms of zero or more calls to the device's
  297. * write_some_at function.
  298. *
  299. * @param d The device to which the data is to be written. The type must support
  300. * the SyncRandomAccessWriteDevice concept.
  301. *
  302. * @param offset The offset at which the data will be written.
  303. *
  304. * @param b The basic_streambuf object from which data will be written.
  305. *
  306. * @param completion_condition The function object to be called to determine
  307. * whether the write operation is complete. The signature of the function object
  308. * must be:
  309. * @code std::size_t completion_condition(
  310. * // Result of latest write_some_at operation.
  311. * const asio::error_code& error,
  312. *
  313. * // Number of bytes transferred so far.
  314. * std::size_t bytes_transferred
  315. * ); @endcode
  316. * A return value of 0 indicates that the write operation is complete. A
  317. * non-zero return value indicates the maximum number of bytes to be written on
  318. * the next call to the device's write_some_at function.
  319. *
  320. * @returns The number of bytes transferred.
  321. *
  322. * @throws asio::system_error Thrown on failure.
  323. */
  324. template <typename SyncRandomAccessWriteDevice, typename Allocator,
  325. typename CompletionCondition>
  326. std::size_t write_at(SyncRandomAccessWriteDevice& d, uint64_t offset,
  327. basic_streambuf<Allocator>& b, CompletionCondition completion_condition);
  328. /// Write a certain amount of data at a specified offset before returning.
  329. /**
  330. * This function is used to write a certain number of bytes of data to a random
  331. * access device at a specified offset. The call will block until one of the
  332. * following conditions is true:
  333. *
  334. * @li All of the data in the supplied basic_streambuf has been written.
  335. *
  336. * @li The completion_condition function object returns 0.
  337. *
  338. * This operation is implemented in terms of zero or more calls to the device's
  339. * write_some_at function.
  340. *
  341. * @param d The device to which the data is to be written. The type must support
  342. * the SyncRandomAccessWriteDevice concept.
  343. *
  344. * @param offset The offset at which the data will be written.
  345. *
  346. * @param b The basic_streambuf object from which data will be written.
  347. *
  348. * @param completion_condition The function object to be called to determine
  349. * whether the write operation is complete. The signature of the function object
  350. * must be:
  351. * @code std::size_t completion_condition(
  352. * // Result of latest write_some_at operation.
  353. * const asio::error_code& error,
  354. *
  355. * // Number of bytes transferred so far.
  356. * std::size_t bytes_transferred
  357. * ); @endcode
  358. * A return value of 0 indicates that the write operation is complete. A
  359. * non-zero return value indicates the maximum number of bytes to be written on
  360. * the next call to the device's write_some_at function.
  361. *
  362. * @param ec Set to indicate what error occurred, if any.
  363. *
  364. * @returns The number of bytes written. If an error occurs, returns the total
  365. * number of bytes successfully transferred prior to the error.
  366. */
  367. template <typename SyncRandomAccessWriteDevice, typename Allocator,
  368. typename CompletionCondition>
  369. std::size_t write_at(SyncRandomAccessWriteDevice& d, uint64_t offset,
  370. basic_streambuf<Allocator>& b, CompletionCondition completion_condition,
  371. asio::error_code& ec);
  372. #endif // !defined(ASIO_NO_IOSTREAM)
  373. #endif // !defined(ASIO_NO_EXTENSIONS)
  374. /*@}*/
  375. /**
  376. * @defgroup async_write_at asio::async_write_at
  377. *
  378. * @brief The @c async_write_at function is a composed asynchronous operation
  379. * that writes a certain amount of data at the specified offset before
  380. * completion.
  381. */
  382. /*@{*/
  383. /// Start an asynchronous operation to write all of the supplied data at the
  384. /// specified offset.
  385. /**
  386. * This function is used to asynchronously write a certain number of bytes of
  387. * data to a random access device at a 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 All of the data in the supplied buffers has been written. That is, the
  392. * bytes transferred is equal to 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_write_some_at function, and is known as a <em>composed operation</em>.
  398. * The program must ensure that the device performs no <em>overlapping</em>
  399. * write operations (such as async_write_at, the device's async_write_some_at
  400. * function, or any other composed operations that perform writes) until this
  401. * operation completes. Operations are overlapping if the regions defined by
  402. * their offsets, and the numbers of bytes to write, intersect.
  403. *
  404. * @param d The device to which the data is to be written. The type must support
  405. * the AsyncRandomAccessWriteDevice concept.
  406. *
  407. * @param offset The offset at which the data will be written.
  408. *
  409. * @param buffers One or more buffers containing the data to be written.
  410. * Although the buffers object may be copied as necessary, ownership of the
  411. * underlying memory blocks is retained by the caller, which must guarantee
  412. * that they remain valid until the handler is called.
  413. *
  414. * @param handler The handler to be called when the write operation completes.
  415. * Copies will be made of the handler as required. The function signature of
  416. * the handler must be:
  417. * @code void handler(
  418. * // Result of operation.
  419. * const asio::error_code& error,
  420. *
  421. * // Number of bytes written from the buffers. If an error
  422. * // occurred, this will be less than the sum of the buffer sizes.
  423. * std::size_t bytes_transferred
  424. * ); @endcode
  425. * Regardless of whether the asynchronous operation completes immediately or
  426. * not, the handler will not be invoked from within this function. On
  427. * immediate completion, invocation of the handler will be performed in a
  428. * manner equivalent to using asio::post().
  429. *
  430. * @par Example
  431. * To write a single data buffer use the @ref buffer function as follows:
  432. * @code
  433. * asio::async_write_at(d, 42, asio::buffer(data, size), handler);
  434. * @endcode
  435. * See the @ref buffer documentation for information on writing multiple
  436. * buffers in one go, and how to use it with arrays, boost::array or
  437. * std::vector.
  438. */
  439. template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
  440. typename WriteHandler>
  441. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  442. void (asio::error_code, std::size_t))
  443. async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset,
  444. const ConstBufferSequence& buffers,
  445. ASIO_MOVE_ARG(WriteHandler) handler);
  446. /// Start an asynchronous operation to write a certain amount of data at the
  447. /// specified offset.
  448. /**
  449. * This function is used to asynchronously write a certain number of bytes of
  450. * data to a random access device at a specified offset. The function call
  451. * always returns immediately. The asynchronous operation will continue until
  452. * one of the following conditions is true:
  453. *
  454. * @li All of the data in the supplied buffers has been written. That is, the
  455. * bytes transferred is equal to the sum of the buffer sizes.
  456. *
  457. * @li The completion_condition function object returns 0.
  458. *
  459. * This operation is implemented in terms of zero or more calls to the device's
  460. * async_write_some_at function, and is known as a <em>composed operation</em>.
  461. * The program must ensure that the device performs no <em>overlapping</em>
  462. * write operations (such as async_write_at, the device's async_write_some_at
  463. * function, or any other composed operations that perform writes) until this
  464. * operation completes. Operations are overlapping if the regions defined by
  465. * their offsets, and the numbers of bytes to write, intersect.
  466. *
  467. * @param d The device to which the data is to be written. The type must support
  468. * the AsyncRandomAccessWriteDevice concept.
  469. *
  470. * @param offset The offset at which the data will be written.
  471. *
  472. * @param buffers One or more buffers containing the data to be written.
  473. * Although the buffers object may be copied as necessary, ownership of the
  474. * underlying memory blocks is retained by the caller, which must guarantee
  475. * that they remain valid until the handler is called.
  476. *
  477. * @param completion_condition The function object to be called to determine
  478. * whether the write operation is complete. The signature of the function object
  479. * must be:
  480. * @code std::size_t completion_condition(
  481. * // Result of latest async_write_some_at operation.
  482. * const asio::error_code& error,
  483. *
  484. * // Number of bytes transferred so far.
  485. * std::size_t bytes_transferred
  486. * ); @endcode
  487. * A return value of 0 indicates that the write operation is complete. A
  488. * non-zero return value indicates the maximum number of bytes to be written on
  489. * the next call to the device's async_write_some_at function.
  490. *
  491. * @param handler The handler to be called when the write operation completes.
  492. * Copies will be made of the handler as required. The function signature of the
  493. * handler must be:
  494. * @code void handler(
  495. * // Result of operation.
  496. * const asio::error_code& error,
  497. *
  498. * // Number of bytes written from the buffers. If an error
  499. * // occurred, this will be less than the sum of the buffer sizes.
  500. * std::size_t bytes_transferred
  501. * ); @endcode
  502. * Regardless of whether the asynchronous operation completes immediately or
  503. * not, the handler will not be invoked from within this function. On
  504. * immediate completion, invocation of the handler will be performed in a
  505. * manner equivalent to using asio::post().
  506. *
  507. * @par Example
  508. * To write a single data buffer use the @ref buffer function as follows:
  509. * @code asio::async_write_at(d, 42,
  510. * asio::buffer(data, size),
  511. * asio::transfer_at_least(32),
  512. * handler); @endcode
  513. * See the @ref buffer documentation for information on writing multiple
  514. * buffers in one go, and how to use it with arrays, boost::array or
  515. * std::vector.
  516. */
  517. template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
  518. typename CompletionCondition, typename WriteHandler>
  519. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  520. void (asio::error_code, std::size_t))
  521. async_write_at(AsyncRandomAccessWriteDevice& d,
  522. uint64_t offset, const ConstBufferSequence& buffers,
  523. CompletionCondition completion_condition,
  524. ASIO_MOVE_ARG(WriteHandler) handler);
  525. #if !defined(ASIO_NO_EXTENSIONS)
  526. #if !defined(ASIO_NO_IOSTREAM)
  527. /// Start an asynchronous operation to write all of the supplied data at the
  528. /// specified offset.
  529. /**
  530. * This function is used to asynchronously write a certain number of bytes of
  531. * data to a random access device at a specified offset. The function call
  532. * always returns immediately. The asynchronous operation will continue until
  533. * one of the following conditions is true:
  534. *
  535. * @li All of the data in the supplied basic_streambuf has been written.
  536. *
  537. * @li An error occurred.
  538. *
  539. * This operation is implemented in terms of zero or more calls to the device's
  540. * async_write_some_at function, and is known as a <em>composed operation</em>.
  541. * The program must ensure that the device performs no <em>overlapping</em>
  542. * write operations (such as async_write_at, the device's async_write_some_at
  543. * function, or any other composed operations that perform writes) until this
  544. * operation completes. Operations are overlapping if the regions defined by
  545. * their offsets, and the numbers of bytes to write, intersect.
  546. *
  547. * @param d The device to which the data is to be written. The type must support
  548. * the AsyncRandomAccessWriteDevice concept.
  549. *
  550. * @param offset The offset at which the data will be written.
  551. *
  552. * @param b A basic_streambuf object from which data will be written. Ownership
  553. * of the streambuf is retained by the caller, which must guarantee that it
  554. * remains valid until the handler is called.
  555. *
  556. * @param handler The handler to be called when the write operation completes.
  557. * Copies will be made of the handler as required. The function signature of the
  558. * handler must be:
  559. * @code void handler(
  560. * // Result of operation.
  561. * const asio::error_code& error,
  562. *
  563. * // Number of bytes written from the buffers. If an error
  564. * // occurred, this will be less than the sum of the buffer sizes.
  565. * std::size_t bytes_transferred
  566. * ); @endcode
  567. * Regardless of whether the asynchronous operation completes immediately or
  568. * not, the handler will not be invoked from within this function. On
  569. * immediate completion, invocation of the handler will be performed in a
  570. * manner equivalent to using asio::post().
  571. */
  572. template <typename AsyncRandomAccessWriteDevice, typename Allocator,
  573. typename WriteHandler>
  574. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  575. void (asio::error_code, std::size_t))
  576. async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset,
  577. basic_streambuf<Allocator>& b, ASIO_MOVE_ARG(WriteHandler) handler);
  578. /// Start an asynchronous operation to write a certain amount of data at the
  579. /// specified offset.
  580. /**
  581. * This function is used to asynchronously write a certain number of bytes of
  582. * data to a random access device at a specified offset. The function call
  583. * always returns immediately. The asynchronous operation will continue until
  584. * one of the following conditions is true:
  585. *
  586. * @li All of the data in the supplied basic_streambuf has been written.
  587. *
  588. * @li The completion_condition function object returns 0.
  589. *
  590. * This operation is implemented in terms of zero or more calls to the device's
  591. * async_write_some_at function, and is known as a <em>composed operation</em>.
  592. * The program must ensure that the device performs no <em>overlapping</em>
  593. * write operations (such as async_write_at, the device's async_write_some_at
  594. * function, or any other composed operations that perform writes) until this
  595. * operation completes. Operations are overlapping if the regions defined by
  596. * their offsets, and the numbers of bytes to write, intersect.
  597. *
  598. * @param d The device to which the data is to be written. The type must support
  599. * the AsyncRandomAccessWriteDevice concept.
  600. *
  601. * @param offset The offset at which the data will be written.
  602. *
  603. * @param b A basic_streambuf object from which data will be written. Ownership
  604. * of the streambuf is retained by the caller, which must guarantee that it
  605. * remains valid until the handler is called.
  606. *
  607. * @param completion_condition The function object to be called to determine
  608. * whether the write operation is complete. The signature of the function object
  609. * must be:
  610. * @code std::size_t completion_condition(
  611. * // Result of latest async_write_some_at operation.
  612. * const asio::error_code& error,
  613. *
  614. * // Number of bytes transferred so far.
  615. * std::size_t bytes_transferred
  616. * ); @endcode
  617. * A return value of 0 indicates that the write operation is complete. A
  618. * non-zero return value indicates the maximum number of bytes to be written on
  619. * the next call to the device's async_write_some_at function.
  620. *
  621. * @param handler The handler to be called when the write operation completes.
  622. * Copies will be made of the handler as required. The function signature of the
  623. * handler must be:
  624. * @code void handler(
  625. * // Result of operation.
  626. * const asio::error_code& error,
  627. *
  628. * // Number of bytes written from the buffers. If an error
  629. * // occurred, this will be less than the sum of the buffer sizes.
  630. * std::size_t bytes_transferred
  631. * ); @endcode
  632. * Regardless of whether the asynchronous operation completes immediately or
  633. * not, the handler will not be invoked from within this function. On
  634. * immediate completion, invocation of the handler will be performed in a
  635. * manner equivalent to using asio::post().
  636. */
  637. template <typename AsyncRandomAccessWriteDevice, typename Allocator,
  638. typename CompletionCondition, typename WriteHandler>
  639. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  640. void (asio::error_code, std::size_t))
  641. async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset,
  642. basic_streambuf<Allocator>& b, CompletionCondition completion_condition,
  643. ASIO_MOVE_ARG(WriteHandler) handler);
  644. #endif // !defined(ASIO_NO_IOSTREAM)
  645. #endif // !defined(ASIO_NO_EXTENSIONS)
  646. /*@}*/
  647. } // namespace asio
  648. #include "asio/detail/pop_options.hpp"
  649. #include "asio/impl/write_at.hpp"
  650. #endif // ASIO_WRITE_AT_HPP