write.hpp 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  1. //
  2. // write.hpp
  3. // ~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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. It is an initiating function for an @ref
  690. * asynchronous_operation, and always returns immediately. The asynchronous
  691. * operation will continue until one of the following conditions 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 completion handler is called.
  711. *
  712. * @param token The @ref completion_token that will be used to produce a
  713. * completion handler, which will be called when the write completes.
  714. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  715. * @ref yield_context, or a function object with the correct completion
  716. * signature. The function signature of the completion handler must be:
  717. * @code void handler(
  718. * // Result of operation.
  719. * const boost::system::error_code& error,
  720. *
  721. * // Number of bytes written from the buffers. If an error
  722. * // occurred, this will be less than the sum of the buffer sizes.
  723. * std::size_t bytes_transferred
  724. * ); @endcode
  725. * Regardless of whether the asynchronous operation completes immediately or
  726. * not, the completion handler will not be invoked from within this function.
  727. * On immediate completion, invocation of the handler will be performed in a
  728. * manner equivalent to using boost::asio::post().
  729. *
  730. * @par Completion Signature
  731. * @code void(boost::system::error_code, std::size_t) @endcode
  732. *
  733. * @par Example
  734. * To write a single data buffer use the @ref buffer function as follows:
  735. * @code
  736. * boost::asio::async_write(s, boost::asio::buffer(data, size), handler);
  737. * @endcode
  738. * See the @ref buffer documentation for information on writing multiple
  739. * buffers in one go, and how to use it with arrays, boost::array or
  740. * std::vector.
  741. *
  742. * @par Per-Operation Cancellation
  743. * This asynchronous operation supports cancellation for the following
  744. * boost::asio::cancellation_type values:
  745. *
  746. * @li @c cancellation_type::terminal
  747. *
  748. * @li @c cancellation_type::partial
  749. *
  750. * if they are also supported by the @c AsyncWriteStream type's
  751. * @c async_write_some operation.
  752. */
  753. template <typename AsyncWriteStream, typename ConstBufferSequence,
  754. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  755. std::size_t)) WriteToken
  756. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  757. typename AsyncWriteStream::executor_type)>
  758. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  759. void (boost::system::error_code, std::size_t))
  760. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  761. BOOST_ASIO_MOVE_ARG(WriteToken) token
  762. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  763. typename AsyncWriteStream::executor_type),
  764. typename constraint<
  765. is_const_buffer_sequence<ConstBufferSequence>::value
  766. >::type = 0);
  767. /// Start an asynchronous operation to write a certain amount of data to a
  768. /// stream.
  769. /**
  770. * This function is used to asynchronously write a certain number of bytes of
  771. * data to a stream. It is an initiating function for an @ref
  772. * asynchronous_operation, and always returns immediately. The asynchronous
  773. * operation will continue until one of the following conditions is true:
  774. *
  775. * @li All of the data in the supplied buffers has been written. That is, the
  776. * bytes transferred is equal to the sum of the buffer sizes.
  777. *
  778. * @li The completion_condition function object returns 0.
  779. *
  780. * This operation is implemented in terms of zero or more calls to the stream's
  781. * async_write_some function, and is known as a <em>composed operation</em>. The
  782. * program must ensure that the stream performs no other write operations (such
  783. * as async_write, the stream's async_write_some function, or any other composed
  784. * operations that perform writes) until this operation completes.
  785. *
  786. * @param s The stream to which the data is to be written. The type must support
  787. * the AsyncWriteStream concept.
  788. *
  789. * @param buffers One or more buffers containing the data to be written.
  790. * Although the buffers object may be copied as necessary, ownership of the
  791. * underlying memory blocks is retained by the caller, which must guarantee
  792. * that they remain valid until the completion handler is called.
  793. *
  794. * @param completion_condition The function object to be called to determine
  795. * whether the write operation is complete. The signature of the function object
  796. * must be:
  797. * @code std::size_t completion_condition(
  798. * // Result of latest async_write_some operation.
  799. * const boost::system::error_code& error,
  800. *
  801. * // Number of bytes transferred so far.
  802. * std::size_t bytes_transferred
  803. * ); @endcode
  804. * A return value of 0 indicates that the write operation is complete. A
  805. * non-zero return value indicates the maximum number of bytes to be written on
  806. * the next call to the stream's async_write_some function.
  807. *
  808. * @param token The @ref completion_token that will be used to produce a
  809. * completion handler, which will be called when the write completes.
  810. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  811. * @ref yield_context, or a function object with the correct completion
  812. * signature. The function signature of the completion handler must be:
  813. * @code void handler(
  814. * // Result of operation.
  815. * const boost::system::error_code& error,
  816. *
  817. * // Number of bytes written from the buffers. If an error
  818. * // occurred, this will be less than the sum of the buffer sizes.
  819. * std::size_t bytes_transferred
  820. * ); @endcode
  821. * Regardless of whether the asynchronous operation completes immediately or
  822. * not, the completion handler will not be invoked from within this function.
  823. * On immediate completion, invocation of the handler will be performed in a
  824. * manner equivalent to using boost::asio::post().
  825. *
  826. * @par Completion Signature
  827. * @code void(boost::system::error_code, std::size_t) @endcode
  828. *
  829. * @par Example
  830. * To write a single data buffer use the @ref buffer function as follows:
  831. * @code boost::asio::async_write(s,
  832. * boost::asio::buffer(data, size),
  833. * boost::asio::transfer_at_least(32),
  834. * handler); @endcode
  835. * See the @ref buffer documentation for information on writing multiple
  836. * buffers in one go, and how to use it with arrays, boost::array or
  837. * std::vector.
  838. *
  839. * @par Per-Operation Cancellation
  840. * This asynchronous operation supports cancellation for the following
  841. * boost::asio::cancellation_type values:
  842. *
  843. * @li @c cancellation_type::terminal
  844. *
  845. * @li @c cancellation_type::partial
  846. *
  847. * if they are also supported by the @c AsyncWriteStream type's
  848. * @c async_write_some operation.
  849. */
  850. template <typename AsyncWriteStream,
  851. typename ConstBufferSequence, typename CompletionCondition,
  852. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  853. std::size_t)) WriteToken>
  854. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  855. void (boost::system::error_code, std::size_t))
  856. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  857. CompletionCondition completion_condition,
  858. BOOST_ASIO_MOVE_ARG(WriteToken) token,
  859. typename constraint<
  860. is_const_buffer_sequence<ConstBufferSequence>::value
  861. >::type = 0);
  862. #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  863. /// Start an asynchronous operation to write all of the supplied data to a
  864. /// stream.
  865. /**
  866. * This function is used to asynchronously write a certain number of bytes of
  867. * data to a stream. It is an initiating function for an @ref
  868. * asynchronous_operation, and always returns immediately. The asynchronous
  869. * operation will continue until one of the following conditions is true:
  870. *
  871. * @li All of the data in the supplied dynamic buffer sequence has been written.
  872. *
  873. * @li An error occurred.
  874. *
  875. * This operation is implemented in terms of zero or more calls to the stream's
  876. * async_write_some function, and is known as a <em>composed operation</em>. The
  877. * program must ensure that the stream performs no other write operations (such
  878. * as async_write, the stream's async_write_some function, or any other composed
  879. * operations that perform writes) until this operation completes.
  880. *
  881. * @param s The stream to which the data is to be written. The type must support
  882. * the AsyncWriteStream concept.
  883. *
  884. * @param buffers The dynamic buffer sequence from which data will be written.
  885. * Although the buffers object may be copied as necessary, ownership of the
  886. * underlying memory blocks is retained by the caller, which must guarantee
  887. * that they remain valid until the completion handler is called. Successfully
  888. * written data is automatically consumed from the buffers.
  889. *
  890. * @param token The @ref completion_token that will be used to produce a
  891. * completion handler, which will be called when the write completes.
  892. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  893. * @ref yield_context, or a function object with the correct completion
  894. * signature. The function signature of the completion handler must be:
  895. * @code void handler(
  896. * // Result of operation.
  897. * const boost::system::error_code& error,
  898. *
  899. * // Number of bytes written from the buffers. If an error
  900. * // occurred, this will be less than the sum of the buffer sizes.
  901. * std::size_t bytes_transferred
  902. * ); @endcode
  903. * Regardless of whether the asynchronous operation completes immediately or
  904. * not, the completion handler will not be invoked from within this function.
  905. * On immediate completion, invocation of the handler will be performed in a
  906. * manner equivalent to using boost::asio::post().
  907. *
  908. * @par Completion Signature
  909. * @code void(boost::system::error_code, std::size_t) @endcode
  910. *
  911. * @par Per-Operation Cancellation
  912. * This asynchronous operation supports cancellation for the following
  913. * boost::asio::cancellation_type values:
  914. *
  915. * @li @c cancellation_type::terminal
  916. *
  917. * @li @c cancellation_type::partial
  918. *
  919. * if they are also supported by the @c AsyncWriteStream type's
  920. * @c async_write_some operation.
  921. */
  922. template <typename AsyncWriteStream, typename DynamicBuffer_v1,
  923. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  924. std::size_t)) WriteToken
  925. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  926. typename AsyncWriteStream::executor_type)>
  927. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  928. void (boost::system::error_code, std::size_t))
  929. async_write(AsyncWriteStream& s,
  930. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  931. BOOST_ASIO_MOVE_ARG(WriteToken) token
  932. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  933. typename AsyncWriteStream::executor_type),
  934. typename constraint<
  935. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  936. >::type = 0,
  937. typename constraint<
  938. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  939. >::type = 0);
  940. /// Start an asynchronous operation to write a certain amount of data to a
  941. /// stream.
  942. /**
  943. * This function is used to asynchronously write a certain number of bytes of
  944. * data to a stream. It is an initiating function for an @ref
  945. * asynchronous_operation, and always returns immediately. The asynchronous
  946. * operation will continue until one of the following conditions is true:
  947. *
  948. * @li All of the data in the supplied dynamic buffer sequence has been written.
  949. *
  950. * @li The completion_condition function object returns 0.
  951. *
  952. * This operation is implemented in terms of zero or more calls to the stream's
  953. * async_write_some function, and is known as a <em>composed operation</em>. The
  954. * program must ensure that the stream performs no other write operations (such
  955. * as async_write, the stream's async_write_some function, or any other composed
  956. * operations that perform writes) until this operation completes.
  957. *
  958. * @param s The stream to which the data is to be written. The type must support
  959. * the AsyncWriteStream concept.
  960. *
  961. * @param buffers The dynamic buffer sequence from which data will be written.
  962. * Although the buffers object may be copied as necessary, ownership of the
  963. * underlying memory blocks is retained by the caller, which must guarantee
  964. * that they remain valid until the completion handler is called. Successfully
  965. * written data is automatically consumed from the buffers.
  966. *
  967. * @param completion_condition The function object to be called to determine
  968. * whether the write operation is complete. The signature of the function object
  969. * must be:
  970. * @code std::size_t completion_condition(
  971. * // Result of latest async_write_some operation.
  972. * const boost::system::error_code& error,
  973. *
  974. * // Number of bytes transferred so far.
  975. * std::size_t bytes_transferred
  976. * ); @endcode
  977. * A return value of 0 indicates that the write operation is complete. A
  978. * non-zero return value indicates the maximum number of bytes to be written on
  979. * the next call to the stream's async_write_some function.
  980. *
  981. * @param token The @ref completion_token that will be used to produce a
  982. * completion handler, which will be called when the write completes.
  983. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  984. * @ref yield_context, or a function object with the correct completion
  985. * signature. The function signature of the completion handler must be:
  986. * @code void handler(
  987. * // Result of operation.
  988. * const boost::system::error_code& error,
  989. *
  990. * // Number of bytes written from the buffers. If an error
  991. * // occurred, this will be less than the sum of the buffer sizes.
  992. * std::size_t bytes_transferred
  993. * ); @endcode
  994. * Regardless of whether the asynchronous operation completes immediately or
  995. * not, the completion handler will not be invoked from within this function.
  996. * On immediate completion, invocation of the handler will be performed in a
  997. * manner equivalent to using boost::asio::post().
  998. *
  999. * @par Completion Signature
  1000. * @code void(boost::system::error_code, std::size_t) @endcode
  1001. *
  1002. * @par Per-Operation Cancellation
  1003. * This asynchronous operation supports cancellation for the following
  1004. * boost::asio::cancellation_type values:
  1005. *
  1006. * @li @c cancellation_type::terminal
  1007. *
  1008. * @li @c cancellation_type::partial
  1009. *
  1010. * if they are also supported by the @c AsyncWriteStream type's
  1011. * @c async_write_some operation.
  1012. */
  1013. template <typename AsyncWriteStream,
  1014. typename DynamicBuffer_v1, typename CompletionCondition,
  1015. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1016. std::size_t)) WriteToken>
  1017. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  1018. void (boost::system::error_code, std::size_t))
  1019. async_write(AsyncWriteStream& s,
  1020. BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
  1021. CompletionCondition completion_condition,
  1022. BOOST_ASIO_MOVE_ARG(WriteToken) token,
  1023. typename constraint<
  1024. is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
  1025. >::type = 0,
  1026. typename constraint<
  1027. !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
  1028. >::type = 0);
  1029. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  1030. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  1031. /// Start an asynchronous operation to write all of the supplied data to a
  1032. /// stream.
  1033. /**
  1034. * This function is used to asynchronously write a certain number of bytes of
  1035. * data to a stream. It is an initiating function for an @ref
  1036. * asynchronous_operation, and always returns immediately. The asynchronous
  1037. * operation will continue until one of the following conditions is true:
  1038. *
  1039. * @li All of the data in the supplied basic_streambuf has been written.
  1040. *
  1041. * @li An error occurred.
  1042. *
  1043. * This operation is implemented in terms of zero or more calls to the stream's
  1044. * async_write_some function, and is known as a <em>composed operation</em>. The
  1045. * program must ensure that the stream performs no other write operations (such
  1046. * as async_write, the stream's async_write_some function, or any other composed
  1047. * operations that perform writes) until this operation completes.
  1048. *
  1049. * @param s The stream to which the data is to be written. The type must support
  1050. * the AsyncWriteStream concept.
  1051. *
  1052. * @param b A basic_streambuf object from which data will be written. Ownership
  1053. * of the streambuf is retained by the caller, which must guarantee that it
  1054. * remains valid until the completion handler is called.
  1055. *
  1056. * @param token The @ref completion_token that will be used to produce a
  1057. * completion handler, which will be called when the write completes.
  1058. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1059. * @ref yield_context, or a function object with the correct completion
  1060. * signature. The function signature of the completion handler must be:
  1061. * @code void handler(
  1062. * // Result of operation.
  1063. * const boost::system::error_code& error,
  1064. *
  1065. * // Number of bytes written from the buffers. If an error
  1066. * // occurred, this will be less than the sum of the buffer sizes.
  1067. * std::size_t bytes_transferred
  1068. * ); @endcode
  1069. * Regardless of whether the asynchronous operation completes immediately or
  1070. * not, the completion handler will not be invoked from within this function.
  1071. * On immediate completion, invocation of the handler will be performed in a
  1072. * manner equivalent to using boost::asio::post().
  1073. *
  1074. * @par Completion Signature
  1075. * @code void(boost::system::error_code, std::size_t) @endcode
  1076. *
  1077. * @par Per-Operation Cancellation
  1078. * This asynchronous operation supports cancellation for the following
  1079. * boost::asio::cancellation_type values:
  1080. *
  1081. * @li @c cancellation_type::terminal
  1082. *
  1083. * @li @c cancellation_type::partial
  1084. *
  1085. * if they are also supported by the @c AsyncWriteStream type's
  1086. * @c async_write_some operation.
  1087. */
  1088. template <typename AsyncWriteStream, typename Allocator,
  1089. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1090. std::size_t)) WriteToken
  1091. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1092. typename AsyncWriteStream::executor_type)>
  1093. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  1094. void (boost::system::error_code, std::size_t))
  1095. async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
  1096. BOOST_ASIO_MOVE_ARG(WriteToken) token
  1097. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1098. typename AsyncWriteStream::executor_type));
  1099. /// Start an asynchronous operation to write a certain amount of data to a
  1100. /// stream.
  1101. /**
  1102. * This function is used to asynchronously write a certain number of bytes of
  1103. * data to a stream. It is an initiating function for an @ref
  1104. * asynchronous_operation, and always returns immediately. The asynchronous
  1105. * operation will continue until one of the following conditions is true:
  1106. *
  1107. * @li All of the data in the supplied basic_streambuf has been written.
  1108. *
  1109. * @li The completion_condition function object returns 0.
  1110. *
  1111. * This operation is implemented in terms of zero or more calls to the stream's
  1112. * async_write_some function, and is known as a <em>composed operation</em>. The
  1113. * program must ensure that the stream performs no other write operations (such
  1114. * as async_write, the stream's async_write_some function, or any other composed
  1115. * operations that perform writes) until this operation completes.
  1116. *
  1117. * @param s The stream to which the data is to be written. The type must support
  1118. * the AsyncWriteStream concept.
  1119. *
  1120. * @param b A basic_streambuf object from which data will be written. Ownership
  1121. * of the streambuf is retained by the caller, which must guarantee that it
  1122. * remains valid until the completion handler is called.
  1123. *
  1124. * @param completion_condition The function object to be called to determine
  1125. * whether the write operation is complete. The signature of the function object
  1126. * must be:
  1127. * @code std::size_t completion_condition(
  1128. * // Result of latest async_write_some operation.
  1129. * const boost::system::error_code& error,
  1130. *
  1131. * // Number of bytes transferred so far.
  1132. * std::size_t bytes_transferred
  1133. * ); @endcode
  1134. * A return value of 0 indicates that the write operation is complete. A
  1135. * non-zero return value indicates the maximum number of bytes to be written on
  1136. * the next call to the stream's async_write_some function.
  1137. *
  1138. * @param token The @ref completion_token that will be used to produce a
  1139. * completion handler, which will be called when the write completes.
  1140. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1141. * @ref yield_context, or a function object with the correct completion
  1142. * signature. The function signature of the completion handler must be:
  1143. * @code void handler(
  1144. * // Result of operation.
  1145. * const boost::system::error_code& error,
  1146. *
  1147. * // Number of bytes written from the buffers. If an error
  1148. * // occurred, this will be less than the sum of the buffer sizes.
  1149. * std::size_t bytes_transferred
  1150. * ); @endcode
  1151. * Regardless of whether the asynchronous operation completes immediately or
  1152. * not, the completion handler will not be invoked from within this function.
  1153. * On immediate completion, invocation of the handler will be performed in a
  1154. * manner equivalent to using boost::asio::post().
  1155. *
  1156. * @par Completion Signature
  1157. * @code void(boost::system::error_code, std::size_t) @endcode
  1158. *
  1159. * @par Per-Operation Cancellation
  1160. * This asynchronous operation supports cancellation for the following
  1161. * boost::asio::cancellation_type values:
  1162. *
  1163. * @li @c cancellation_type::terminal
  1164. *
  1165. * @li @c cancellation_type::partial
  1166. *
  1167. * if they are also supported by the @c AsyncWriteStream type's
  1168. * @c async_write_some operation.
  1169. */
  1170. template <typename AsyncWriteStream,
  1171. typename Allocator, typename CompletionCondition,
  1172. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1173. std::size_t)) WriteToken>
  1174. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  1175. void (boost::system::error_code, std::size_t))
  1176. async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
  1177. CompletionCondition completion_condition,
  1178. BOOST_ASIO_MOVE_ARG(WriteToken) token);
  1179. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  1180. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  1181. #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
  1182. /// Start an asynchronous operation to write all of the supplied data to a
  1183. /// stream.
  1184. /**
  1185. * This function is used to asynchronously write a certain number of bytes of
  1186. * data to a stream. It is an initiating function for an @ref
  1187. * asynchronous_operation, and always returns immediately. The asynchronous
  1188. * operation will continue until one of the following conditions is true:
  1189. *
  1190. * @li All of the data in the supplied dynamic buffer sequence has been written.
  1191. *
  1192. * @li An error occurred.
  1193. *
  1194. * This operation is implemented in terms of zero or more calls to the stream's
  1195. * async_write_some function, and is known as a <em>composed operation</em>. The
  1196. * program must ensure that the stream performs no other write operations (such
  1197. * as async_write, the stream's async_write_some function, or any other composed
  1198. * operations that perform writes) until this operation completes.
  1199. *
  1200. * @param s The stream to which the data is to be written. The type must support
  1201. * the AsyncWriteStream concept.
  1202. *
  1203. * @param buffers The dynamic buffer sequence from which data will be written.
  1204. * Although the buffers object may be copied as necessary, ownership of the
  1205. * underlying memory blocks is retained by the caller, which must guarantee
  1206. * that they remain valid until the completion handler is called. Successfully
  1207. * written data is automatically consumed from the buffers.
  1208. *
  1209. * @param token The @ref completion_token that will be used to produce a
  1210. * completion handler, which will be called when the write completes.
  1211. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1212. * @ref yield_context, or a function object with the correct completion
  1213. * signature. The function signature of the completion handler must be:
  1214. * @code void handler(
  1215. * // Result of operation.
  1216. * const boost::system::error_code& error,
  1217. *
  1218. * // Number of bytes written from the buffers. If an error
  1219. * // occurred, this will be less than the sum of the buffer sizes.
  1220. * std::size_t bytes_transferred
  1221. * ); @endcode
  1222. * Regardless of whether the asynchronous operation completes immediately or
  1223. * not, the completion handler will not be invoked from within this function.
  1224. * On immediate completion, invocation of the handler will be performed in a
  1225. * manner equivalent to using boost::asio::post().
  1226. *
  1227. * @par Completion Signature
  1228. * @code void(boost::system::error_code, std::size_t) @endcode
  1229. *
  1230. * @par Per-Operation Cancellation
  1231. * This asynchronous operation supports cancellation for the following
  1232. * boost::asio::cancellation_type values:
  1233. *
  1234. * @li @c cancellation_type::terminal
  1235. *
  1236. * @li @c cancellation_type::partial
  1237. *
  1238. * if they are also supported by the @c AsyncWriteStream type's
  1239. * @c async_write_some operation.
  1240. */
  1241. template <typename AsyncWriteStream, typename DynamicBuffer_v2,
  1242. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1243. std::size_t)) WriteToken
  1244. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
  1245. typename AsyncWriteStream::executor_type)>
  1246. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  1247. void (boost::system::error_code, std::size_t))
  1248. async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
  1249. BOOST_ASIO_MOVE_ARG(WriteToken) token
  1250. BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
  1251. typename AsyncWriteStream::executor_type),
  1252. typename constraint<
  1253. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  1254. >::type = 0);
  1255. /// Start an asynchronous operation to write a certain amount of data to a
  1256. /// stream.
  1257. /**
  1258. * This function is used to asynchronously write a certain number of bytes of
  1259. * data to a stream. It is an initiating function for an @ref
  1260. * asynchronous_operation, and always returns immediately. The asynchronous
  1261. * operation will continue until one of the following conditions is true:
  1262. *
  1263. * @li All of the data in the supplied dynamic buffer sequence has been written.
  1264. *
  1265. * @li The completion_condition function object returns 0.
  1266. *
  1267. * This operation is implemented in terms of zero or more calls to the stream's
  1268. * async_write_some function, and is known as a <em>composed operation</em>. The
  1269. * program must ensure that the stream performs no other write operations (such
  1270. * as async_write, the stream's async_write_some function, or any other composed
  1271. * operations that perform writes) until this operation completes.
  1272. *
  1273. * @param s The stream to which the data is to be written. The type must support
  1274. * the AsyncWriteStream concept.
  1275. *
  1276. * @param buffers The dynamic buffer sequence from which data will be written.
  1277. * Although the buffers object may be copied as necessary, ownership of the
  1278. * underlying memory blocks is retained by the caller, which must guarantee
  1279. * that they remain valid until the completion handler is called. Successfully
  1280. * written data is automatically consumed from the buffers.
  1281. *
  1282. * @param completion_condition The function object to be called to determine
  1283. * whether the write operation is complete. The signature of the function object
  1284. * must be:
  1285. * @code std::size_t completion_condition(
  1286. * // Result of latest async_write_some operation.
  1287. * const boost::system::error_code& error,
  1288. *
  1289. * // Number of bytes transferred so far.
  1290. * std::size_t bytes_transferred
  1291. * ); @endcode
  1292. * A return value of 0 indicates that the write operation is complete. A
  1293. * non-zero return value indicates the maximum number of bytes to be written on
  1294. * the next call to the stream's async_write_some function.
  1295. *
  1296. * @param token The @ref completion_token that will be used to produce a
  1297. * completion handler, which will be called when the write completes.
  1298. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  1299. * @ref yield_context, or a function object with the correct completion
  1300. * signature. The function signature of the completion handler must be:
  1301. * @code void handler(
  1302. * // Result of operation.
  1303. * const boost::system::error_code& error,
  1304. *
  1305. * // Number of bytes written from the buffers. If an error
  1306. * // occurred, this will be less than the sum of the buffer sizes.
  1307. * std::size_t bytes_transferred
  1308. * ); @endcode
  1309. * Regardless of whether the asynchronous operation completes immediately or
  1310. * not, the completion handler will not be invoked from within this function.
  1311. * On immediate completion, invocation of the handler will be performed in a
  1312. * manner equivalent to using boost::asio::post().
  1313. *
  1314. * @par Completion Signature
  1315. * @code void(boost::system::error_code, std::size_t) @endcode
  1316. *
  1317. * @par Per-Operation Cancellation
  1318. * This asynchronous operation supports cancellation for the following
  1319. * boost::asio::cancellation_type values:
  1320. *
  1321. * @li @c cancellation_type::terminal
  1322. *
  1323. * @li @c cancellation_type::partial
  1324. *
  1325. * if they are also supported by the @c AsyncWriteStream type's
  1326. * @c async_write_some operation.
  1327. */
  1328. template <typename AsyncWriteStream,
  1329. typename DynamicBuffer_v2, typename CompletionCondition,
  1330. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  1331. std::size_t)) WriteToken>
  1332. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
  1333. void (boost::system::error_code, std::size_t))
  1334. async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
  1335. CompletionCondition completion_condition,
  1336. BOOST_ASIO_MOVE_ARG(WriteToken) token,
  1337. typename constraint<
  1338. is_dynamic_buffer_v2<DynamicBuffer_v2>::value
  1339. >::type = 0);
  1340. /*@}*/
  1341. } // namespace asio
  1342. } // namespace boost
  1343. #include <boost/asio/detail/pop_options.hpp>
  1344. #include <boost/asio/impl/write.hpp>
  1345. #endif // BOOST_ASIO_WRITE_HPP