write.hpp 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. //
  2. // write.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_WRITE_HPP
  11. #define BOOST_ASIO_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/detail/config.hpp>
  16. #include <cstddef>
  17. #include <boost/asio/async_result.hpp>
  18. #include <boost/asio/buffer.hpp>
  19. #include <boost/asio/error.hpp>
  20. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  21. # include <boost/asio/basic_streambuf_fwd.hpp>
  22. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  23. #include <boost/asio/detail/push_options.hpp>
  24. namespace boost {
  25. namespace asio {
  26. /**
  27. * @defgroup write boost::asio::write
  28. *
  29. * @brief The @c write function is a composed operation that writes a certain
  30. * amount of data to a stream before returning.
  31. */
  32. /*@{*/
  33. /// Write all of the supplied data to a stream before returning.
  34. /**
  35. * This function is used to write a certain number of bytes of data to a stream.
  36. * The call will block until one of the following conditions is true:
  37. *
  38. * @li All of the data in the supplied buffers has been written. That is, the
  39. * bytes transferred is equal to the sum of the buffer sizes.
  40. *
  41. * @li An error occurred.
  42. *
  43. * This operation is implemented in terms of zero or more calls to the stream's
  44. * write_some function.
  45. *
  46. * @param s The stream to which the data is to be written. The type must support
  47. * the SyncWriteStream concept.
  48. *
  49. * @param buffers One or more buffers containing the data to be written. The sum
  50. * of the buffer sizes indicates the maximum number of bytes to write to the
  51. * stream.
  52. *
  53. * @returns The number of bytes transferred.
  54. *
  55. * @throws boost::system::system_error Thrown on failure.
  56. *
  57. * @par Example
  58. * To write a single data buffer use the @ref buffer function as follows:
  59. * @code boost::asio::write(s, boost::asio::buffer(data, size)); @endcode
  60. * See the @ref buffer documentation for information on writing multiple
  61. * buffers in one go, and how to use it with arrays, boost::array or
  62. * std::vector.
  63. *
  64. * @note This overload is equivalent to calling:
  65. * @code boost::asio::write(
  66. * s, buffers,
  67. * boost::asio::transfer_all()); @endcode
  68. */
  69. template <typename SyncWriteStream, typename ConstBufferSequence>
  70. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  71. typename enable_if<
  72. is_const_buffer_sequence<ConstBufferSequence>::value
  73. >::type* = 0);
  74. /// Write all of the supplied data to a stream before returning.
  75. /**
  76. * This function is used to write a certain number of bytes of data to a stream.
  77. * The call will block until one of the following conditions is true:
  78. *
  79. * @li All of the data in the supplied buffers has been written. That is, the
  80. * bytes transferred is equal to the sum of the buffer sizes.
  81. *
  82. * @li An error occurred.
  83. *
  84. * This operation is implemented in terms of zero or more calls to the stream's
  85. * write_some function.
  86. *
  87. * @param s The stream to which the data is to be written. The type must support
  88. * the SyncWriteStream concept.
  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. * stream.
  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 boost::asio::write(s, boost::asio::buffer(data, size), ec); @endcode
  101. * See the @ref buffer documentation for information on writing multiple
  102. * buffers in one go, and how to use it with arrays, boost::array or
  103. * std::vector.
  104. *
  105. * @note This overload is equivalent to calling:
  106. * @code boost::asio::write(
  107. * s, buffers,
  108. * boost::asio::transfer_all(), ec); @endcode
  109. */
  110. template <typename SyncWriteStream, typename ConstBufferSequence>
  111. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  112. boost::system::error_code& ec,
  113. typename enable_if<
  114. is_const_buffer_sequence<ConstBufferSequence>::value
  115. >::type* = 0);
  116. /// Write a certain amount of data to a stream before returning.
  117. /**
  118. * This function is used to write a certain number of bytes of data to a stream.
  119. * The call will block until one of the 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 stream's
  127. * write_some function.
  128. *
  129. * @param s The stream to which the data is to be written. The type must support
  130. * the SyncWriteStream concept.
  131. *
  132. * @param buffers One or more buffers containing the data to be written. The sum
  133. * of the buffer sizes indicates the maximum number of bytes to write to the
  134. * stream.
  135. *
  136. * @param completion_condition The function object to be called to determine
  137. * whether the write operation is complete. The signature of the function object
  138. * must be:
  139. * @code std::size_t completion_condition(
  140. * // Result of latest write_some operation.
  141. * const boost::system::error_code& error,
  142. *
  143. * // Number of bytes transferred so far.
  144. * std::size_t bytes_transferred
  145. * ); @endcode
  146. * A return value of 0 indicates that the write operation is complete. A
  147. * non-zero return value indicates the maximum number of bytes to be written on
  148. * the next call to the stream's write_some function.
  149. *
  150. * @returns The number of bytes transferred.
  151. *
  152. * @throws boost::system::system_error Thrown on failure.
  153. *
  154. * @par Example
  155. * To write a single data buffer use the @ref buffer function as follows:
  156. * @code boost::asio::write(s, boost::asio::buffer(data, size),
  157. * boost::asio::transfer_at_least(32)); @endcode
  158. * See the @ref buffer documentation for information on writing multiple
  159. * buffers in one go, and how to use it with arrays, boost::array or
  160. * std::vector.
  161. */
  162. template <typename SyncWriteStream, typename ConstBufferSequence,
  163. typename CompletionCondition>
  164. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  165. CompletionCondition completion_condition,
  166. typename enable_if<
  167. is_const_buffer_sequence<ConstBufferSequence>::value
  168. >::type* = 0);
  169. /// Write a certain amount of data to a stream before returning.
  170. /**
  171. * This function is used to write a certain number of bytes of data to a stream.
  172. * The call will block until one of the following conditions is true:
  173. *
  174. * @li All of the data in the supplied buffers has been written. That is, the
  175. * bytes transferred is equal to the sum of the buffer sizes.
  176. *
  177. * @li The completion_condition function object returns 0.
  178. *
  179. * This operation is implemented in terms of zero or more calls to the stream's
  180. * write_some function.
  181. *
  182. * @param s The stream to which the data is to be written. The type must support
  183. * the SyncWriteStream concept.
  184. *
  185. * @param buffers One or more buffers containing the data to be written. The sum
  186. * of the buffer sizes indicates the maximum number of bytes to write to the
  187. * stream.
  188. *
  189. * @param completion_condition The function object to be called to determine
  190. * whether the write operation is complete. The signature of the function object
  191. * must be:
  192. * @code std::size_t completion_condition(
  193. * // Result of latest write_some operation.
  194. * const boost::system::error_code& error,
  195. *
  196. * // Number of bytes transferred so far.
  197. * std::size_t bytes_transferred
  198. * ); @endcode
  199. * A return value of 0 indicates that the write operation is complete. A
  200. * non-zero return value indicates the maximum number of bytes to be written on
  201. * the next call to the stream's write_some function.
  202. *
  203. * @param ec Set to indicate what error occurred, if any.
  204. *
  205. * @returns The number of bytes written. If an error occurs, returns the total
  206. * number of bytes successfully transferred prior to the error.
  207. */
  208. template <typename SyncWriteStream, typename ConstBufferSequence,
  209. typename CompletionCondition>
  210. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  211. CompletionCondition completion_condition, boost::system::error_code& ec,
  212. typename enable_if<
  213. is_const_buffer_sequence<ConstBufferSequence>::value
  214. >::type* = 0);
  215. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  216. /// Write all of the supplied data to a stream before returning.
  217. /**
  218. * This function is used to write a certain number of bytes of data to a stream.
  219. * The call will block until one of the following conditions is true:
  220. *
  221. * @li All of the data in the supplied dynamic buffer sequence has been written.
  222. *
  223. * @li An error occurred.
  224. *
  225. * This operation is implemented in terms of zero or more calls to the stream's
  226. * write_some function.
  227. *
  228. * @param s The stream to which the data is to be written. The type must support
  229. * the SyncWriteStream concept.
  230. *
  231. * @param buffers The dynamic buffer sequence from which data will be written.
  232. * Successfully written data is automatically consumed from the buffers.
  233. *
  234. * @returns The number of bytes transferred.
  235. *
  236. * @throws boost::system::system_error Thrown on failure.
  237. *
  238. * @note This overload is equivalent to calling:
  239. * @code boost::asio::write(
  240. * s, buffers,
  241. * boost::asio::transfer_all()); @endcode
  242. */
  243. template <typename SyncWriteStream, typename DynamicBuffer_v1>
  244. std::size_t write(SyncWriteStream& s,
  245. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  246. typename enable_if<
  247. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  248. && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  249. >::type* = 0);
  250. /// Write all of the supplied data to a stream before returning.
  251. /**
  252. * This function is used to write a certain number of bytes of data to a stream.
  253. * The call will block until one of the following conditions is true:
  254. *
  255. * @li All of the data in the supplied dynamic buffer sequence has been written.
  256. *
  257. * @li An error occurred.
  258. *
  259. * This operation is implemented in terms of zero or more calls to the stream's
  260. * write_some function.
  261. *
  262. * @param s The stream to which the data is to be written. The type must support
  263. * the SyncWriteStream concept.
  264. *
  265. * @param buffers The dynamic buffer sequence from which data will be written.
  266. * Successfully written data is automatically consumed from the buffers.
  267. *
  268. * @param ec Set to indicate what error occurred, if any.
  269. *
  270. * @returns The number of bytes transferred.
  271. *
  272. * @note This overload is equivalent to calling:
  273. * @code boost::asio::write(
  274. * s, buffers,
  275. * boost::asio::transfer_all(), ec); @endcode
  276. */
  277. template <typename SyncWriteStream, typename DynamicBuffer_v1>
  278. std::size_t write(SyncWriteStream& s,
  279. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  280. boost::system::error_code& ec,
  281. typename enable_if<
  282. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  283. && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  284. >::type* = 0);
  285. /// Write a certain amount of data to a stream before returning.
  286. /**
  287. * This function is used to write a certain number of bytes of data to a stream.
  288. * The call will block until one of the following conditions is true:
  289. *
  290. * @li All of the data in the supplied dynamic buffer sequence has been written.
  291. *
  292. * @li The completion_condition function object returns 0.
  293. *
  294. * This operation is implemented in terms of zero or more calls to the stream's
  295. * write_some function.
  296. *
  297. * @param s The stream to which the data is to be written. The type must support
  298. * the SyncWriteStream concept.
  299. *
  300. * @param buffers The dynamic buffer sequence from which data will be written.
  301. * Successfully written data is automatically consumed from the buffers.
  302. *
  303. * @param completion_condition The function object to be called to determine
  304. * whether the write operation is complete. The signature of the function object
  305. * must be:
  306. * @code std::size_t completion_condition(
  307. * // Result of latest write_some operation.
  308. * const boost::system::error_code& error,
  309. *
  310. * // Number of bytes transferred so far.
  311. * std::size_t bytes_transferred
  312. * ); @endcode
  313. * A return value of 0 indicates that the write operation is complete. A
  314. * non-zero return value indicates the maximum number of bytes to be written on
  315. * the next call to the stream's write_some function.
  316. *
  317. * @returns The number of bytes transferred.
  318. *
  319. * @throws boost::system::system_error Thrown on failure.
  320. */
  321. template <typename SyncWriteStream, typename DynamicBuffer_v1,
  322. typename CompletionCondition>
  323. std::size_t write(SyncWriteStream& s,
  324. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  325. CompletionCondition completion_condition,
  326. typename enable_if<
  327. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  328. && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  329. >::type* = 0);
  330. /// Write a certain amount of data to a stream before returning.
  331. /**
  332. * This function is used to write a certain number of bytes of data to a stream.
  333. * The call will block until one of the following conditions is true:
  334. *
  335. * @li All of the data in the supplied dynamic buffer sequence has been written.
  336. *
  337. * @li The completion_condition function object returns 0.
  338. *
  339. * This operation is implemented in terms of zero or more calls to the stream's
  340. * write_some function.
  341. *
  342. * @param s The stream to which the data is to be written. The type must support
  343. * the SyncWriteStream concept.
  344. *
  345. * @param buffers The dynamic buffer sequence from which data will be written.
  346. * Successfully written data is automatically consumed from the buffers.
  347. *
  348. * @param completion_condition The function object to be called to determine
  349. * whether the write operation is complete. The signature of the function object
  350. * must be:
  351. * @code std::size_t completion_condition(
  352. * // Result of latest write_some operation.
  353. * const boost::system::error_code& error,
  354. *
  355. * // Number of bytes transferred so far.
  356. * std::size_t bytes_transferred
  357. * ); @endcode
  358. * A return value of 0 indicates that the write operation is complete. A
  359. * non-zero return value indicates the maximum number of bytes to be written on
  360. * the next call to the stream's write_some function.
  361. *
  362. * @param ec Set to indicate what error occurred, if any.
  363. *
  364. * @returns The number of bytes written. If an error occurs, returns the total
  365. * number of bytes successfully transferred prior to the error.
  366. */
  367. template <typename SyncWriteStream, typename DynamicBuffer_v1,
  368. typename CompletionCondition>
  369. std::size_t write(SyncWriteStream& s,
  370. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  371. CompletionCondition completion_condition, boost::system::error_code& ec,
  372. typename enable_if<
  373. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  374. && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  375. >::type* = 0);
  376. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  377. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  378. /// Write all of the supplied data to a stream before returning.
  379. /**
  380. * This function is used to write a certain number of bytes of data to a stream.
  381. * The call will block until one of the following conditions is true:
  382. *
  383. * @li All of the data in the supplied basic_streambuf has been written.
  384. *
  385. * @li An error occurred.
  386. *
  387. * This operation is implemented in terms of zero or more calls to the stream's
  388. * write_some function.
  389. *
  390. * @param s The stream to which the data is to be written. The type must support
  391. * the SyncWriteStream concept.
  392. *
  393. * @param b The basic_streambuf object from which data will be written.
  394. *
  395. * @returns The number of bytes transferred.
  396. *
  397. * @throws boost::system::system_error Thrown on failure.
  398. *
  399. * @note This overload is equivalent to calling:
  400. * @code boost::asio::write(
  401. * s, b,
  402. * boost::asio::transfer_all()); @endcode
  403. */
  404. template <typename SyncWriteStream, typename Allocator>
  405. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b);
  406. /// Write all of the supplied data to a stream before returning.
  407. /**
  408. * This function is used to write a certain number of bytes of data to a stream.
  409. * The call will block until one of the following conditions is true:
  410. *
  411. * @li All of the data in the supplied basic_streambuf has been written.
  412. *
  413. * @li An error occurred.
  414. *
  415. * This operation is implemented in terms of zero or more calls to the stream's
  416. * write_some function.
  417. *
  418. * @param s The stream to which the data is to be written. The type must support
  419. * the SyncWriteStream concept.
  420. *
  421. * @param b The basic_streambuf object from which data will be written.
  422. *
  423. * @param ec Set to indicate what error occurred, if any.
  424. *
  425. * @returns The number of bytes transferred.
  426. *
  427. * @note This overload is equivalent to calling:
  428. * @code boost::asio::write(
  429. * s, b,
  430. * boost::asio::transfer_all(), ec); @endcode
  431. */
  432. template <typename SyncWriteStream, typename Allocator>
  433. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
  434. boost::system::error_code& ec);
  435. /// Write a certain amount of data to a stream before returning.
  436. /**
  437. * This function is used to write a certain number of bytes of data to a stream.
  438. * The call will block until one of the following conditions is true:
  439. *
  440. * @li All of the data in the supplied basic_streambuf has been written.
  441. *
  442. * @li The completion_condition function object returns 0.
  443. *
  444. * This operation is implemented in terms of zero or more calls to the stream's
  445. * write_some function.
  446. *
  447. * @param s The stream to which the data is to be written. The type must support
  448. * the SyncWriteStream concept.
  449. *
  450. * @param b The basic_streambuf object from which data will be written.
  451. *
  452. * @param completion_condition The function object to be called to determine
  453. * whether the write operation is complete. The signature of the function object
  454. * must be:
  455. * @code std::size_t completion_condition(
  456. * // Result of latest write_some operation.
  457. * const boost::system::error_code& error,
  458. *
  459. * // Number of bytes transferred so far.
  460. * std::size_t bytes_transferred
  461. * ); @endcode
  462. * A return value of 0 indicates that the write operation is complete. A
  463. * non-zero return value indicates the maximum number of bytes to be written on
  464. * the next call to the stream's write_some function.
  465. *
  466. * @returns The number of bytes transferred.
  467. *
  468. * @throws boost::system::system_error Thrown on failure.
  469. */
  470. template <typename SyncWriteStream, typename Allocator,
  471. typename CompletionCondition>
  472. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
  473. CompletionCondition completion_condition);
  474. /// Write a certain amount of data to a stream before returning.
  475. /**
  476. * This function is used to write a certain number of bytes of data to a stream.
  477. * The call will block until one of the following conditions is true:
  478. *
  479. * @li All of the data in the supplied basic_streambuf has been written.
  480. *
  481. * @li The completion_condition function object returns 0.
  482. *
  483. * This operation is implemented in terms of zero or more calls to the stream's
  484. * write_some function.
  485. *
  486. * @param s The stream to which the data is to be written. The type must support
  487. * the SyncWriteStream concept.
  488. *
  489. * @param b The basic_streambuf object from which data will be written.
  490. *
  491. * @param completion_condition The function object to be called to determine
  492. * whether the write operation is complete. The signature of the function object
  493. * must be:
  494. * @code std::size_t completion_condition(
  495. * // Result of latest write_some operation.
  496. * const boost::system::error_code& error,
  497. *
  498. * // Number of bytes transferred so far.
  499. * std::size_t bytes_transferred
  500. * ); @endcode
  501. * A return value of 0 indicates that the write operation is complete. A
  502. * non-zero return value indicates the maximum number of bytes to be written on
  503. * the next call to the stream's write_some function.
  504. *
  505. * @param ec Set to indicate what error occurred, if any.
  506. *
  507. * @returns The number of bytes written. If an error occurs, returns the total
  508. * number of bytes successfully transferred prior to the error.
  509. */
  510. template <typename SyncWriteStream, typename Allocator,
  511. typename CompletionCondition>
  512. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
  513. CompletionCondition completion_condition, boost::system::error_code& ec);
  514. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  515. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  516. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  517. /// Write all of the supplied data to a stream before returning.
  518. /**
  519. * This function is used to write a certain number of bytes of data to a stream.
  520. * The call will block until one of the following conditions is true:
  521. *
  522. * @li All of the data in the supplied dynamic buffer sequence has been written.
  523. *
  524. * @li An error occurred.
  525. *
  526. * This operation is implemented in terms of zero or more calls to the stream's
  527. * write_some function.
  528. *
  529. * @param s The stream to which the data is to be written. The type must support
  530. * the SyncWriteStream concept.
  531. *
  532. * @param buffers The dynamic buffer sequence from which data will be written.
  533. * Successfully written data is automatically consumed from the buffers.
  534. *
  535. * @returns The number of bytes transferred.
  536. *
  537. * @throws boost::system::system_error Thrown on failure.
  538. *
  539. * @note This overload is equivalent to calling:
  540. * @code boost::asio::write(
  541. * s, buffers,
  542. * boost::asio::transfer_all()); @endcode
  543. */
  544. template <typename SyncWriteStream, typename DynamicBuffer_v2>
  545. std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  546. typename enable_if<
  547. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  548. >::type* = 0);
  549. /// Write all of the supplied data to a stream before returning.
  550. /**
  551. * This function is used to write a certain number of bytes of data to a stream.
  552. * The call will block until one of the following conditions is true:
  553. *
  554. * @li All of the data in the supplied dynamic buffer sequence has been written.
  555. *
  556. * @li An error occurred.
  557. *
  558. * This operation is implemented in terms of zero or more calls to the stream's
  559. * write_some function.
  560. *
  561. * @param s The stream to which the data is to be written. The type must support
  562. * the SyncWriteStream concept.
  563. *
  564. * @param buffers The dynamic buffer sequence from which data will be written.
  565. * Successfully written data is automatically consumed from the buffers.
  566. *
  567. * @param ec Set to indicate what error occurred, if any.
  568. *
  569. * @returns The number of bytes transferred.
  570. *
  571. * @note This overload is equivalent to calling:
  572. * @code boost::asio::write(
  573. * s, buffers,
  574. * boost::asio::transfer_all(), ec); @endcode
  575. */
  576. template <typename SyncWriteStream, typename DynamicBuffer_v2>
  577. std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  578. boost::system::error_code& ec,
  579. typename enable_if<
  580. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  581. >::type* = 0);
  582. /// Write a certain amount of data to a stream before returning.
  583. /**
  584. * This function is used to write a certain number of bytes of data to a stream.
  585. * The call will block until one of the following conditions is true:
  586. *
  587. * @li All of the data in the supplied dynamic buffer sequence has been written.
  588. *
  589. * @li The completion_condition function object returns 0.
  590. *
  591. * This operation is implemented in terms of zero or more calls to the stream's
  592. * write_some function.
  593. *
  594. * @param s The stream to which the data is to be written. The type must support
  595. * the SyncWriteStream concept.
  596. *
  597. * @param buffers The dynamic buffer sequence from which data will be written.
  598. * Successfully written data is automatically consumed from the buffers.
  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 write_some operation.
  605. * const boost::system::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 stream's write_some function.
  613. *
  614. * @returns The number of bytes transferred.
  615. *
  616. * @throws boost::system::system_error Thrown on failure.
  617. */
  618. template <typename SyncWriteStream, typename DynamicBuffer_v2,
  619. typename CompletionCondition>
  620. std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  621. CompletionCondition completion_condition,
  622. typename enable_if<
  623. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  624. >::type* = 0);
  625. /// Write a certain amount of data to a stream before returning.
  626. /**
  627. * This function is used to write a certain number of bytes of data to a stream.
  628. * The call will block until one of the following conditions is true:
  629. *
  630. * @li All of the data in the supplied dynamic buffer sequence has been written.
  631. *
  632. * @li The completion_condition function object returns 0.
  633. *
  634. * This operation is implemented in terms of zero or more calls to the stream's
  635. * write_some function.
  636. *
  637. * @param s The stream to which the data is to be written. The type must support
  638. * the SyncWriteStream concept.
  639. *
  640. * @param buffers The dynamic buffer sequence from which data will be written.
  641. * Successfully written data is automatically consumed from the buffers.
  642. *
  643. * @param completion_condition The function object to be called to determine
  644. * whether the write operation is complete. The signature of the function object
  645. * must be:
  646. * @code std::size_t completion_condition(
  647. * // Result of latest write_some operation.
  648. * const boost::system::error_code& error,
  649. *
  650. * // Number of bytes transferred so far.
  651. * std::size_t bytes_transferred
  652. * ); @endcode
  653. * A return value of 0 indicates that the write operation is complete. A
  654. * non-zero return value indicates the maximum number of bytes to be written on
  655. * the next call to the stream's write_some function.
  656. *
  657. * @param ec Set to indicate what error occurred, if any.
  658. *
  659. * @returns The number of bytes written. If an error occurs, returns the total
  660. * number of bytes successfully transferred prior to the error.
  661. */
  662. template <typename SyncWriteStream, typename DynamicBuffer_v2,
  663. typename CompletionCondition>
  664. std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
  665. CompletionCondition completion_condition, boost::system::error_code& ec,
  666. typename enable_if<
  667. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  668. >::type* = 0);
  669. /*@}*/
  670. /**
  671. * @defgroup async_write boost::asio::async_write
  672. *
  673. * @brief The @c async_write function is a composed asynchronous operation that
  674. * writes a certain amount of data to a stream before completion.
  675. */
  676. /*@{*/
  677. /// Start an asynchronous operation to write all of the supplied data to a
  678. /// stream.
  679. /**
  680. * This function is used to asynchronously write a certain number of bytes of
  681. * data to a stream. The function call always returns immediately. The
  682. * asynchronous operation will continue until one of the following conditions
  683. * is true:
  684. *
  685. * @li All of the data in the supplied buffers has been written. That is, the
  686. * bytes transferred is equal to the sum of the buffer sizes.
  687. *
  688. * @li An error occurred.
  689. *
  690. * This operation is implemented in terms of zero or more calls to the stream's
  691. * async_write_some function, and is known as a <em>composed operation</em>. The
  692. * program must ensure that the stream performs no other write operations (such
  693. * as async_write, the stream's async_write_some function, or any other composed
  694. * operations that perform writes) until this operation completes.
  695. *
  696. * @param s The stream to which the data is to be written. The type must support
  697. * the AsyncWriteStream concept.
  698. *
  699. * @param buffers One or more buffers containing the data to be written.
  700. * Although the buffers object may be copied as necessary, ownership of the
  701. * underlying memory blocks is retained by the caller, which must guarantee
  702. * that they remain valid until the handler is called.
  703. *
  704. * @param handler The handler to be called when the write operation completes.
  705. * Copies will be made of the handler as required. The function signature of
  706. * the handler must be:
  707. * @code void handler(
  708. * const boost::system::error_code& error, // Result of operation.
  709. *
  710. * std::size_t bytes_transferred // Number of bytes written from the
  711. * // buffers. If an error occurred,
  712. * // this will be less than the sum
  713. * // of the buffer sizes.
  714. * ); @endcode
  715. * Regardless of whether the asynchronous operation completes immediately or
  716. * not, the handler will not be invoked from within this function. On
  717. * immediate completion, invocation of the handler will be performed in a
  718. * manner equivalent to using boost::asio::post().
  719. *
  720. * @par Example
  721. * To write a single data buffer use the @ref buffer function as follows:
  722. * @code
  723. * boost::asio::async_write(s, boost::asio::buffer(data, size), handler);
  724. * @endcode
  725. * See the @ref buffer documentation for information on writing multiple
  726. * buffers in one go, and how to use it with arrays, boost::array or
  727. * std::vector.
  728. */
  729. template <typename AsyncWriteStream, typename ConstBufferSequence,
  730. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  731. std::size_t)) WriteHandler
  732. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  733. typename AsyncWriteStream::executor_type)>
  734. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  735. void (boost::system::error_code, std::size_t))
  736. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  737. BOOST_ASIO_MOVE_ARG(WriteHandler) handler
  738. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  739. typename AsyncWriteStream::executor_type),
  740. typename enable_if<
  741. is_const_buffer_sequence<ConstBufferSequence>::value
  742. >::type* = 0);
  743. /// Start an asynchronous operation to write a certain amount of data to a
  744. /// stream.
  745. /**
  746. * This function is used to asynchronously write a certain number of bytes of
  747. * data to a stream. The function call always returns immediately. The
  748. * asynchronous operation will continue until one of the following conditions
  749. * is true:
  750. *
  751. * @li All of the data in the supplied buffers has been written. That is, the
  752. * bytes transferred is equal to the sum of the buffer sizes.
  753. *
  754. * @li The completion_condition function object returns 0.
  755. *
  756. * This operation is implemented in terms of zero or more calls to the stream's
  757. * async_write_some function, and is known as a <em>composed operation</em>. The
  758. * program must ensure that the stream performs no other write operations (such
  759. * as async_write, the stream's async_write_some function, or any other composed
  760. * operations that perform writes) until this operation completes.
  761. *
  762. * @param s The stream to which the data is to be written. The type must support
  763. * the AsyncWriteStream concept.
  764. *
  765. * @param buffers One or more buffers containing the data to be written.
  766. * Although the buffers object may be copied as necessary, ownership of the
  767. * underlying memory blocks is retained by the caller, which must guarantee
  768. * that they remain valid until the handler is called.
  769. *
  770. * @param completion_condition The function object to be called to determine
  771. * whether the write operation is complete. The signature of the function object
  772. * must be:
  773. * @code std::size_t completion_condition(
  774. * // Result of latest async_write_some operation.
  775. * const boost::system::error_code& error,
  776. *
  777. * // Number of bytes transferred so far.
  778. * std::size_t bytes_transferred
  779. * ); @endcode
  780. * A return value of 0 indicates that the write operation is complete. A
  781. * non-zero return value indicates the maximum number of bytes to be written on
  782. * the next call to the stream's async_write_some function.
  783. *
  784. * @param handler The handler to be called when the write operation completes.
  785. * Copies will be made of the handler as required. The function signature of the
  786. * handler must be:
  787. * @code void handler(
  788. * const boost::system::error_code& error, // Result of operation.
  789. *
  790. * std::size_t bytes_transferred // Number of bytes written from the
  791. * // buffers. If an error occurred,
  792. * // this will be less than the sum
  793. * // of the buffer sizes.
  794. * ); @endcode
  795. * Regardless of whether the asynchronous operation completes immediately or
  796. * not, the handler will not be invoked from within this function. On
  797. * immediate completion, invocation of the handler will be performed in a
  798. * manner equivalent to using boost::asio::post().
  799. *
  800. * @par Example
  801. * To write a single data buffer use the @ref buffer function as follows:
  802. * @code boost::asio::async_write(s,
  803. * boost::asio::buffer(data, size),
  804. * boost::asio::transfer_at_least(32),
  805. * handler); @endcode
  806. * See the @ref buffer documentation for information on writing multiple
  807. * buffers in one go, and how to use it with arrays, boost::array or
  808. * std::vector.
  809. */
  810. template <typename AsyncWriteStream,
  811. typename ConstBufferSequence, typename CompletionCondition,
  812. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  813. std::size_t)) WriteHandler>
  814. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  815. void (boost::system::error_code, std::size_t))
  816. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  817. CompletionCondition completion_condition,
  818. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  819. typename enable_if<
  820. is_const_buffer_sequence<ConstBufferSequence>::value
  821. >::type* = 0);
  822. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  823. /// Start an asynchronous operation to write all of the supplied data to a
  824. /// stream.
  825. /**
  826. * This function is used to asynchronously write a certain number of bytes of
  827. * data to a stream. The function call always returns immediately. The
  828. * asynchronous operation will continue until one of the following conditions
  829. * is true:
  830. *
  831. * @li All of the data in the supplied dynamic buffer sequence has been written.
  832. *
  833. * @li An error occurred.
  834. *
  835. * This operation is implemented in terms of zero or more calls to the stream's
  836. * async_write_some function, and is known as a <em>composed operation</em>. The
  837. * program must ensure that the stream performs no other write operations (such
  838. * as async_write, the stream's async_write_some function, or any other composed
  839. * operations that perform writes) until this operation completes.
  840. *
  841. * @param s The stream to which the data is to be written. The type must support
  842. * the AsyncWriteStream concept.
  843. *
  844. * @param buffers The dynamic buffer sequence from which data will be written.
  845. * Although the buffers object may be copied as necessary, ownership of the
  846. * underlying memory blocks is retained by the caller, which must guarantee
  847. * that they remain valid until the handler is called. Successfully written
  848. * data is automatically consumed from the buffers.
  849. *
  850. * @param handler The handler to be called when the write operation completes.
  851. * Copies will be made of the handler as required. The function signature of the
  852. * handler must be:
  853. * @code void handler(
  854. * const boost::system::error_code& error, // Result of operation.
  855. *
  856. * std::size_t bytes_transferred // Number of bytes written from the
  857. * // buffers. If an error occurred,
  858. * // this will be less than the sum
  859. * // of the buffer sizes.
  860. * ); @endcode
  861. * Regardless of whether the asynchronous operation completes immediately or
  862. * not, the handler will not be invoked from within this function. On
  863. * immediate completion, invocation of the handler will be performed in a
  864. * manner equivalent to using boost::asio::post().
  865. */
  866. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  867. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  868. std::size_t)) WriteHandler
  869. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  870. typename AsyncWriteStream::executor_type)>
  871. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  872. void (boost::system::error_code, std::size_t))
  873. async_write(AsyncWriteStream& s,
  874. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  875. BOOST_ASIO_MOVE_ARG(WriteHandler) handler
  876. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  877. typename AsyncWriteStream::executor_type),
  878. typename enable_if<
  879. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  880. && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  881. >::type* = 0);
  882. /// Start an asynchronous operation to write a certain amount of data to a
  883. /// stream.
  884. /**
  885. * This function is used to asynchronously write a certain number of bytes of
  886. * data to a stream. The function call always returns immediately. The
  887. * asynchronous operation will continue until one of the following conditions
  888. * is true:
  889. *
  890. * @li All of the data in the supplied dynamic buffer sequence has been written.
  891. *
  892. * @li The completion_condition function object returns 0.
  893. *
  894. * This operation is implemented in terms of zero or more calls to the stream's
  895. * async_write_some function, and is known as a <em>composed operation</em>. The
  896. * program must ensure that the stream performs no other write operations (such
  897. * as async_write, the stream's async_write_some function, or any other composed
  898. * operations that perform writes) until this operation completes.
  899. *
  900. * @param s The stream to which the data is to be written. The type must support
  901. * the AsyncWriteStream concept.
  902. *
  903. * @param buffers The dynamic buffer sequence from which data will be written.
  904. * Although the buffers object may be copied as necessary, ownership of the
  905. * underlying memory blocks is retained by the caller, which must guarantee
  906. * that they remain valid until the handler is called. Successfully written
  907. * data is automatically consumed from the buffers.
  908. *
  909. * @param completion_condition The function object to be called to determine
  910. * whether the write operation is complete. The signature of the function object
  911. * must be:
  912. * @code std::size_t completion_condition(
  913. * // Result of latest async_write_some operation.
  914. * const boost::system::error_code& error,
  915. *
  916. * // Number of bytes transferred so far.
  917. * std::size_t bytes_transferred
  918. * ); @endcode
  919. * A return value of 0 indicates that the write operation is complete. A
  920. * non-zero return value indicates the maximum number of bytes to be written on
  921. * the next call to the stream's async_write_some function.
  922. *
  923. * @param handler The handler to be called when the write operation completes.
  924. * Copies will be made of the handler as required. The function signature of the
  925. * handler must be:
  926. * @code void handler(
  927. * const boost::system::error_code& error, // Result of operation.
  928. *
  929. * std::size_t bytes_transferred // Number of bytes written from the
  930. * // buffers. If an error occurred,
  931. * // this will be less than the sum
  932. * // of the buffer sizes.
  933. * ); @endcode
  934. * Regardless of whether the asynchronous operation completes immediately or
  935. * not, the handler will not be invoked from within this function. On
  936. * immediate completion, invocation of the handler will be performed in a
  937. * manner equivalent to using boost::asio::post().
  938. */
  939. template <typename AsyncWriteStream,
  940. typename DynamicBuffer_v1, typename CompletionCondition,
  941. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  942. std::size_t)) WriteHandler>
  943. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  944. void (boost::system::error_code, std::size_t))
  945. async_write(AsyncWriteStream& s,
  946. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  947. CompletionCondition completion_condition,
  948. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  949. typename enable_if<
  950. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  951. && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  952. >::type* = 0);
  953. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  954. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  955. /// Start an asynchronous operation to write all of the supplied data to a
  956. /// stream.
  957. /**
  958. * This function is used to asynchronously write a certain number of bytes of
  959. * data to a stream. The function call always returns immediately. The
  960. * asynchronous operation will continue until one of the following conditions
  961. * is true:
  962. *
  963. * @li All of the data in the supplied basic_streambuf has been written.
  964. *
  965. * @li An error occurred.
  966. *
  967. * This operation is implemented in terms of zero or more calls to the stream's
  968. * async_write_some function, and is known as a <em>composed operation</em>. The
  969. * program must ensure that the stream performs no other write operations (such
  970. * as async_write, the stream's async_write_some function, or any other composed
  971. * operations that perform writes) until this operation completes.
  972. *
  973. * @param s The stream to which the data is to be written. The type must support
  974. * the AsyncWriteStream concept.
  975. *
  976. * @param b A basic_streambuf object from which data will be written. Ownership
  977. * of the streambuf is retained by the caller, which must guarantee that it
  978. * remains valid until the handler is called.
  979. *
  980. * @param handler The handler to be called when the write operation completes.
  981. * Copies will be made of the handler as required. The function signature of the
  982. * handler must be:
  983. * @code void handler(
  984. * const boost::system::error_code& error, // Result of operation.
  985. *
  986. * std::size_t bytes_transferred // Number of bytes written from the
  987. * // buffers. If an error occurred,
  988. * // this will be less than the sum
  989. * // of the buffer sizes.
  990. * ); @endcode
  991. * Regardless of whether the asynchronous operation completes immediately or
  992. * not, the handler will not be invoked from within this function. On
  993. * immediate completion, invocation of the handler will be performed in a
  994. * manner equivalent to using boost::asio::post().
  995. */
  996. template <typename AsyncWriteStream, typename Allocator,
  997. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  998. std::size_t)) WriteHandler
  999. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1000. typename AsyncWriteStream::executor_type)>
  1001. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  1002. void (boost::system::error_code, std::size_t))
  1003. async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
  1004. BOOST_ASIO_MOVE_ARG(WriteHandler) handler
  1005. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1006. typename AsyncWriteStream::executor_type));
  1007. /// Start an asynchronous operation to write a certain amount of data to a
  1008. /// stream.
  1009. /**
  1010. * This function is used to asynchronously write a certain number of bytes of
  1011. * data to a stream. The function call always returns immediately. The
  1012. * asynchronous operation will continue until one of the following conditions
  1013. * is true:
  1014. *
  1015. * @li All of the data in the supplied basic_streambuf has been written.
  1016. *
  1017. * @li The completion_condition function object returns 0.
  1018. *
  1019. * This operation is implemented in terms of zero or more calls to the stream's
  1020. * async_write_some function, and is known as a <em>composed operation</em>. The
  1021. * program must ensure that the stream performs no other write operations (such
  1022. * as async_write, the stream's async_write_some function, or any other composed
  1023. * operations that perform writes) until this operation completes.
  1024. *
  1025. * @param s The stream to which the data is to be written. The type must support
  1026. * the AsyncWriteStream concept.
  1027. *
  1028. * @param b A basic_streambuf object from which data will be written. Ownership
  1029. * of the streambuf is retained by the caller, which must guarantee that it
  1030. * remains valid until the handler is called.
  1031. *
  1032. * @param completion_condition The function object to be called to determine
  1033. * whether the write operation is complete. The signature of the function object
  1034. * must be:
  1035. * @code std::size_t completion_condition(
  1036. * // Result of latest async_write_some operation.
  1037. * const boost::system::error_code& error,
  1038. *
  1039. * // Number of bytes transferred so far.
  1040. * std::size_t bytes_transferred
  1041. * ); @endcode
  1042. * A return value of 0 indicates that the write operation is complete. A
  1043. * non-zero return value indicates the maximum number of bytes to be written on
  1044. * the next call to the stream's async_write_some function.
  1045. *
  1046. * @param handler The handler to be called when the write operation completes.
  1047. * Copies will be made of the handler as required. The function signature of the
  1048. * handler must be:
  1049. * @code void handler(
  1050. * const boost::system::error_code& error, // Result of operation.
  1051. *
  1052. * std::size_t bytes_transferred // Number of bytes written from the
  1053. * // buffers. If an error occurred,
  1054. * // this will be less than the sum
  1055. * // of the buffer sizes.
  1056. * ); @endcode
  1057. * Regardless of whether the asynchronous operation completes immediately or
  1058. * not, the handler will not be invoked from within this function. On
  1059. * immediate completion, invocation of the handler will be performed in a
  1060. * manner equivalent to using boost::asio::post().
  1061. */
  1062. template <typename AsyncWriteStream,
  1063. typename Allocator, typename CompletionCondition,
  1064. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1065. std::size_t)) WriteHandler>
  1066. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  1067. void (boost::system::error_code, std::size_t))
  1068. async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
  1069. CompletionCondition completion_condition,
  1070. BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
  1071. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  1072. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  1073. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  1074. /// Start an asynchronous operation to write all of the supplied data to a
  1075. /// stream.
  1076. /**
  1077. * This function is used to asynchronously write a certain number of bytes of
  1078. * data to a stream. The function call always returns immediately. The
  1079. * asynchronous operation will continue until one of the following conditions
  1080. * is true:
  1081. *
  1082. * @li All of the data in the supplied dynamic buffer sequence has been written.
  1083. *
  1084. * @li An error occurred.
  1085. *
  1086. * This operation is implemented in terms of zero or more calls to the stream's
  1087. * async_write_some function, and is known as a <em>composed operation</em>. The
  1088. * program must ensure that the stream performs no other write operations (such
  1089. * as async_write, the stream's async_write_some function, or any other composed
  1090. * operations that perform writes) until this operation completes.
  1091. *
  1092. * @param s The stream to which the data is to be written. The type must support
  1093. * the AsyncWriteStream concept.
  1094. *
  1095. * @param buffers The dynamic buffer sequence from which data will be written.
  1096. * Although the buffers object may be copied as necessary, ownership of the
  1097. * underlying memory blocks is retained by the caller, which must guarantee
  1098. * that they remain valid until the handler is called. Successfully written
  1099. * data is automatically consumed from the buffers.
  1100. *
  1101. * @param handler The handler to be called when the write operation completes.
  1102. * Copies will be made of the handler as required. The function signature of the
  1103. * handler must be:
  1104. * @code void handler(
  1105. * const boost::system::error_code& error, // Result of operation.
  1106. *
  1107. * std::size_t bytes_transferred // Number of bytes written from the
  1108. * // buffers. If an error occurred,
  1109. * // this will be less than the sum
  1110. * // of the buffer sizes.
  1111. * ); @endcode
  1112. * Regardless of whether the asynchronous operation completes immediately or
  1113. * not, the handler will not be invoked from within this function. On
  1114. * immediate completion, invocation of the handler will be performed in a
  1115. * manner equivalent to using boost::asio::post().
  1116. */
  1117. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  1118. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1119. std::size_t)) WriteHandler
  1120. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1121. typename AsyncWriteStream::executor_type)>
  1122. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  1123. void (boost::system::error_code, std::size_t))
  1124. async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
  1125. BOOST_ASIO_MOVE_ARG(WriteHandler) handler
  1126. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1127. typename AsyncWriteStream::executor_type),
  1128. typename enable_if<
  1129. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  1130. >::type* = 0);
  1131. /// Start an asynchronous operation to write a certain amount of data to a
  1132. /// stream.
  1133. /**
  1134. * This function is used to asynchronously write a certain number of bytes of
  1135. * data to a stream. The function call always returns immediately. The
  1136. * asynchronous operation will continue until one of the following conditions
  1137. * is true:
  1138. *
  1139. * @li All of the data in the supplied dynamic buffer sequence has been written.
  1140. *
  1141. * @li The completion_condition function object returns 0.
  1142. *
  1143. * This operation is implemented in terms of zero or more calls to the stream's
  1144. * async_write_some function, and is known as a <em>composed operation</em>. The
  1145. * program must ensure that the stream performs no other write operations (such
  1146. * as async_write, the stream's async_write_some function, or any other composed
  1147. * operations that perform writes) until this operation completes.
  1148. *
  1149. * @param s The stream to which the data is to be written. The type must support
  1150. * the AsyncWriteStream concept.
  1151. *
  1152. * @param buffers The dynamic buffer sequence from which data will be written.
  1153. * Although the buffers object may be copied as necessary, ownership of the
  1154. * underlying memory blocks is retained by the caller, which must guarantee
  1155. * that they remain valid until the handler is called. Successfully written
  1156. * data is automatically consumed from the buffers.
  1157. *
  1158. * @param completion_condition The function object to be called to determine
  1159. * whether the write operation is complete. The signature of the function object
  1160. * must be:
  1161. * @code std::size_t completion_condition(
  1162. * // Result of latest async_write_some operation.
  1163. * const boost::system::error_code& error,
  1164. *
  1165. * // Number of bytes transferred so far.
  1166. * std::size_t bytes_transferred
  1167. * ); @endcode
  1168. * A return value of 0 indicates that the write operation is complete. A
  1169. * non-zero return value indicates the maximum number of bytes to be written on
  1170. * the next call to the stream's async_write_some function.
  1171. *
  1172. * @param handler The handler to be called when the write operation completes.
  1173. * Copies will be made of the handler as required. The function signature of the
  1174. * handler must be:
  1175. * @code void handler(
  1176. * const boost::system::error_code& error, // Result of operation.
  1177. *
  1178. * std::size_t bytes_transferred // Number of bytes written from the
  1179. * // buffers. If an error occurred,
  1180. * // this will be less than the sum
  1181. * // of the buffer sizes.
  1182. * ); @endcode
  1183. * Regardless of whether the asynchronous operation completes immediately or
  1184. * not, the handler will not be invoked from within this function. On
  1185. * immediate completion, invocation of the handler will be performed in a
  1186. * manner equivalent to using boost::asio::post().
  1187. */
  1188. template <typename AsyncWriteStream,
  1189. typename DynamicBuffer_v2, typename CompletionCondition,
  1190. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1191. std::size_t)) WriteHandler>
  1192. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
  1193. void (boost::system::error_code, std::size_t))
  1194. async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
  1195. CompletionCondition completion_condition,
  1196. BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
  1197. typename enable_if<
  1198. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  1199. >::type* = 0);
  1200. /*@}*/
  1201. } // namespace asio
  1202. } // namespace boost
  1203. #include <boost/asio/detail/pop_options.hpp>
  1204. #include <boost/asio/impl/write.hpp>
  1205. #endif // BOOST_ASIO_WRITE_HPP