write.hpp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. //
  2. // impl/write.hpp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_HPP
  11. #define BOOST_ASIO_IMPL_WRITE_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_tracking.hpp>
  28. #include <boost/asio/detail/handler_type_requirements.hpp>
  29. #include <boost/asio/detail/non_const_lvalue.hpp>
  30. #include <boost/asio/detail/throw_error.hpp>
  31. #include <boost/asio/detail/push_options.hpp>
  32. namespace boost {
  33. namespace asio {
  34. namespace detail
  35. {
  36. template <typename SyncWriteStream, typename ConstBufferSequence,
  37. typename ConstBufferIterator, typename CompletionCondition>
  38. std::size_t write_buffer_sequence(SyncWriteStream& s,
  39. const ConstBufferSequence& buffers, const ConstBufferIterator&,
  40. CompletionCondition completion_condition, 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. tmp.consume(s.write_some(tmp.prepare(max_size), ec));
  50. else
  51. break;
  52. }
  53. return tmp.total_consumed();
  54. }
  55. } // namespace detail
  56. template <typename SyncWriteStream, typename ConstBufferSequence,
  57. typename CompletionCondition>
  58. inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  59. CompletionCondition completion_condition, boost::system::error_code& ec,
  60. typename constraint<
  61. is_const_buffer_sequence<ConstBufferSequence>::value
  62. >::type)
  63. {
  64. return detail::write_buffer_sequence(s, buffers,
  65. boost::asio::buffer_sequence_begin(buffers),
  66. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  67. }
  68. template <typename SyncWriteStream, typename ConstBufferSequence>
  69. inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  70. typename constraint<
  71. is_const_buffer_sequence<ConstBufferSequence>::value
  72. >::type)
  73. {
  74. boost::system::error_code ec;
  75. std::size_t bytes_transferred = write(s, buffers, transfer_all(), ec);
  76. boost::asio::detail::throw_error(ec, "write");
  77. return bytes_transferred;
  78. }
  79. template <typename SyncWriteStream, typename ConstBufferSequence>
  80. inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  81. boost::system::error_code& ec,
  82. typename constraint<
  83. is_const_buffer_sequence<ConstBufferSequence>::value
  84. >::type)
  85. {
  86. return write(s, buffers, transfer_all(), ec);
  87. }
  88. template <typename SyncWriteStream, typename ConstBufferSequence,
  89. typename CompletionCondition>
  90. inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  91. CompletionCondition completion_condition,
  92. typename constraint<
  93. is_const_buffer_sequence<ConstBufferSequence>::value
  94. >::type)
  95. {
  96. boost::system::error_code ec;
  97. std::size_t bytes_transferred = write(s, buffers,
  98. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  99. boost::asio::detail::throw_error(ec, "write");
  100. return bytes_transferred;
  101. }
  102. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  103. template <typename SyncWriteStream, typename DynamicBuffer_v1,
  104. typename CompletionCondition>
  105. std::size_t write(SyncWriteStream& s,
  106. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  107. CompletionCondition completion_condition, boost::system::error_code& ec,
  108. typename constraint<
  109. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  110. >::type,
  111. typename constraint<
  112. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  113. >::type)
  114. {
  115. typename decay<DynamicBuffer_v1>::type b(
  116. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers));
  117. std::size_t bytes_transferred = write(s, b.data(),
  118. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  119. b.consume(bytes_transferred);
  120. return bytes_transferred;
  121. }
  122. template <typename SyncWriteStream, typename DynamicBuffer_v1>
  123. inline std::size_t write(SyncWriteStream& s,
  124. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  125. typename constraint<
  126. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  127. >::type,
  128. typename constraint<
  129. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  130. >::type)
  131. {
  132. boost::system::error_code ec;
  133. std::size_t bytes_transferred = write(s,
  134. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  135. transfer_all(), ec);
  136. boost::asio::detail::throw_error(ec, "write");
  137. return bytes_transferred;
  138. }
  139. template <typename SyncWriteStream, typename DynamicBuffer_v1>
  140. inline std::size_t write(SyncWriteStream& s,
  141. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  142. boost::system::error_code& ec,
  143. typename constraint<
  144. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  145. >::type,
  146. typename constraint<
  147. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  148. >::type)
  149. {
  150. return write(s, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  151. transfer_all(), ec);
  152. }
  153. template <typename SyncWriteStream, typename DynamicBuffer_v1,
  154. typename CompletionCondition>
  155. inline std::size_t write(SyncWriteStream& s,
  156. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  157. CompletionCondition completion_condition,
  158. typename constraint<
  159. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  160. >::type,
  161. typename constraint<
  162. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  163. >::type)
  164. {
  165. boost::system::error_code ec;
  166. std::size_t bytes_transferred = write(s,
  167. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  168. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  169. boost::asio::detail::throw_error(ec, "write");
  170. return bytes_transferred;
  171. }
  172. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  173. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  174. template <typename SyncWriteStream, typename Allocator,
  175. typename CompletionCondition>
  176. inline std::size_t write(SyncWriteStream& s,
  177. boost::asio::basic_streambuf<Allocator>& b,
  178. CompletionCondition completion_condition, boost::system::error_code& ec)
  179. {
  180. return write(s, basic_streambuf_ref<Allocator>(b),
  181. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  182. }
  183. template <typename SyncWriteStream, typename Allocator>
  184. inline std::size_t write(SyncWriteStream& s,
  185. boost::asio::basic_streambuf<Allocator>& b)
  186. {
  187. return write(s, basic_streambuf_ref<Allocator>(b));
  188. }
  189. template <typename SyncWriteStream, typename Allocator>
  190. inline std::size_t write(SyncWriteStream& s,
  191. boost::asio::basic_streambuf<Allocator>& b,
  192. boost::system::error_code& ec)
  193. {
  194. return write(s, basic_streambuf_ref<Allocator>(b), ec);
  195. }
  196. template <typename SyncWriteStream, typename Allocator,
  197. typename CompletionCondition>
  198. inline std::size_t write(SyncWriteStream& s,
  199. boost::asio::basic_streambuf<Allocator>& b,
  200. CompletionCondition completion_condition)
  201. {
  202. return write(s, basic_streambuf_ref<Allocator>(b),
  203. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
  204. }
  205. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  206. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  207. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  208. template <typename SyncWriteStream, typename DynamicBuffer_v2,
  209. typename CompletionCondition>
  210. std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  211. CompletionCondition completion_condition, boost::system::error_code& ec,
  212. typename constraint<
  213. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  214. >::type)
  215. {
  216. std::size_t bytes_transferred = write(s, buffers.data(0, buffers.size()),
  217. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  218. buffers.consume(bytes_transferred);
  219. return bytes_transferred;
  220. }
  221. template <typename SyncWriteStream, typename DynamicBuffer_v2>
  222. inline std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  223. typename constraint<
  224. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  225. >::type)
  226. {
  227. boost::system::error_code ec;
  228. std::size_t bytes_transferred = write(s,
  229. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  230. transfer_all(), ec);
  231. boost::asio::detail::throw_error(ec, "write");
  232. return bytes_transferred;
  233. }
  234. template <typename SyncWriteStream, typename DynamicBuffer_v2>
  235. inline std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  236. boost::system::error_code& ec,
  237. typename constraint<
  238. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  239. >::type)
  240. {
  241. return write(s, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  242. transfer_all(), ec);
  243. }
  244. template <typename SyncWriteStream, typename DynamicBuffer_v2,
  245. typename CompletionCondition>
  246. inline std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  247. CompletionCondition completion_condition,
  248. typename constraint<
  249. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  250. >::type)
  251. {
  252. boost::system::error_code ec;
  253. std::size_t bytes_transferred = write(s,
  254. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  255. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
  256. boost::asio::detail::throw_error(ec, "write");
  257. return bytes_transferred;
  258. }
  259. namespace detail
  260. {
  261. template <typename AsyncWriteStream, typename ConstBufferSequence,
  262. typename ConstBufferIterator, typename CompletionCondition,
  263. typename WriteHandler>
  264. class write_op
  265. : detail::base_from_completion_cond<CompletionCondition>
  266. {
  267. public:
  268. write_op(AsyncWriteStream& stream, const ConstBufferSequence& buffers,
  269. CompletionCondition& completion_condition, WriteHandler& handler)
  270. : detail::base_from_completion_cond<
  271. CompletionCondition>(completion_condition),
  272. stream_(stream),
  273. buffers_(buffers),
  274. start_(0),
  275. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
  276. {
  277. }
  278. #if defined(BOOST_ASIO_HAS_MOVE)
  279. write_op(const write_op& other)
  280. : detail::base_from_completion_cond<CompletionCondition>(other),
  281. stream_(other.stream_),
  282. buffers_(other.buffers_),
  283. start_(other.start_),
  284. handler_(other.handler_)
  285. {
  286. }
  287. write_op(write_op&& other)
  288. : detail::base_from_completion_cond<CompletionCondition>(
  289. BOOST_ASIO_MOVE_CAST(detail::base_from_completion_cond<
  290. CompletionCondition>)(other)),
  291. stream_(other.stream_),
  292. buffers_(BOOST_ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
  293. start_(other.start_),
  294. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
  295. {
  296. }
  297. #endif // defined(BOOST_ASIO_HAS_MOVE)
  298. void operator()(const boost::system::error_code& ec,
  299. std::size_t bytes_transferred, int start = 0)
  300. {
  301. std::size_t max_size;
  302. switch (start_ = start)
  303. {
  304. case 1:
  305. max_size = this->check_for_completion(ec, buffers_.total_consumed());
  306. do
  307. {
  308. {
  309. BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_write"));
  310. stream_.async_write_some(buffers_.prepare(max_size),
  311. BOOST_ASIO_MOVE_CAST(write_op)(*this));
  312. }
  313. return; default:
  314. buffers_.consume(bytes_transferred);
  315. if ((!ec && bytes_transferred == 0) || buffers_.empty())
  316. break;
  317. max_size = this->check_for_completion(ec, buffers_.total_consumed());
  318. } while (max_size > 0);
  319. handler_(ec, buffers_.total_consumed());
  320. }
  321. }
  322. //private:
  323. typedef boost::asio::detail::consuming_buffers<const_buffer,
  324. ConstBufferSequence, ConstBufferIterator> buffers_type;
  325. AsyncWriteStream& stream_;
  326. buffers_type buffers_;
  327. int start_;
  328. WriteHandler handler_;
  329. };
  330. template <typename AsyncWriteStream, typename ConstBufferSequence,
  331. typename ConstBufferIterator, typename CompletionCondition,
  332. typename WriteHandler>
  333. inline asio_handler_allocate_is_deprecated
  334. asio_handler_allocate(std::size_t size,
  335. write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
  336. CompletionCondition, WriteHandler>* this_handler)
  337. {
  338. #if defined(BOOST_ASIO_NO_DEPRECATED)
  339. boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
  340. return asio_handler_allocate_is_no_longer_used();
  341. #else // defined(BOOST_ASIO_NO_DEPRECATED)
  342. return boost_asio_handler_alloc_helpers::allocate(
  343. size, this_handler->handler_);
  344. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  345. }
  346. template <typename AsyncWriteStream, typename ConstBufferSequence,
  347. typename ConstBufferIterator, typename CompletionCondition,
  348. typename WriteHandler>
  349. inline asio_handler_deallocate_is_deprecated
  350. asio_handler_deallocate(void* pointer, std::size_t size,
  351. write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
  352. CompletionCondition, WriteHandler>* this_handler)
  353. {
  354. boost_asio_handler_alloc_helpers::deallocate(
  355. pointer, size, this_handler->handler_);
  356. #if defined(BOOST_ASIO_NO_DEPRECATED)
  357. return asio_handler_deallocate_is_no_longer_used();
  358. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  359. }
  360. template <typename AsyncWriteStream, typename ConstBufferSequence,
  361. typename ConstBufferIterator, typename CompletionCondition,
  362. typename WriteHandler>
  363. inline bool asio_handler_is_continuation(
  364. write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
  365. CompletionCondition, WriteHandler>* this_handler)
  366. {
  367. return this_handler->start_ == 0 ? true
  368. : boost_asio_handler_cont_helpers::is_continuation(
  369. this_handler->handler_);
  370. }
  371. template <typename Function, typename AsyncWriteStream,
  372. typename ConstBufferSequence, typename ConstBufferIterator,
  373. typename CompletionCondition, typename WriteHandler>
  374. inline asio_handler_invoke_is_deprecated
  375. asio_handler_invoke(Function& function,
  376. write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
  377. CompletionCondition, WriteHandler>* this_handler)
  378. {
  379. boost_asio_handler_invoke_helpers::invoke(
  380. function, this_handler->handler_);
  381. #if defined(BOOST_ASIO_NO_DEPRECATED)
  382. return asio_handler_invoke_is_no_longer_used();
  383. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  384. }
  385. template <typename Function, typename AsyncWriteStream,
  386. typename ConstBufferSequence, typename ConstBufferIterator,
  387. typename CompletionCondition, typename WriteHandler>
  388. inline asio_handler_invoke_is_deprecated
  389. asio_handler_invoke(const Function& function,
  390. write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
  391. CompletionCondition, WriteHandler>* this_handler)
  392. {
  393. boost_asio_handler_invoke_helpers::invoke(
  394. function, this_handler->handler_);
  395. #if defined(BOOST_ASIO_NO_DEPRECATED)
  396. return asio_handler_invoke_is_no_longer_used();
  397. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  398. }
  399. template <typename AsyncWriteStream, typename ConstBufferSequence,
  400. typename ConstBufferIterator, typename CompletionCondition,
  401. typename WriteHandler>
  402. inline void start_write_buffer_sequence_op(AsyncWriteStream& stream,
  403. const ConstBufferSequence& buffers, const ConstBufferIterator&,
  404. CompletionCondition& completion_condition, WriteHandler& handler)
  405. {
  406. detail::write_op<AsyncWriteStream, ConstBufferSequence,
  407. ConstBufferIterator, CompletionCondition, WriteHandler>(
  408. stream, buffers, completion_condition, handler)(
  409. boost::system::error_code(), 0, 1);
  410. }
  411. template <typename AsyncWriteStream>
  412. class initiate_async_write_buffer_sequence
  413. {
  414. public:
  415. typedef typename AsyncWriteStream::executor_type executor_type;
  416. explicit initiate_async_write_buffer_sequence(AsyncWriteStream& stream)
  417. : stream_(stream)
  418. {
  419. }
  420. executor_type get_executor() const BOOST_ASIO_NOEXCEPT
  421. {
  422. return stream_.get_executor();
  423. }
  424. template <typename WriteHandler, typename ConstBufferSequence,
  425. typename CompletionCondition>
  426. void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  427. const ConstBufferSequence& buffers,
  428. BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
  429. {
  430. // If you get an error on the following line it means that your handler
  431. // does not meet the documented type requirements for a WriteHandler.
  432. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
  433. non_const_lvalue<WriteHandler> handler2(handler);
  434. non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
  435. start_write_buffer_sequence_op(stream_, buffers,
  436. boost::asio::buffer_sequence_begin(buffers),
  437. completion_cond2.value, handler2.value);
  438. }
  439. private:
  440. AsyncWriteStream& stream_;
  441. };
  442. } // namespace detail
  443. #if !defined(GENERATING_DOCUMENTATION)
  444. template <typename AsyncWriteStream, typename ConstBufferSequence,
  445. typename ConstBufferIterator, typename CompletionCondition,
  446. typename WriteHandler, typename Allocator>
  447. struct associated_allocator<
  448. detail::write_op<AsyncWriteStream, ConstBufferSequence,
  449. ConstBufferIterator, CompletionCondition, WriteHandler>,
  450. Allocator>
  451. {
  452. typedef typename associated_allocator<WriteHandler, Allocator>::type type;
  453. static type get(
  454. const detail::write_op<AsyncWriteStream, ConstBufferSequence,
  455. ConstBufferIterator, CompletionCondition, WriteHandler>& h,
  456. const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
  457. {
  458. return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
  459. }
  460. };
  461. template <typename AsyncWriteStream, typename ConstBufferSequence,
  462. typename ConstBufferIterator, typename CompletionCondition,
  463. typename WriteHandler, typename Executor>
  464. struct associated_executor<
  465. detail::write_op<AsyncWriteStream, ConstBufferSequence,
  466. ConstBufferIterator, CompletionCondition, WriteHandler>,
  467. Executor>
  468. : detail::associated_executor_forwarding_base<WriteHandler, Executor>
  469. {
  470. typedef typename associated_executor<WriteHandler, Executor>::type type;
  471. static type get(
  472. const detail::write_op<AsyncWriteStream, ConstBufferSequence,
  473. ConstBufferIterator, CompletionCondition, WriteHandler>& h,
  474. const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
  475. {
  476. return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
  477. }
  478. };
  479. #endif // !defined(GENERATING_DOCUMENTATION)
  480. template <typename AsyncWriteStream,
  481. typename ConstBufferSequence, typename CompletionCondition,
  482. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  483. std::size_t)) WriteHandler>
  484. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  485. void (boost::system::error_code, std::size_t))
  486. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  487. CompletionCondition completion_condition,
  488. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  489. typename constraint<
  490. is_const_buffer_sequence<ConstBufferSequence>::value
  491. >::type)
  492. {
  493. return async_initiate<WriteHandler,
  494. void (boost::system::error_code, std::size_t)>(
  495. detail::initiate_async_write_buffer_sequence<AsyncWriteStream>(s),
  496. handler, buffers,
  497. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
  498. }
  499. template <typename AsyncWriteStream, typename ConstBufferSequence,
  500. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  501. std::size_t)) WriteHandler>
  502. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  503. void (boost::system::error_code, std::size_t))
  504. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  505. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  506. typename constraint<
  507. is_const_buffer_sequence<ConstBufferSequence>::value
  508. >::type)
  509. {
  510. return async_initiate<WriteHandler,
  511. void (boost::system::error_code, std::size_t)>(
  512. detail::initiate_async_write_buffer_sequence<AsyncWriteStream>(s),
  513. handler, buffers, transfer_all());
  514. }
  515. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  516. namespace detail
  517. {
  518. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  519. typename CompletionCondition, typename WriteHandler>
  520. class write_dynbuf_v1_op
  521. {
  522. public:
  523. template <typename BufferSequence>
  524. write_dynbuf_v1_op(AsyncWriteStream& stream,
  525. BOOST_ASIO_MOVE_ARG(BufferSequence) buffers,
  526. CompletionCondition& completion_condition, WriteHandler& handler)
  527. : stream_(stream),
  528. buffers_(BOOST_ASIO_MOVE_CAST(BufferSequence)(buffers)),
  529. completion_condition_(
  530. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition)),
  531. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
  532. {
  533. }
  534. #if defined(BOOST_ASIO_HAS_MOVE)
  535. write_dynbuf_v1_op(const write_dynbuf_v1_op& other)
  536. : stream_(other.stream_),
  537. buffers_(other.buffers_),
  538. completion_condition_(other.completion_condition_),
  539. handler_(other.handler_)
  540. {
  541. }
  542. write_dynbuf_v1_op(write_dynbuf_v1_op&& other)
  543. : stream_(other.stream_),
  544. buffers_(BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(other.buffers_)),
  545. completion_condition_(
  546. BOOST_ASIO_MOVE_CAST(CompletionCondition)(
  547. other.completion_condition_)),
  548. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
  549. {
  550. }
  551. #endif // defined(BOOST_ASIO_HAS_MOVE)
  552. void operator()(const boost::system::error_code& ec,
  553. std::size_t bytes_transferred, int start = 0)
  554. {
  555. switch (start)
  556. {
  557. case 1:
  558. async_write(stream_, buffers_.data(),
  559. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition_),
  560. BOOST_ASIO_MOVE_CAST(write_dynbuf_v1_op)(*this));
  561. return; default:
  562. buffers_.consume(bytes_transferred);
  563. handler_(ec, static_cast<const std::size_t&>(bytes_transferred));
  564. }
  565. }
  566. //private:
  567. AsyncWriteStream& stream_;
  568. DynamicBuffer_v1 buffers_;
  569. CompletionCondition completion_condition_;
  570. WriteHandler handler_;
  571. };
  572. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  573. typename CompletionCondition, typename WriteHandler>
  574. inline asio_handler_allocate_is_deprecated
  575. asio_handler_allocate(std::size_t size,
  576. write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
  577. CompletionCondition, WriteHandler>* this_handler)
  578. {
  579. #if defined(BOOST_ASIO_NO_DEPRECATED)
  580. boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
  581. return asio_handler_allocate_is_no_longer_used();
  582. #else // defined(BOOST_ASIO_NO_DEPRECATED)
  583. return boost_asio_handler_alloc_helpers::allocate(
  584. size, this_handler->handler_);
  585. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  586. }
  587. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  588. typename CompletionCondition, typename WriteHandler>
  589. inline asio_handler_deallocate_is_deprecated
  590. asio_handler_deallocate(void* pointer, std::size_t size,
  591. write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
  592. CompletionCondition, WriteHandler>* this_handler)
  593. {
  594. boost_asio_handler_alloc_helpers::deallocate(
  595. pointer, size, this_handler->handler_);
  596. #if defined(BOOST_ASIO_NO_DEPRECATED)
  597. return asio_handler_deallocate_is_no_longer_used();
  598. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  599. }
  600. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  601. typename CompletionCondition, typename WriteHandler>
  602. inline bool asio_handler_is_continuation(
  603. write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
  604. CompletionCondition, WriteHandler>* this_handler)
  605. {
  606. return boost_asio_handler_cont_helpers::is_continuation(
  607. this_handler->handler_);
  608. }
  609. template <typename Function, typename AsyncWriteStream,
  610. typename DynamicBuffer_v1, typename CompletionCondition,
  611. typename WriteHandler>
  612. inline asio_handler_invoke_is_deprecated
  613. asio_handler_invoke(Function& function,
  614. write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
  615. CompletionCondition, WriteHandler>* this_handler)
  616. {
  617. boost_asio_handler_invoke_helpers::invoke(
  618. function, this_handler->handler_);
  619. #if defined(BOOST_ASIO_NO_DEPRECATED)
  620. return asio_handler_invoke_is_no_longer_used();
  621. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  622. }
  623. template <typename Function, typename AsyncWriteStream,
  624. typename DynamicBuffer_v1, typename CompletionCondition,
  625. typename WriteHandler>
  626. inline asio_handler_invoke_is_deprecated
  627. asio_handler_invoke(const Function& function,
  628. write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
  629. CompletionCondition, WriteHandler>* this_handler)
  630. {
  631. boost_asio_handler_invoke_helpers::invoke(
  632. function, this_handler->handler_);
  633. #if defined(BOOST_ASIO_NO_DEPRECATED)
  634. return asio_handler_invoke_is_no_longer_used();
  635. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  636. }
  637. template <typename AsyncWriteStream>
  638. class initiate_async_write_dynbuf_v1
  639. {
  640. public:
  641. typedef typename AsyncWriteStream::executor_type executor_type;
  642. explicit initiate_async_write_dynbuf_v1(AsyncWriteStream& stream)
  643. : stream_(stream)
  644. {
  645. }
  646. executor_type get_executor() const BOOST_ASIO_NOEXCEPT
  647. {
  648. return stream_.get_executor();
  649. }
  650. template <typename WriteHandler, typename DynamicBuffer_v1,
  651. typename CompletionCondition>
  652. void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  653. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  654. BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
  655. {
  656. // If you get an error on the following line it means that your handler
  657. // does not meet the documented type requirements for a WriteHandler.
  658. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
  659. non_const_lvalue<WriteHandler> handler2(handler);
  660. non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
  661. write_dynbuf_v1_op<AsyncWriteStream,
  662. typename decay<DynamicBuffer_v1>::type,
  663. CompletionCondition, typename decay<WriteHandler>::type>(
  664. stream_, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  665. completion_cond2.value, handler2.value)(
  666. boost::system::error_code(), 0, 1);
  667. }
  668. private:
  669. AsyncWriteStream& stream_;
  670. };
  671. } // namespace detail
  672. #if !defined(GENERATING_DOCUMENTATION)
  673. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  674. typename CompletionCondition, typename WriteHandler, typename Allocator>
  675. struct associated_allocator<
  676. detail::write_dynbuf_v1_op<AsyncWriteStream,
  677. DynamicBuffer_v1, CompletionCondition, WriteHandler>,
  678. Allocator>
  679. {
  680. typedef typename associated_allocator<WriteHandler, Allocator>::type type;
  681. static type get(
  682. const detail::write_dynbuf_v1_op<AsyncWriteStream,
  683. DynamicBuffer_v1, CompletionCondition, WriteHandler>& h,
  684. const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
  685. {
  686. return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
  687. }
  688. };
  689. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  690. typename CompletionCondition, typename WriteHandler, typename Executor>
  691. struct associated_executor<
  692. detail::write_dynbuf_v1_op<AsyncWriteStream,
  693. DynamicBuffer_v1, CompletionCondition, WriteHandler>,
  694. Executor>
  695. : detail::associated_executor_forwarding_base<WriteHandler, Executor>
  696. {
  697. typedef typename associated_executor<WriteHandler, Executor>::type type;
  698. static type get(
  699. const detail::write_dynbuf_v1_op<AsyncWriteStream,
  700. DynamicBuffer_v1, CompletionCondition, WriteHandler>& h,
  701. const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
  702. {
  703. return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
  704. }
  705. };
  706. #endif // !defined(GENERATING_DOCUMENTATION)
  707. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  708. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  709. std::size_t)) WriteHandler>
  710. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  711. void (boost::system::error_code, std::size_t))
  712. async_write(AsyncWriteStream& s,
  713. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  714. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  715. typename constraint<
  716. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  717. >::type,
  718. typename constraint<
  719. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  720. >::type)
  721. {
  722. return async_write(s,
  723. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  724. transfer_all(), BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  725. }
  726. template <typename AsyncWriteStream,
  727. typename DynamicBuffer_v1, typename CompletionCondition,
  728. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  729. std::size_t)) WriteHandler>
  730. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  731. void (boost::system::error_code, std::size_t))
  732. async_write(AsyncWriteStream& s,
  733. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  734. CompletionCondition completion_condition,
  735. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  736. typename constraint<
  737. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  738. >::type,
  739. typename constraint<
  740. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  741. >::type)
  742. {
  743. return async_initiate<WriteHandler,
  744. void (boost::system::error_code, std::size_t)>(
  745. detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s),
  746. handler, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
  747. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
  748. }
  749. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  750. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  751. template <typename AsyncWriteStream, typename Allocator,
  752. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  753. std::size_t)) WriteHandler>
  754. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  755. void (boost::system::error_code, std::size_t))
  756. async_write(AsyncWriteStream& s,
  757. boost::asio::basic_streambuf<Allocator>& b,
  758. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  759. {
  760. return async_write(s, basic_streambuf_ref<Allocator>(b),
  761. BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  762. }
  763. template <typename AsyncWriteStream,
  764. typename Allocator, typename CompletionCondition,
  765. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  766. std::size_t)) WriteHandler>
  767. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  768. void (boost::system::error_code, std::size_t))
  769. async_write(AsyncWriteStream& s,
  770. boost::asio::basic_streambuf<Allocator>& b,
  771. CompletionCondition completion_condition,
  772. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  773. {
  774. return async_write(s, basic_streambuf_ref<Allocator>(b),
  775. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition),
  776. BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  777. }
  778. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  779. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  780. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  781. namespace detail
  782. {
  783. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  784. typename CompletionCondition, typename WriteHandler>
  785. class write_dynbuf_v2_op
  786. {
  787. public:
  788. template <typename BufferSequence>
  789. write_dynbuf_v2_op(AsyncWriteStream& stream,
  790. BOOST_ASIO_MOVE_ARG(BufferSequence) buffers,
  791. CompletionCondition& completion_condition, WriteHandler& handler)
  792. : stream_(stream),
  793. buffers_(BOOST_ASIO_MOVE_CAST(BufferSequence)(buffers)),
  794. completion_condition_(
  795. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition)),
  796. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
  797. {
  798. }
  799. #if defined(BOOST_ASIO_HAS_MOVE)
  800. write_dynbuf_v2_op(const write_dynbuf_v2_op& other)
  801. : stream_(other.stream_),
  802. buffers_(other.buffers_),
  803. completion_condition_(other.completion_condition_),
  804. handler_(other.handler_)
  805. {
  806. }
  807. write_dynbuf_v2_op(write_dynbuf_v2_op&& other)
  808. : stream_(other.stream_),
  809. buffers_(BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(other.buffers_)),
  810. completion_condition_(
  811. BOOST_ASIO_MOVE_CAST(CompletionCondition)(
  812. other.completion_condition_)),
  813. handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
  814. {
  815. }
  816. #endif // defined(BOOST_ASIO_HAS_MOVE)
  817. void operator()(const boost::system::error_code& ec,
  818. std::size_t bytes_transferred, int start = 0)
  819. {
  820. switch (start)
  821. {
  822. case 1:
  823. async_write(stream_, buffers_.data(0, buffers_.size()),
  824. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition_),
  825. BOOST_ASIO_MOVE_CAST(write_dynbuf_v2_op)(*this));
  826. return; default:
  827. buffers_.consume(bytes_transferred);
  828. handler_(ec, static_cast<const std::size_t&>(bytes_transferred));
  829. }
  830. }
  831. //private:
  832. AsyncWriteStream& stream_;
  833. DynamicBuffer_v2 buffers_;
  834. CompletionCondition completion_condition_;
  835. WriteHandler handler_;
  836. };
  837. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  838. typename CompletionCondition, typename WriteHandler>
  839. inline asio_handler_allocate_is_deprecated
  840. asio_handler_allocate(std::size_t size,
  841. write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
  842. CompletionCondition, WriteHandler>* this_handler)
  843. {
  844. #if defined(BOOST_ASIO_NO_DEPRECATED)
  845. boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
  846. return asio_handler_allocate_is_no_longer_used();
  847. #else // defined(BOOST_ASIO_NO_DEPRECATED)
  848. return boost_asio_handler_alloc_helpers::allocate(
  849. size, this_handler->handler_);
  850. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  851. }
  852. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  853. typename CompletionCondition, typename WriteHandler>
  854. inline asio_handler_deallocate_is_deprecated
  855. asio_handler_deallocate(void* pointer, std::size_t size,
  856. write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
  857. CompletionCondition, WriteHandler>* this_handler)
  858. {
  859. boost_asio_handler_alloc_helpers::deallocate(
  860. pointer, size, this_handler->handler_);
  861. #if defined(BOOST_ASIO_NO_DEPRECATED)
  862. return asio_handler_deallocate_is_no_longer_used();
  863. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  864. }
  865. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  866. typename CompletionCondition, typename WriteHandler>
  867. inline bool asio_handler_is_continuation(
  868. write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
  869. CompletionCondition, WriteHandler>* this_handler)
  870. {
  871. return boost_asio_handler_cont_helpers::is_continuation(
  872. this_handler->handler_);
  873. }
  874. template <typename Function, typename AsyncWriteStream,
  875. typename DynamicBuffer_v2, typename CompletionCondition,
  876. typename WriteHandler>
  877. inline asio_handler_invoke_is_deprecated
  878. asio_handler_invoke(Function& function,
  879. write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
  880. CompletionCondition, WriteHandler>* this_handler)
  881. {
  882. boost_asio_handler_invoke_helpers::invoke(
  883. function, this_handler->handler_);
  884. #if defined(BOOST_ASIO_NO_DEPRECATED)
  885. return asio_handler_invoke_is_no_longer_used();
  886. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  887. }
  888. template <typename Function, typename AsyncWriteStream,
  889. typename DynamicBuffer_v2, typename CompletionCondition,
  890. typename WriteHandler>
  891. inline asio_handler_invoke_is_deprecated
  892. asio_handler_invoke(const Function& function,
  893. write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
  894. CompletionCondition, WriteHandler>* this_handler)
  895. {
  896. boost_asio_handler_invoke_helpers::invoke(
  897. function, this_handler->handler_);
  898. #if defined(BOOST_ASIO_NO_DEPRECATED)
  899. return asio_handler_invoke_is_no_longer_used();
  900. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  901. }
  902. template <typename AsyncWriteStream>
  903. class initiate_async_write_dynbuf_v2
  904. {
  905. public:
  906. typedef typename AsyncWriteStream::executor_type executor_type;
  907. explicit initiate_async_write_dynbuf_v2(AsyncWriteStream& stream)
  908. : stream_(stream)
  909. {
  910. }
  911. executor_type get_executor() const BOOST_ASIO_NOEXCEPT
  912. {
  913. return stream_.get_executor();
  914. }
  915. template <typename WriteHandler, typename DynamicBuffer_v2,
  916. typename CompletionCondition>
  917. void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  918. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v2) buffers,
  919. BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
  920. {
  921. // If you get an error on the following line it means that your handler
  922. // does not meet the documented type requirements for a WriteHandler.
  923. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
  924. non_const_lvalue<WriteHandler> handler2(handler);
  925. non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
  926. write_dynbuf_v2_op<AsyncWriteStream,
  927. typename decay<DynamicBuffer_v2>::type,
  928. CompletionCondition, typename decay<WriteHandler>::type>(
  929. stream_, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  930. completion_cond2.value, handler2.value)(
  931. boost::system::error_code(), 0, 1);
  932. }
  933. private:
  934. AsyncWriteStream& stream_;
  935. };
  936. } // namespace detail
  937. #if !defined(GENERATING_DOCUMENTATION)
  938. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  939. typename CompletionCondition, typename WriteHandler, typename Allocator>
  940. struct associated_allocator<
  941. detail::write_dynbuf_v2_op<AsyncWriteStream,
  942. DynamicBuffer_v2, CompletionCondition, WriteHandler>,
  943. Allocator>
  944. {
  945. typedef typename associated_allocator<WriteHandler, Allocator>::type type;
  946. static type get(
  947. const detail::write_dynbuf_v2_op<AsyncWriteStream,
  948. DynamicBuffer_v2, CompletionCondition, WriteHandler>& h,
  949. const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
  950. {
  951. return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
  952. }
  953. };
  954. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  955. typename CompletionCondition, typename WriteHandler, typename Executor>
  956. struct associated_executor<
  957. detail::write_dynbuf_v2_op<AsyncWriteStream,
  958. DynamicBuffer_v2, CompletionCondition, WriteHandler>,
  959. Executor>
  960. : detail::associated_executor_forwarding_base<WriteHandler, Executor>
  961. {
  962. typedef typename associated_executor<WriteHandler, Executor>::type type;
  963. static type get(
  964. const detail::write_dynbuf_v2_op<AsyncWriteStream,
  965. DynamicBuffer_v2, CompletionCondition, WriteHandler>& h,
  966. const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
  967. {
  968. return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
  969. }
  970. };
  971. #endif // !defined(GENERATING_DOCUMENTATION)
  972. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  973. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  974. std::size_t)) WriteHandler>
  975. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  976. void (boost::system::error_code, std::size_t))
  977. async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
  978. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  979. typename constraint<
  980. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  981. >::type)
  982. {
  983. return async_write(s,
  984. BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  985. transfer_all(), BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  986. }
  987. template <typename AsyncWriteStream,
  988. typename DynamicBuffer_v2, typename CompletionCondition,
  989. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  990. std::size_t)) WriteHandler>
  991. inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  992. void (boost::system::error_code, std::size_t))
  993. async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
  994. CompletionCondition completion_condition,
  995. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  996. typename constraint<
  997. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  998. >::type)
  999. {
  1000. return async_initiate<WriteHandler,
  1001. void (boost::system::error_code, std::size_t)>(
  1002. detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>(s),
  1003. handler, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
  1004. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
  1005. }
  1006. } // namespace asio
  1007. } // namespace boost
  1008. #include <boost/asio/detail/pop_options.hpp>
  1009. #endif // BOOST_ASIO_IMPL_WRITE_HPP