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