write.hpp 52 KB

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