write.hpp 59 KB

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