write.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. //
  2. // write.hpp
  3. // ~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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 ASIO_WRITE_HPP
  11. #define ASIO_WRITE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <cstddef>
  17. #include "asio/async_result.hpp"
  18. #include "asio/basic_streambuf_fwd.hpp"
  19. #include "asio/error.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. /**
  23. * @defgroup write asio::write
  24. *
  25. * @brief Write a certain amount of data to a stream before returning.
  26. */
  27. /*@{*/
  28. /// Write all of the supplied data to a stream before returning.
  29. /**
  30. * This function is used to write a certain number of bytes of data to a stream.
  31. * The call will block until one of the following conditions is true:
  32. *
  33. * @li All of the data in the supplied buffers has been written. That is, the
  34. * bytes transferred is equal to the sum of the buffer sizes.
  35. *
  36. * @li An error occurred.
  37. *
  38. * This operation is implemented in terms of zero or more calls to the stream's
  39. * write_some function.
  40. *
  41. * @param s The stream to which the data is to be written. The type must support
  42. * the SyncWriteStream concept.
  43. *
  44. * @param buffers One or more buffers containing the data to be written. The sum
  45. * of the buffer sizes indicates the maximum number of bytes to write to the
  46. * stream.
  47. *
  48. * @returns The number of bytes transferred.
  49. *
  50. * @throws asio::system_error Thrown on failure.
  51. *
  52. * @par Example
  53. * To write a single data buffer use the @ref buffer function as follows:
  54. * @code asio::write(s, asio::buffer(data, size)); @endcode
  55. * See the @ref buffer documentation for information on writing multiple
  56. * buffers in one go, and how to use it with arrays, boost::array or
  57. * std::vector.
  58. *
  59. * @note This overload is equivalent to calling:
  60. * @code asio::write(
  61. * s, buffers,
  62. * asio::transfer_all()); @endcode
  63. */
  64. template <typename SyncWriteStream, typename ConstBufferSequence>
  65. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers);
  66. /// Write all of the supplied data to a stream before returning.
  67. /**
  68. * This function is used to write a certain number of bytes of data to a stream.
  69. * The call will block until one of the following conditions is true:
  70. *
  71. * @li All of the data in the supplied buffers has been written. That is, the
  72. * bytes transferred is equal to the sum of the buffer sizes.
  73. *
  74. * @li An error occurred.
  75. *
  76. * This operation is implemented in terms of zero or more calls to the stream's
  77. * write_some function.
  78. *
  79. * @param s The stream to which the data is to be written. The type must support
  80. * the SyncWriteStream concept.
  81. *
  82. * @param buffers One or more buffers containing the data to be written. The sum
  83. * of the buffer sizes indicates the maximum number of bytes to write to the
  84. * stream.
  85. *
  86. * @param ec Set to indicate what error occurred, if any.
  87. *
  88. * @returns The number of bytes transferred.
  89. *
  90. * @par Example
  91. * To write a single data buffer use the @ref buffer function as follows:
  92. * @code asio::write(s, asio::buffer(data, size), ec); @endcode
  93. * See the @ref buffer documentation for information on writing multiple
  94. * buffers in one go, and how to use it with arrays, boost::array or
  95. * std::vector.
  96. *
  97. * @note This overload is equivalent to calling:
  98. * @code asio::write(
  99. * s, buffers,
  100. * asio::transfer_all(), ec); @endcode
  101. */
  102. template <typename SyncWriteStream, typename ConstBufferSequence>
  103. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  104. asio::error_code& ec);
  105. /// Write a certain amount of data to a stream before returning.
  106. /**
  107. * This function is used to write a certain number of bytes of data to a stream.
  108. * The call will block until one of the following conditions is true:
  109. *
  110. * @li All of the data in the supplied buffers has been written. That is, the
  111. * bytes transferred is equal to the sum of the buffer sizes.
  112. *
  113. * @li The completion_condition function object returns 0.
  114. *
  115. * This operation is implemented in terms of zero or more calls to the stream's
  116. * write_some function.
  117. *
  118. * @param s The stream to which the data is to be written. The type must support
  119. * the SyncWriteStream concept.
  120. *
  121. * @param buffers One or more buffers containing the data to be written. The sum
  122. * of the buffer sizes indicates the maximum number of bytes to write to the
  123. * stream.
  124. *
  125. * @param completion_condition The function object to be called to determine
  126. * whether the write operation is complete. The signature of the function object
  127. * must be:
  128. * @code std::size_t completion_condition(
  129. * // Result of latest write_some operation.
  130. * const asio::error_code& error,
  131. *
  132. * // Number of bytes transferred so far.
  133. * std::size_t bytes_transferred
  134. * ); @endcode
  135. * A return value of 0 indicates that the write operation is complete. A
  136. * non-zero return value indicates the maximum number of bytes to be written on
  137. * the next call to the stream's write_some function.
  138. *
  139. * @returns The number of bytes transferred.
  140. *
  141. * @throws asio::system_error Thrown on failure.
  142. *
  143. * @par Example
  144. * To write a single data buffer use the @ref buffer function as follows:
  145. * @code asio::write(s, asio::buffer(data, size),
  146. * asio::transfer_at_least(32)); @endcode
  147. * See the @ref buffer documentation for information on writing multiple
  148. * buffers in one go, and how to use it with arrays, boost::array or
  149. * std::vector.
  150. */
  151. template <typename SyncWriteStream, typename ConstBufferSequence,
  152. typename CompletionCondition>
  153. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  154. CompletionCondition completion_condition);
  155. /// Write a certain amount of data to a stream before returning.
  156. /**
  157. * This function is used to write a certain number of bytes of data to a stream.
  158. * The call will block until one of the following conditions is true:
  159. *
  160. * @li All of the data in the supplied buffers has been written. That is, the
  161. * bytes transferred is equal to the sum of the buffer sizes.
  162. *
  163. * @li The completion_condition function object returns 0.
  164. *
  165. * This operation is implemented in terms of zero or more calls to the stream's
  166. * write_some function.
  167. *
  168. * @param s The stream to which the data is to be written. The type must support
  169. * the SyncWriteStream concept.
  170. *
  171. * @param buffers One or more buffers containing the data to be written. The sum
  172. * of the buffer sizes indicates the maximum number of bytes to write to the
  173. * stream.
  174. *
  175. * @param completion_condition The function object to be called to determine
  176. * whether the write operation is complete. The signature of the function object
  177. * must be:
  178. * @code std::size_t completion_condition(
  179. * // Result of latest write_some operation.
  180. * const asio::error_code& error,
  181. *
  182. * // Number of bytes transferred so far.
  183. * std::size_t bytes_transferred
  184. * ); @endcode
  185. * A return value of 0 indicates that the write operation is complete. A
  186. * non-zero return value indicates the maximum number of bytes to be written on
  187. * the next call to the stream's write_some function.
  188. *
  189. * @param ec Set to indicate what error occurred, if any.
  190. *
  191. * @returns The number of bytes written. If an error occurs, returns the total
  192. * number of bytes successfully transferred prior to the error.
  193. */
  194. template <typename SyncWriteStream, typename ConstBufferSequence,
  195. typename CompletionCondition>
  196. std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
  197. CompletionCondition completion_condition, asio::error_code& ec);
  198. #if !defined(ASIO_NO_IOSTREAM)
  199. /// Write all of the supplied data to a stream before returning.
  200. /**
  201. * This function is used to write a certain number of bytes of data to a stream.
  202. * The call will block until one of the following conditions is true:
  203. *
  204. * @li All of the data in the supplied basic_streambuf has been written.
  205. *
  206. * @li An error occurred.
  207. *
  208. * This operation is implemented in terms of zero or more calls to the stream's
  209. * write_some function.
  210. *
  211. * @param s The stream to which the data is to be written. The type must support
  212. * the SyncWriteStream concept.
  213. *
  214. * @param b The basic_streambuf object from which data will be written.
  215. *
  216. * @returns The number of bytes transferred.
  217. *
  218. * @throws asio::system_error Thrown on failure.
  219. *
  220. * @note This overload is equivalent to calling:
  221. * @code asio::write(
  222. * s, b,
  223. * asio::transfer_all()); @endcode
  224. */
  225. template <typename SyncWriteStream, typename Allocator>
  226. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b);
  227. /// Write all of the supplied data to a stream before returning.
  228. /**
  229. * This function is used to write a certain number of bytes of data to a stream.
  230. * The call will block until one of the following conditions is true:
  231. *
  232. * @li All of the data in the supplied basic_streambuf has been written.
  233. *
  234. * @li An error occurred.
  235. *
  236. * This operation is implemented in terms of zero or more calls to the stream's
  237. * write_some function.
  238. *
  239. * @param s The stream to which the data is to be written. The type must support
  240. * the SyncWriteStream concept.
  241. *
  242. * @param b The basic_streambuf object from which data will be written.
  243. *
  244. * @param ec Set to indicate what error occurred, if any.
  245. *
  246. * @returns The number of bytes transferred.
  247. *
  248. * @note This overload is equivalent to calling:
  249. * @code asio::write(
  250. * s, b,
  251. * asio::transfer_all(), ec); @endcode
  252. */
  253. template <typename SyncWriteStream, typename Allocator>
  254. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
  255. asio::error_code& ec);
  256. /// Write a certain amount of data to a stream before returning.
  257. /**
  258. * This function is used to write a certain number of bytes of data to a stream.
  259. * The call will block until one of the following conditions is true:
  260. *
  261. * @li All of the data in the supplied basic_streambuf has been written.
  262. *
  263. * @li The completion_condition function object returns 0.
  264. *
  265. * This operation is implemented in terms of zero or more calls to the stream's
  266. * write_some function.
  267. *
  268. * @param s The stream to which the data is to be written. The type must support
  269. * the SyncWriteStream concept.
  270. *
  271. * @param b The basic_streambuf object from which data will be written.
  272. *
  273. * @param completion_condition The function object to be called to determine
  274. * whether the write operation is complete. The signature of the function object
  275. * must be:
  276. * @code std::size_t completion_condition(
  277. * // Result of latest write_some operation.
  278. * const asio::error_code& error,
  279. *
  280. * // Number of bytes transferred so far.
  281. * std::size_t bytes_transferred
  282. * ); @endcode
  283. * A return value of 0 indicates that the write operation is complete. A
  284. * non-zero return value indicates the maximum number of bytes to be written on
  285. * the next call to the stream's write_some function.
  286. *
  287. * @returns The number of bytes transferred.
  288. *
  289. * @throws asio::system_error Thrown on failure.
  290. */
  291. template <typename SyncWriteStream, typename Allocator,
  292. typename CompletionCondition>
  293. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
  294. CompletionCondition completion_condition);
  295. /// Write a certain amount of data to a stream before returning.
  296. /**
  297. * This function is used to write a certain number of bytes of data to a stream.
  298. * The call will block until one of the following conditions is true:
  299. *
  300. * @li All of the data in the supplied basic_streambuf has been written.
  301. *
  302. * @li The completion_condition function object returns 0.
  303. *
  304. * This operation is implemented in terms of zero or more calls to the stream's
  305. * write_some function.
  306. *
  307. * @param s The stream to which the data is to be written. The type must support
  308. * the SyncWriteStream concept.
  309. *
  310. * @param b The basic_streambuf object from which data will be written.
  311. *
  312. * @param completion_condition The function object to be called to determine
  313. * whether the write operation is complete. The signature of the function object
  314. * must be:
  315. * @code std::size_t completion_condition(
  316. * // Result of latest write_some operation.
  317. * const asio::error_code& error,
  318. *
  319. * // Number of bytes transferred so far.
  320. * std::size_t bytes_transferred
  321. * ); @endcode
  322. * A return value of 0 indicates that the write operation is complete. A
  323. * non-zero return value indicates the maximum number of bytes to be written on
  324. * the next call to the stream's write_some function.
  325. *
  326. * @param ec Set to indicate what error occurred, if any.
  327. *
  328. * @returns The number of bytes written. If an error occurs, returns the total
  329. * number of bytes successfully transferred prior to the error.
  330. */
  331. template <typename SyncWriteStream, typename Allocator,
  332. typename CompletionCondition>
  333. std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
  334. CompletionCondition completion_condition, asio::error_code& ec);
  335. #endif // !defined(ASIO_NO_IOSTREAM)
  336. /*@}*/
  337. /**
  338. * @defgroup async_write asio::async_write
  339. *
  340. * @brief Start an asynchronous operation to write a certain amount of data to a
  341. * stream.
  342. */
  343. /*@{*/
  344. /// Start an asynchronous operation to write all of the supplied data to a
  345. /// stream.
  346. /**
  347. * This function is used to asynchronously write a certain number of bytes of
  348. * data to a stream. The function call always returns immediately. The
  349. * asynchronous operation will continue until one of the following conditions
  350. * is true:
  351. *
  352. * @li All of the data in the supplied buffers has been written. That is, the
  353. * bytes transferred is equal to the sum of the buffer sizes.
  354. *
  355. * @li An error occurred.
  356. *
  357. * This operation is implemented in terms of zero or more calls to the stream's
  358. * async_write_some function, and is known as a <em>composed operation</em>. The
  359. * program must ensure that the stream performs no other write operations (such
  360. * as async_write, the stream's async_write_some function, or any other composed
  361. * operations that perform writes) until this operation completes.
  362. *
  363. * @param s The stream to which the data is to be written. The type must support
  364. * the AsyncWriteStream concept.
  365. *
  366. * @param buffers One or more buffers containing the data to be written.
  367. * Although the buffers object may be copied as necessary, ownership of the
  368. * underlying memory blocks is retained by the caller, which must guarantee
  369. * that they remain valid until the handler is called.
  370. *
  371. * @param handler The handler to be called when the write operation completes.
  372. * Copies will be made of the handler as required. The function signature of
  373. * the handler must be:
  374. * @code void handler(
  375. * const asio::error_code& error, // Result of operation.
  376. *
  377. * std::size_t bytes_transferred // Number of bytes written from the
  378. * // buffers. If an error occurred,
  379. * // this will be less than the sum
  380. * // of the buffer sizes.
  381. * ); @endcode
  382. * Regardless of whether the asynchronous operation completes immediately or
  383. * not, the handler will not be invoked from within this function. Invocation of
  384. * the handler will be performed in a manner equivalent to using
  385. * asio::io_service::post().
  386. *
  387. * @par Example
  388. * To write a single data buffer use the @ref buffer function as follows:
  389. * @code
  390. * asio::async_write(s, asio::buffer(data, size), handler);
  391. * @endcode
  392. * See the @ref buffer documentation for information on writing multiple
  393. * buffers in one go, and how to use it with arrays, boost::array or
  394. * std::vector.
  395. */
  396. template <typename AsyncWriteStream, typename ConstBufferSequence,
  397. typename WriteHandler>
  398. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  399. void (asio::error_code, std::size_t))
  400. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  401. ASIO_MOVE_ARG(WriteHandler) handler);
  402. /// Start an asynchronous operation to write a certain amount of data to a
  403. /// stream.
  404. /**
  405. * This function is used to asynchronously write a certain number of bytes of
  406. * data to a stream. The function call always returns immediately. The
  407. * asynchronous operation will continue until one of the following conditions
  408. * is true:
  409. *
  410. * @li All of the data in the supplied buffers has been written. That is, the
  411. * bytes transferred is equal to the sum of the buffer sizes.
  412. *
  413. * @li The completion_condition function object returns 0.
  414. *
  415. * This operation is implemented in terms of zero or more calls to the stream's
  416. * async_write_some function, and is known as a <em>composed operation</em>. The
  417. * program must ensure that the stream performs no other write operations (such
  418. * as async_write, the stream's async_write_some function, or any other composed
  419. * operations that perform writes) until this operation completes.
  420. *
  421. * @param s The stream to which the data is to be written. The type must support
  422. * the AsyncWriteStream concept.
  423. *
  424. * @param buffers One or more buffers containing the data to be written.
  425. * Although the buffers object may be copied as necessary, ownership of the
  426. * underlying memory blocks is retained by the caller, which must guarantee
  427. * that they remain valid until the handler is called.
  428. *
  429. * @param completion_condition The function object to be called to determine
  430. * whether the write operation is complete. The signature of the function object
  431. * must be:
  432. * @code std::size_t completion_condition(
  433. * // Result of latest async_write_some operation.
  434. * const asio::error_code& error,
  435. *
  436. * // Number of bytes transferred so far.
  437. * std::size_t bytes_transferred
  438. * ); @endcode
  439. * A return value of 0 indicates that the write operation is complete. A
  440. * non-zero return value indicates the maximum number of bytes to be written on
  441. * the next call to the stream's async_write_some function.
  442. *
  443. * @param handler The handler to be called when the write operation completes.
  444. * Copies will be made of the handler as required. The function signature of the
  445. * handler must be:
  446. * @code void handler(
  447. * const asio::error_code& error, // Result of operation.
  448. *
  449. * std::size_t bytes_transferred // Number of bytes written from the
  450. * // buffers. If an error occurred,
  451. * // this will be less than the sum
  452. * // of the buffer sizes.
  453. * ); @endcode
  454. * Regardless of whether the asynchronous operation completes immediately or
  455. * not, the handler will not be invoked from within this function. Invocation of
  456. * the handler will be performed in a manner equivalent to using
  457. * asio::io_service::post().
  458. *
  459. * @par Example
  460. * To write a single data buffer use the @ref buffer function as follows:
  461. * @code asio::async_write(s,
  462. * asio::buffer(data, size),
  463. * asio::transfer_at_least(32),
  464. * handler); @endcode
  465. * See the @ref buffer documentation for information on writing multiple
  466. * buffers in one go, and how to use it with arrays, boost::array or
  467. * std::vector.
  468. */
  469. template <typename AsyncWriteStream, typename ConstBufferSequence,
  470. typename CompletionCondition, typename WriteHandler>
  471. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  472. void (asio::error_code, std::size_t))
  473. async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
  474. CompletionCondition completion_condition,
  475. ASIO_MOVE_ARG(WriteHandler) handler);
  476. #if !defined(ASIO_NO_IOSTREAM)
  477. /// Start an asynchronous operation to write all of the supplied data to a
  478. /// stream.
  479. /**
  480. * This function is used to asynchronously write a certain number of bytes of
  481. * data to a stream. The function call always returns immediately. The
  482. * asynchronous operation will continue until one of the following conditions
  483. * is true:
  484. *
  485. * @li All of the data in the supplied basic_streambuf has been written.
  486. *
  487. * @li An error occurred.
  488. *
  489. * This operation is implemented in terms of zero or more calls to the stream's
  490. * async_write_some function, and is known as a <em>composed operation</em>. The
  491. * program must ensure that the stream performs no other write operations (such
  492. * as async_write, the stream's async_write_some function, or any other composed
  493. * operations that perform writes) until this operation completes.
  494. *
  495. * @param s The stream to which the data is to be written. The type must support
  496. * the AsyncWriteStream concept.
  497. *
  498. * @param b A basic_streambuf object from which data will be written. Ownership
  499. * of the streambuf is retained by the caller, which must guarantee that it
  500. * remains valid until the handler is called.
  501. *
  502. * @param handler The handler to be called when the write operation completes.
  503. * Copies will be made of the handler as required. The function signature of the
  504. * handler must be:
  505. * @code void handler(
  506. * const asio::error_code& error, // Result of operation.
  507. *
  508. * std::size_t bytes_transferred // Number of bytes written from the
  509. * // buffers. If an error occurred,
  510. * // this will be less than the sum
  511. * // of the buffer sizes.
  512. * ); @endcode
  513. * Regardless of whether the asynchronous operation completes immediately or
  514. * not, the handler will not be invoked from within this function. Invocation of
  515. * the handler will be performed in a manner equivalent to using
  516. * asio::io_service::post().
  517. */
  518. template <typename AsyncWriteStream, typename Allocator, typename WriteHandler>
  519. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  520. void (asio::error_code, std::size_t))
  521. async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
  522. ASIO_MOVE_ARG(WriteHandler) handler);
  523. /// Start an asynchronous operation to write a certain amount of data to a
  524. /// stream.
  525. /**
  526. * This function is used to asynchronously write a certain number of bytes of
  527. * data to a stream. The function call always returns immediately. The
  528. * asynchronous operation will continue until one of the following conditions
  529. * is true:
  530. *
  531. * @li All of the data in the supplied basic_streambuf has been written.
  532. *
  533. * @li The completion_condition function object returns 0.
  534. *
  535. * This operation is implemented in terms of zero or more calls to the stream's
  536. * async_write_some function, and is known as a <em>composed operation</em>. The
  537. * program must ensure that the stream performs no other write operations (such
  538. * as async_write, the stream's async_write_some function, or any other composed
  539. * operations that perform writes) until this operation completes.
  540. *
  541. * @param s The stream to which the data is to be written. The type must support
  542. * the AsyncWriteStream concept.
  543. *
  544. * @param b A basic_streambuf object from which data will be written. Ownership
  545. * of the streambuf is retained by the caller, which must guarantee that it
  546. * remains valid until the handler is called.
  547. *
  548. * @param completion_condition The function object to be called to determine
  549. * whether the write operation is complete. The signature of the function object
  550. * must be:
  551. * @code std::size_t completion_condition(
  552. * // Result of latest async_write_some operation.
  553. * const asio::error_code& error,
  554. *
  555. * // Number of bytes transferred so far.
  556. * std::size_t bytes_transferred
  557. * ); @endcode
  558. * A return value of 0 indicates that the write operation is complete. A
  559. * non-zero return value indicates the maximum number of bytes to be written on
  560. * the next call to the stream's async_write_some function.
  561. *
  562. * @param handler The handler to be called when the write operation completes.
  563. * Copies will be made of the handler as required. The function signature of the
  564. * handler must be:
  565. * @code void handler(
  566. * const asio::error_code& error, // Result of operation.
  567. *
  568. * std::size_t bytes_transferred // Number of bytes written from the
  569. * // buffers. If an error occurred,
  570. * // this will be less than the sum
  571. * // of the buffer sizes.
  572. * ); @endcode
  573. * Regardless of whether the asynchronous operation completes immediately or
  574. * not, the handler will not be invoked from within this function. Invocation of
  575. * the handler will be performed in a manner equivalent to using
  576. * asio::io_service::post().
  577. */
  578. template <typename AsyncWriteStream, typename Allocator,
  579. typename CompletionCondition, typename WriteHandler>
  580. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  581. void (asio::error_code, std::size_t))
  582. async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
  583. CompletionCondition completion_condition,
  584. ASIO_MOVE_ARG(WriteHandler) handler);
  585. #endif // !defined(ASIO_NO_IOSTREAM)
  586. /*@}*/
  587. } // namespace asio
  588. #include "asio/detail/pop_options.hpp"
  589. #include "asio/impl/write.hpp"
  590. #endif // ASIO_WRITE_HPP