write.hpp 50 KB

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