write_at.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. //
  2. // impl/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 BOOST_ASIO_IMPL_WRITE_AT_HPP
  11. #define BOOST_ASIO_IMPL_WRITE_AT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/associated_allocator.hpp>
  16. #include <boost/asio/associated_executor.hpp>
  17. #include <boost/asio/buffer.hpp>
  18. #include <boost/asio/completion_condition.hpp>
  19. #include <boost/asio/detail/array_fwd.hpp>
  20. #include <boost/asio/detail/base_from_completion_cond.hpp>
  21. #include <boost/asio/detail/bind_handler.hpp>
  22. #include <boost/asio/detail/consuming_buffers.hpp>
  23. #include <boost/asio/detail/dependent_type.hpp>
  24. #include <boost/asio/detail/handler_alloc_helpers.hpp>
  25. #include <boost/asio/detail/handler_cont_helpers.hpp>
  26. #include <boost/asio/detail/handler_invoke_helpers.hpp>
  27. #include <boost/asio/detail/handler_type_requirements.hpp>
  28. #include <boost/asio/detail/non_const_lvalue.hpp>
  29. #include <boost/asio/detail/throw_error.hpp>
  30. #include <boost/asio/detail/push_options.hpp>
  31. namespace boost {
  32. namespace asio {
  33. namespace detail
  34. {
  35. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
  36. typename ConstBufferIterator, typename CompletionCondition>
  37. std::size_t write_at_buffer_sequence(SyncRandomAccessWriteDevice& d,
  38. uint64_t offset, const ConstBufferSequence& buffers,
  39. const ConstBufferIterator&, CompletionCondition completion_condition,
  40. boost::system::error_code& ec)
  41. {
  42. ec = boost::system::error_code();
  43. boost::asio::detail::consuming_buffers<const_buffer,
  44. ConstBufferSequence, ConstBufferIterator> tmp(buffers);
  45. while (!tmp.empty())
  46. {
  47. if (std::size_t max_size = detail::adapt_completion_condition_result(
  48. completion_condition(ec, tmp.total_consumed())))
  49. {
  50. tmp.consume(d.write_some_at(offset + tmp.total_consumed(),
  51. tmp.prepare(max_size), ec));
  52. }
  53. else
  54. break;
  55. }
  56. return tmp.total_consumed();;
  57. }
  58. } // namespace detail
  59. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
  60. typename CompletionCondition>
  61. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  62. uint64_t offset, const ConstBufferSequence& buffers,
  63. CompletionCondition completion_condition, boost::system::error_code& ec)
  64. {
  65. return detail::write_at_buffer_sequence(d, offset, buffers,
  66. boost::asio::buffer_sequence_begin(buffers),
  67. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  68. }
  69. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
  70. inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
  71. uint64_t offset, const ConstBufferSequence& buffers)
  72. {
  73. boost::system::error_code ec;
  74. std::size_t bytes_transferred = write_at(
  75. d, offset, buffers, transfer_all(), ec);
  76. boost::asio::detail::throw_error(ec, "write_at");
  77. return bytes_transferred;
  78. }
  79. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
  80. inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
  81. uint64_t offset, const ConstBufferSequence& buffers,
  82. boost::system::error_code& ec)
  83. {
  84. return write_at(d, offset, buffers, transfer_all(), ec);
  85. }
  86. template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
  87. typename CompletionCondition>
  88. inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
  89. uint64_t offset, const ConstBufferSequence& buffers,
  90. CompletionCondition completion_condition)
  91. {
  92. boost::system::error_code ec;
  93. std::size_t bytes_transferred = write_at(d, offset, buffers,
  94. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  95. boost::asio::detail::throw_error(ec, "write_at");
  96. return bytes_transferred;
  97. }
  98. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  99. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  100. template <typename SyncRandomAccessWriteDevice, typename Allocator,
  101. typename CompletionCondition>
  102. std::size_t write_at(SyncRandomAccessWriteDevice& d,
  103. uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
  104. CompletionCondition completion_condition, boost::system::error_code& ec)
  105. {
  106. std::size_t bytes_transferred = write_at(d, offset, b.data(),
  107. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  108. b.consume(bytes_transferred);
  109. return bytes_transferred;
  110. }
  111. template <typename SyncRandomAccessWriteDevice, typename Allocator>
  112. inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
  113. uint64_t offset, boost::asio::basic_streambuf<Allocator>& b)
  114. {
  115. boost::system::error_code ec;
  116. std::size_t bytes_transferred = write_at(d, offset, b, transfer_all(), ec);
  117. boost::asio::detail::throw_error(ec, "write_at");
  118. return bytes_transferred;
  119. }
  120. template <typename SyncRandomAccessWriteDevice, typename Allocator>
  121. inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
  122. uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
  123. boost::system::error_code& ec)
  124. {
  125. return write_at(d, offset, b, transfer_all(), ec);
  126. }
  127. template <typename SyncRandomAccessWriteDevice, typename Allocator,
  128. typename CompletionCondition>
  129. inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
  130. uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
  131. CompletionCondition completion_condition)
  132. {
  133. boost::system::error_code ec;
  134. std::size_t bytes_transferred = write_at(d, offset, b,
  135. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  136. boost::asio::detail::throw_error(ec, "write_at");
  137. return bytes_transferred;
  138. }
  139. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  140. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  141. namespace detail
  142. {
  143. template <typename AsyncRandomAccessWriteDevice,
  144. typename ConstBufferSequence, typename ConstBufferIterator,
  145. typename CompletionCondition, typename WriteHandler>
  146. class write_at_op
  147. : detail::base_from_completion_cond<CompletionCondition>
  148. {
  149. public:
  150. write_at_op(AsyncRandomAccessWriteDevice& device,
  151. uint64_t offset, const ConstBufferSequence& buffers,
  152. CompletionCondition& completion_condition, WriteHandler& handler)
  153. : detail::base_from_completion_cond<
  154. CompletionCondition>(completion_condition),
  155. device_(device),
  156. offset_(offset),
  157. buffers_(buffers),
  158. start_(0),
  159. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
  160. {
  161. }
  162. #if defined(BOOST_ASIO_HAS_MOVE)
  163. write_at_op(const write_at_op& other)
  164. : detail::base_from_completion_cond<CompletionCondition>(other),
  165. device_(other.device_),
  166. offset_(other.offset_),
  167. buffers_(other.buffers_),
  168. start_(other.start_),
  169. handler_(other.handler_)
  170. {
  171. }
  172. write_at_op(write_at_op&& other)
  173. : detail::base_from_completion_cond<CompletionCondition>(
  174. BOOST_ASIO_MOVE_CAST(detail::base_from_completion_cond<
  175. CompletionCondition>)(other)),
  176. device_(other.device_),
  177. offset_(other.offset_),
  178. buffers_(BOOST_ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
  179. start_(other.start_),
  180. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
  181. {
  182. }
  183. #endif // defined(BOOST_ASIO_HAS_MOVE)
  184. void operator()(const boost::system::error_code& ec,
  185. std::size_t bytes_transferred, int start = 0)
  186. {
  187. std::size_t max_size;
  188. switch (start_ = start)
  189. {
  190. case 1:
  191. max_size = this->check_for_completion(ec, buffers_.total_consumed());
  192. do
  193. {
  194. device_.async_write_some_at(
  195. offset_ + buffers_.total_consumed(), buffers_.prepare(max_size),
  196. BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
  197. return; default:
  198. buffers_.consume(bytes_transferred);
  199. if ((!ec && bytes_transferred == 0) || buffers_.empty())
  200. break;
  201. max_size = this->check_for_completion(ec, buffers_.total_consumed());
  202. } while (max_size > 0);
  203. handler_(ec, buffers_.total_consumed());
  204. }
  205. }
  206. //private:
  207. typedef boost::asio::detail::consuming_buffers<const_buffer,
  208. ConstBufferSequence, ConstBufferIterator> buffers_type;
  209. AsyncRandomAccessWriteDevice& device_;
  210. uint64_t offset_;
  211. buffers_type buffers_;
  212. int start_;
  213. WriteHandler handler_;
  214. };
  215. template <typename AsyncRandomAccessWriteDevice,
  216. typename ConstBufferSequence, typename ConstBufferIterator,
  217. typename CompletionCondition, typename WriteHandler>
  218. inline void* asio_handler_allocate(std::size_t size,
  219. write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  220. ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
  221. {
  222. return boost_asio_handler_alloc_helpers::allocate(
  223. size, this_handler->handler_);
  224. }
  225. template <typename AsyncRandomAccessWriteDevice,
  226. typename ConstBufferSequence, typename ConstBufferIterator,
  227. typename CompletionCondition, typename WriteHandler>
  228. inline void asio_handler_deallocate(void* pointer, std::size_t size,
  229. write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  230. ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
  231. {
  232. boost_asio_handler_alloc_helpers::deallocate(
  233. pointer, size, this_handler->handler_);
  234. }
  235. template <typename AsyncRandomAccessWriteDevice,
  236. typename ConstBufferSequence, typename ConstBufferIterator,
  237. typename CompletionCondition, typename WriteHandler>
  238. inline bool asio_handler_is_continuation(
  239. write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  240. ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
  241. {
  242. return this_handler->start_ == 0 ? true
  243. : boost_asio_handler_cont_helpers::is_continuation(
  244. this_handler->handler_);
  245. }
  246. template <typename Function, typename AsyncRandomAccessWriteDevice,
  247. typename ConstBufferSequence, typename ConstBufferIterator,
  248. typename CompletionCondition, typename WriteHandler>
  249. inline void asio_handler_invoke(Function& function,
  250. write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  251. ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
  252. {
  253. boost_asio_handler_invoke_helpers::invoke(
  254. function, this_handler->handler_);
  255. }
  256. template <typename Function, typename AsyncRandomAccessWriteDevice,
  257. typename ConstBufferSequence, typename ConstBufferIterator,
  258. typename CompletionCondition, typename WriteHandler>
  259. inline void asio_handler_invoke(const Function& function,
  260. write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  261. ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
  262. {
  263. boost_asio_handler_invoke_helpers::invoke(
  264. function, this_handler->handler_);
  265. }
  266. template <typename AsyncRandomAccessWriteDevice,
  267. typename ConstBufferSequence, typename ConstBufferIterator,
  268. typename CompletionCondition, typename WriteHandler>
  269. inline void start_write_at_buffer_sequence_op(AsyncRandomAccessWriteDevice& d,
  270. uint64_t offset, const ConstBufferSequence& buffers,
  271. const ConstBufferIterator&, CompletionCondition& completion_condition,
  272. WriteHandler& handler)
  273. {
  274. detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  275. ConstBufferIterator, CompletionCondition, WriteHandler>(
  276. d, offset, buffers, completion_condition, handler)(
  277. boost::system::error_code(), 0, 1);
  278. }
  279. struct initiate_async_write_at_buffer_sequence
  280. {
  281. template <typename WriteHandler, typename AsyncRandomAccessWriteDevice,
  282. typename ConstBufferSequence, typename CompletionCondition>
  283. void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  284. AsyncRandomAccessWriteDevice* d, uint64_t offset,
  285. const ConstBufferSequence& buffers,
  286. BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
  287. {
  288. // If you get an error on the following line it means that your handler
  289. // does not meet the documented type requirements for a WriteHandler.
  290. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
  291. non_const_lvalue<WriteHandler> handler2(handler);
  292. non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
  293. start_write_at_buffer_sequence_op(*d, offset, buffers,
  294. boost::asio::buffer_sequence_begin(buffers),
  295. completion_cond2.value, handler2.value);
  296. }
  297. };
  298. } // namespace detail
  299. #if !defined(GENERATING_DOCUMENTATION)
  300. template <typename AsyncRandomAccessWriteDevice,
  301. typename ConstBufferSequence, typename ConstBufferIterator,
  302. typename CompletionCondition, typename WriteHandler, typename Allocator>
  303. struct associated_allocator<
  304. detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  305. ConstBufferIterator, CompletionCondition, WriteHandler>,
  306. Allocator>
  307. {
  308. typedef typename associated_allocator<WriteHandler, Allocator>::type type;
  309. static type get(
  310. const detail::write_at_op<AsyncRandomAccessWriteDevice,
  311. ConstBufferSequence, ConstBufferIterator,
  312. CompletionCondition, WriteHandler>& h,
  313. const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
  314. {
  315. return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
  316. }
  317. };
  318. template <typename AsyncRandomAccessWriteDevice,
  319. typename ConstBufferSequence, typename ConstBufferIterator,
  320. typename CompletionCondition, typename WriteHandler, typename Executor>
  321. struct associated_executor<
  322. detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
  323. ConstBufferIterator, CompletionCondition, WriteHandler>,
  324. Executor>
  325. {
  326. typedef typename associated_executor<WriteHandler, Executor>::type type;
  327. static type get(
  328. const detail::write_at_op<AsyncRandomAccessWriteDevice,
  329. ConstBufferSequence, ConstBufferIterator,
  330. CompletionCondition, WriteHandler>& h,
  331. const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
  332. {
  333. return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
  334. }
  335. };
  336. #endif // !defined(GENERATING_DOCUMENTATION)
  337. template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
  338. typename CompletionCondition, typename WriteHandler>
  339. inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
  340. void (boost::system::error_code, std::size_t))
  341. async_write_at(AsyncRandomAccessWriteDevice& d,
  342. uint64_t offset, const ConstBufferSequence& buffers,
  343. CompletionCondition completion_condition,
  344. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  345. {
  346. return async_initiate<WriteHandler,
  347. void (boost::system::error_code, std::size_t)>(
  348. detail::initiate_async_write_at_buffer_sequence(), handler, &d, offset,
  349. buffers, BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
  350. }
  351. template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
  352. typename WriteHandler>
  353. inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
  354. void (boost::system::error_code, std::size_t))
  355. async_write_at(AsyncRandomAccessWriteDevice& d,
  356. uint64_t offset, const ConstBufferSequence& buffers,
  357. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  358. {
  359. return async_initiate<WriteHandler,
  360. void (boost::system::error_code, std::size_t)>(
  361. detail::initiate_async_write_at_buffer_sequence(),
  362. handler, &d, offset, buffers, transfer_all());
  363. }
  364. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  365. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  366. namespace detail
  367. {
  368. template <typename Allocator, typename WriteHandler>
  369. class write_at_streambuf_op
  370. {
  371. public:
  372. write_at_streambuf_op(
  373. boost::asio::basic_streambuf<Allocator>& streambuf,
  374. WriteHandler& handler)
  375. : streambuf_(streambuf),
  376. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
  377. {
  378. }
  379. #if defined(BOOST_ASIO_HAS_MOVE)
  380. write_at_streambuf_op(const write_at_streambuf_op& other)
  381. : streambuf_(other.streambuf_),
  382. handler_(other.handler_)
  383. {
  384. }
  385. write_at_streambuf_op(write_at_streambuf_op&& other)
  386. : streambuf_(other.streambuf_),
  387. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
  388. {
  389. }
  390. #endif // defined(BOOST_ASIO_HAS_MOVE)
  391. void operator()(const boost::system::error_code& ec,
  392. const std::size_t bytes_transferred)
  393. {
  394. streambuf_.consume(bytes_transferred);
  395. handler_(ec, bytes_transferred);
  396. }
  397. //private:
  398. boost::asio::basic_streambuf<Allocator>& streambuf_;
  399. WriteHandler handler_;
  400. };
  401. template <typename Allocator, typename WriteHandler>
  402. inline void* asio_handler_allocate(std::size_t size,
  403. write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
  404. {
  405. return boost_asio_handler_alloc_helpers::allocate(
  406. size, this_handler->handler_);
  407. }
  408. template <typename Allocator, typename WriteHandler>
  409. inline void asio_handler_deallocate(void* pointer, std::size_t size,
  410. write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
  411. {
  412. boost_asio_handler_alloc_helpers::deallocate(
  413. pointer, size, this_handler->handler_);
  414. }
  415. template <typename Allocator, typename WriteHandler>
  416. inline bool asio_handler_is_continuation(
  417. write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
  418. {
  419. return boost_asio_handler_cont_helpers::is_continuation(
  420. this_handler->handler_);
  421. }
  422. template <typename Function, typename Allocator, typename WriteHandler>
  423. inline void asio_handler_invoke(Function& function,
  424. write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
  425. {
  426. boost_asio_handler_invoke_helpers::invoke(
  427. function, this_handler->handler_);
  428. }
  429. template <typename Function, typename Allocator, typename WriteHandler>
  430. inline void asio_handler_invoke(const Function& function,
  431. write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
  432. {
  433. boost_asio_handler_invoke_helpers::invoke(
  434. function, this_handler->handler_);
  435. }
  436. struct initiate_async_write_at_streambuf
  437. {
  438. template <typename WriteHandler, typename AsyncRandomAccessWriteDevice,
  439. typename Allocator, typename CompletionCondition>
  440. void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  441. AsyncRandomAccessWriteDevice* d, uint64_t offset,
  442. basic_streambuf<Allocator>* b,
  443. BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_condition) const
  444. {
  445. // If you get an error on the following line it means that your handler
  446. // does not meet the documented type requirements for a WriteHandler.
  447. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
  448. non_const_lvalue<WriteHandler> handler2(handler);
  449. async_write_at(*d, offset, b->data(),
  450. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition),
  451. write_at_streambuf_op<Allocator, typename decay<WriteHandler>::type>(
  452. *b, handler2.value));
  453. }
  454. };
  455. } // namespace detail
  456. #if !defined(GENERATING_DOCUMENTATION)
  457. template <typename Allocator, typename WriteHandler, typename Allocator1>
  458. struct associated_allocator<
  459. detail::write_at_streambuf_op<Allocator, WriteHandler>,
  460. Allocator1>
  461. {
  462. typedef typename associated_allocator<WriteHandler, Allocator1>::type type;
  463. static type get(
  464. const detail::write_at_streambuf_op<Allocator, WriteHandler>& h,
  465. const Allocator1& a = Allocator1()) BOOST_ASIO_NOEXCEPT
  466. {
  467. return associated_allocator<WriteHandler, Allocator1>::get(h.handler_, a);
  468. }
  469. };
  470. template <typename Executor, typename WriteHandler, typename Executor1>
  471. struct associated_executor<
  472. detail::write_at_streambuf_op<Executor, WriteHandler>,
  473. Executor1>
  474. {
  475. typedef typename associated_executor<WriteHandler, Executor1>::type type;
  476. static type get(
  477. const detail::write_at_streambuf_op<Executor, WriteHandler>& h,
  478. const Executor1& ex = Executor1()) BOOST_ASIO_NOEXCEPT
  479. {
  480. return associated_executor<WriteHandler, Executor1>::get(h.handler_, ex);
  481. }
  482. };
  483. #endif // !defined(GENERATING_DOCUMENTATION)
  484. template <typename AsyncRandomAccessWriteDevice, typename Allocator,
  485. typename CompletionCondition, typename WriteHandler>
  486. inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
  487. void (boost::system::error_code, std::size_t))
  488. async_write_at(AsyncRandomAccessWriteDevice& d,
  489. uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
  490. CompletionCondition completion_condition,
  491. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  492. {
  493. return async_initiate<WriteHandler,
  494. void (boost::system::error_code, std::size_t)>(
  495. detail::initiate_async_write_at_streambuf(), handler, &d, offset,
  496. &b, BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
  497. }
  498. template <typename AsyncRandomAccessWriteDevice, typename Allocator,
  499. typename WriteHandler>
  500. inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
  501. void (boost::system::error_code, std::size_t))
  502. async_write_at(AsyncRandomAccessWriteDevice& d,
  503. uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
  504. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  505. {
  506. return async_initiate<WriteHandler,
  507. void (boost::system::error_code, std::size_t)>(
  508. detail::initiate_async_write_at_streambuf(),
  509. handler, &d, offset, &b, transfer_all());
  510. }
  511. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  512. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  513. } // namespace asio
  514. } // namespace boost
  515. #include <boost/asio/detail/pop_options.hpp>
  516. #endif // BOOST_ASIO_IMPL_WRITE_AT_HPP