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.

671 lines
27KB

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