5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_WRITE_HPP
12 #define BOOST_ASIO_WRITE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #include <boost/asio/async_result.hpp>
21 #include <boost/asio/buffer.hpp>
22 #include <boost/asio/error.hpp>
24 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
25 # include <boost/asio/basic_streambuf_fwd.hpp>
26 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
28 #include <boost/asio/detail/push_options.hpp>
34 * @defgroup write boost::asio::write
36 * @brief The @c write function is a composed operation that writes a certain
37 * amount of data to a stream before returning.
41 /// Write all of the supplied data to a stream before returning.
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:
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.
49 * @li An error occurred.
51 * This operation is implemented in terms of zero or more calls to the stream's
52 * write_some function.
54 * @param s The stream to which the data is to be written. The type must support
55 * the SyncWriteStream concept.
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
61 * @returns The number of bytes transferred.
63 * @throws boost::system::system_error Thrown on failure.
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
72 * @note This overload is equivalent to calling:
73 * @code boost::asio::write(
75 * boost::asio::transfer_all()); @endcode
77 template <typename SyncWriteStream, typename ConstBufferSequence>
78 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
80 is_const_buffer_sequence<ConstBufferSequence>::value
83 /// Write all of the supplied data to a stream before returning.
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:
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.
91 * @li An error occurred.
93 * This operation is implemented in terms of zero or more calls to the stream's
94 * write_some function.
96 * @param s The stream to which the data is to be written. The type must support
97 * the SyncWriteStream concept.
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
103 * @param ec Set to indicate what error occurred, if any.
105 * @returns The number of bytes transferred.
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
114 * @note This overload is equivalent to calling:
115 * @code boost::asio::write(
117 * boost::asio::transfer_all(), ec); @endcode
119 template <typename SyncWriteStream, typename ConstBufferSequence>
120 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
121 boost::system::error_code& ec,
123 is_const_buffer_sequence<ConstBufferSequence>::value
126 /// Write a certain amount of data to a stream before returning.
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:
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.
134 * @li The completion_condition function object returns 0.
136 * This operation is implemented in terms of zero or more calls to the stream's
137 * write_some function.
139 * @param s The stream to which the data is to be written. The type must support
140 * the SyncWriteStream concept.
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
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
149 * @code std::size_t completion_condition(
150 * // Result of latest write_some operation.
151 * const boost::system::error_code& error,
153 * // Number of bytes transferred so far.
154 * std::size_t bytes_transferred
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.
160 * @returns The number of bytes transferred.
162 * @throws boost::system::system_error Thrown on failure.
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
172 template <typename SyncWriteStream, typename ConstBufferSequence,
173 typename CompletionCondition>
174 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
175 CompletionCondition completion_condition,
177 is_const_buffer_sequence<ConstBufferSequence>::value
180 /// Write a certain amount of data to a stream before returning.
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:
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.
188 * @li The completion_condition function object returns 0.
190 * This operation is implemented in terms of zero or more calls to the stream's
191 * write_some function.
193 * @param s The stream to which the data is to be written. The type must support
194 * the SyncWriteStream concept.
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
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
203 * @code std::size_t completion_condition(
204 * // Result of latest write_some operation.
205 * const boost::system::error_code& error,
207 * // Number of bytes transferred so far.
208 * std::size_t bytes_transferred
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.
214 * @param ec Set to indicate what error occurred, if any.
216 * @returns The number of bytes written. If an error occurs, returns the total
217 * number of bytes successfully transferred prior to the error.
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,
224 is_const_buffer_sequence<ConstBufferSequence>::value
227 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
229 /// Write all of the supplied data to a stream before returning.
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:
234 * @li All of the data in the supplied dynamic buffer sequence has been written.
236 * @li An error occurred.
238 * This operation is implemented in terms of zero or more calls to the stream's
239 * write_some function.
241 * @param s The stream to which the data is to be written. The type must support
242 * the SyncWriteStream concept.
244 * @param buffers The dynamic buffer sequence from which data will be written.
245 * Successfully written data is automatically consumed from the buffers.
247 * @returns The number of bytes transferred.
249 * @throws boost::system::system_error Thrown on failure.
251 * @note This overload is equivalent to calling:
252 * @code boost::asio::write(
254 * boost::asio::transfer_all()); @endcode
256 template <typename SyncWriteStream, typename DynamicBuffer_v1>
257 std::size_t write(SyncWriteStream& s,
258 BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
260 is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
261 && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
264 /// Write all of the supplied data to a stream before returning.
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:
269 * @li All of the data in the supplied dynamic buffer sequence has been written.
271 * @li An error occurred.
273 * This operation is implemented in terms of zero or more calls to the stream's
274 * write_some function.
276 * @param s The stream to which the data is to be written. The type must support
277 * the SyncWriteStream concept.
279 * @param buffers The dynamic buffer sequence from which data will be written.
280 * Successfully written data is automatically consumed from the buffers.
282 * @param ec Set to indicate what error occurred, if any.
284 * @returns The number of bytes transferred.
286 * @note This overload is equivalent to calling:
287 * @code boost::asio::write(
289 * boost::asio::transfer_all(), ec); @endcode
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,
296 is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
297 && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
300 /// Write a certain amount of data to a stream before returning.
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:
305 * @li All of the data in the supplied dynamic buffer sequence has been written.
307 * @li The completion_condition function object returns 0.
309 * This operation is implemented in terms of zero or more calls to the stream's
310 * write_some function.
312 * @param s The stream to which the data is to be written. The type must support
313 * the SyncWriteStream concept.
315 * @param buffers The dynamic buffer sequence from which data will be written.
316 * Successfully written data is automatically consumed from the buffers.
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
321 * @code std::size_t completion_condition(
322 * // Result of latest write_some operation.
323 * const boost::system::error_code& error,
325 * // Number of bytes transferred so far.
326 * std::size_t bytes_transferred
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.
332 * @returns The number of bytes transferred.
334 * @throws boost::system::system_error Thrown on failure.
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,
342 is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
343 && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
346 /// Write a certain amount of data to a stream before returning.
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:
351 * @li All of the data in the supplied dynamic buffer sequence has been written.
353 * @li The completion_condition function object returns 0.
355 * This operation is implemented in terms of zero or more calls to the stream's
356 * write_some function.
358 * @param s The stream to which the data is to be written. The type must support
359 * the SyncWriteStream concept.
361 * @param buffers The dynamic buffer sequence from which data will be written.
362 * Successfully written data is automatically consumed from the buffers.
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
367 * @code std::size_t completion_condition(
368 * // Result of latest write_some operation.
369 * const boost::system::error_code& error,
371 * // Number of bytes transferred so far.
372 * std::size_t bytes_transferred
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.
378 * @param ec Set to indicate what error occurred, if any.
380 * @returns The number of bytes written. If an error occurs, returns the total
381 * number of bytes successfully transferred prior to the error.
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,
389 is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
390 && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
393 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
394 #if !defined(BOOST_ASIO_NO_IOSTREAM)
396 /// Write all of the supplied data to a stream before returning.
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:
401 * @li All of the data in the supplied basic_streambuf has been written.
403 * @li An error occurred.
405 * This operation is implemented in terms of zero or more calls to the stream's
406 * write_some function.
408 * @param s The stream to which the data is to be written. The type must support
409 * the SyncWriteStream concept.
411 * @param b The basic_streambuf object from which data will be written.
413 * @returns The number of bytes transferred.
415 * @throws boost::system::system_error Thrown on failure.
417 * @note This overload is equivalent to calling:
418 * @code boost::asio::write(
420 * boost::asio::transfer_all()); @endcode
422 template <typename SyncWriteStream, typename Allocator>
423 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b);
425 /// Write all of the supplied data to a stream before returning.
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:
430 * @li All of the data in the supplied basic_streambuf has been written.
432 * @li An error occurred.
434 * This operation is implemented in terms of zero or more calls to the stream's
435 * write_some function.
437 * @param s The stream to which the data is to be written. The type must support
438 * the SyncWriteStream concept.
440 * @param b The basic_streambuf object from which data will be written.
442 * @param ec Set to indicate what error occurred, if any.
444 * @returns The number of bytes transferred.
446 * @note This overload is equivalent to calling:
447 * @code boost::asio::write(
449 * boost::asio::transfer_all(), ec); @endcode
451 template <typename SyncWriteStream, typename Allocator>
452 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
453 boost::system::error_code& ec);
455 /// Write a certain amount of data to a stream before returning.
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:
460 * @li All of the data in the supplied basic_streambuf has been written.
462 * @li The completion_condition function object returns 0.
464 * This operation is implemented in terms of zero or more calls to the stream's
465 * write_some function.
467 * @param s The stream to which the data is to be written. The type must support
468 * the SyncWriteStream concept.
470 * @param b The basic_streambuf object from which data will be written.
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
475 * @code std::size_t completion_condition(
476 * // Result of latest write_some operation.
477 * const boost::system::error_code& error,
479 * // Number of bytes transferred so far.
480 * std::size_t bytes_transferred
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.
486 * @returns The number of bytes transferred.
488 * @throws boost::system::system_error Thrown on failure.
490 template <typename SyncWriteStream, typename Allocator,
491 typename CompletionCondition>
492 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
493 CompletionCondition completion_condition);
495 /// Write a certain amount of data to a stream before returning.
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:
500 * @li All of the data in the supplied basic_streambuf has been written.
502 * @li The completion_condition function object returns 0.
504 * This operation is implemented in terms of zero or more calls to the stream's
505 * write_some function.
507 * @param s The stream to which the data is to be written. The type must support
508 * the SyncWriteStream concept.
510 * @param b The basic_streambuf object from which data will be written.
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
515 * @code std::size_t completion_condition(
516 * // Result of latest write_some operation.
517 * const boost::system::error_code& error,
519 * // Number of bytes transferred so far.
520 * std::size_t bytes_transferred
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.
526 * @param ec Set to indicate what error occurred, if any.
528 * @returns The number of bytes written. If an error occurs, returns the total
529 * number of bytes successfully transferred prior to the error.
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);
536 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
537 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
538 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
540 /// Write all of the supplied data to a stream before returning.
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:
545 * @li All of the data in the supplied dynamic buffer sequence has been written.
547 * @li An error occurred.
549 * This operation is implemented in terms of zero or more calls to the stream's
550 * write_some function.
552 * @param s The stream to which the data is to be written. The type must support
553 * the SyncWriteStream concept.
555 * @param buffers The dynamic buffer sequence from which data will be written.
556 * Successfully written data is automatically consumed from the buffers.
558 * @returns The number of bytes transferred.
560 * @throws boost::system::system_error Thrown on failure.
562 * @note This overload is equivalent to calling:
563 * @code boost::asio::write(
565 * boost::asio::transfer_all()); @endcode
567 template <typename SyncWriteStream, typename DynamicBuffer_v2>
568 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
570 is_dynamic_buffer_v2<DynamicBuffer_v2>::value
573 /// Write all of the supplied data to a stream before returning.
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:
578 * @li All of the data in the supplied dynamic buffer sequence has been written.
580 * @li An error occurred.
582 * This operation is implemented in terms of zero or more calls to the stream's
583 * write_some function.
585 * @param s The stream to which the data is to be written. The type must support
586 * the SyncWriteStream concept.
588 * @param buffers The dynamic buffer sequence from which data will be written.
589 * Successfully written data is automatically consumed from the buffers.
591 * @param ec Set to indicate what error occurred, if any.
593 * @returns The number of bytes transferred.
595 * @note This overload is equivalent to calling:
596 * @code boost::asio::write(
598 * boost::asio::transfer_all(), ec); @endcode
600 template <typename SyncWriteStream, typename DynamicBuffer_v2>
601 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
602 boost::system::error_code& ec,
604 is_dynamic_buffer_v2<DynamicBuffer_v2>::value
607 /// Write a certain amount of data to a stream before returning.
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:
612 * @li All of the data in the supplied dynamic buffer sequence has been written.
614 * @li The completion_condition function object returns 0.
616 * This operation is implemented in terms of zero or more calls to the stream's
617 * write_some function.
619 * @param s The stream to which the data is to be written. The type must support
620 * the SyncWriteStream concept.
622 * @param buffers The dynamic buffer sequence from which data will be written.
623 * Successfully written data is automatically consumed from the buffers.
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
628 * @code std::size_t completion_condition(
629 * // Result of latest write_some operation.
630 * const boost::system::error_code& error,
632 * // Number of bytes transferred so far.
633 * std::size_t bytes_transferred
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.
639 * @returns The number of bytes transferred.
641 * @throws boost::system::system_error Thrown on failure.
643 template <typename SyncWriteStream, typename DynamicBuffer_v2,
644 typename CompletionCondition>
645 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
646 CompletionCondition completion_condition,
648 is_dynamic_buffer_v2<DynamicBuffer_v2>::value
651 /// Write a certain amount of data to a stream before returning.
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:
656 * @li All of the data in the supplied dynamic buffer sequence has been written.
658 * @li The completion_condition function object returns 0.
660 * This operation is implemented in terms of zero or more calls to the stream's
661 * write_some function.
663 * @param s The stream to which the data is to be written. The type must support
664 * the SyncWriteStream concept.
666 * @param buffers The dynamic buffer sequence from which data will be written.
667 * Successfully written data is automatically consumed from the buffers.
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
672 * @code std::size_t completion_condition(
673 * // Result of latest write_some operation.
674 * const boost::system::error_code& error,
676 * // Number of bytes transferred so far.
677 * std::size_t bytes_transferred
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.
683 * @param ec Set to indicate what error occurred, if any.
685 * @returns The number of bytes written. If an error occurs, returns the total
686 * number of bytes successfully transferred prior to the error.
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,
693 is_dynamic_buffer_v2<DynamicBuffer_v2>::value
698 * @defgroup async_write boost::asio::async_write
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.
705 /// Start an asynchronous operation to write all of the supplied data to a
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
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.
716 * @li An error occurred.
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.
724 * @param s The stream to which the data is to be written. The type must support
725 * the AsyncWriteStream concept.
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.
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.
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.
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().
749 * To write a single data buffer use the @ref buffer function as follows:
751 * boost::asio::async_write(s, boost::asio::buffer(data, size), handler);
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
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),
769 is_const_buffer_sequence<ConstBufferSequence>::value
772 /// Start an asynchronous operation to write a certain amount of data to a
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
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.
783 * @li The completion_condition function object returns 0.
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.
791 * @param s The stream to which the data is to be written. The type must support
792 * the AsyncWriteStream concept.
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.
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
802 * @code std::size_t completion_condition(
803 * // Result of latest async_write_some operation.
804 * const boost::system::error_code& error,
806 * // Number of bytes transferred so far.
807 * std::size_t bytes_transferred
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.
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
816 * @code void handler(
817 * const boost::system::error_code& error, // Result of operation.
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.
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().
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),
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
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,
849 is_const_buffer_sequence<ConstBufferSequence>::value
852 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
854 /// Start an asynchronous operation to write all of the supplied data to a
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
862 * @li All of the data in the supplied dynamic buffer sequence has been written.
864 * @li An error occurred.
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.
872 * @param s The stream to which the data is to be written. The type must support
873 * the AsyncWriteStream concept.
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.
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
884 * @code void handler(
885 * const boost::system::error_code& error, // Result of operation.
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.
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().
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),
910 is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
911 && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
914 /// Start an asynchronous operation to write a certain amount of data to a
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
922 * @li All of the data in the supplied dynamic buffer sequence has been written.
924 * @li The completion_condition function object returns 0.
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.
932 * @param s The stream to which the data is to be written. The type must support
933 * the AsyncWriteStream concept.
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.
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
944 * @code std::size_t completion_condition(
945 * // Result of latest async_write_some operation.
946 * const boost::system::error_code& error,
948 * // Number of bytes transferred so far.
949 * std::size_t bytes_transferred
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.
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
958 * @code void handler(
959 * const boost::system::error_code& error, // Result of operation.
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.
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().
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,
982 is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
983 && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
986 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
987 #if !defined(BOOST_ASIO_NO_IOSTREAM)
989 /// Start an asynchronous operation to write all of the supplied data to a
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
997 * @li All of the data in the supplied basic_streambuf has been written.
999 * @li An error occurred.
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.
1007 * @param s The stream to which the data is to be written. The type must support
1008 * the AsyncWriteStream concept.
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.
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
1017 * @code void handler(
1018 * const boost::system::error_code& error, // Result of operation.
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.
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().
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));
1042 /// Start an asynchronous operation to write a certain amount of data to a
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
1050 * @li All of the data in the supplied basic_streambuf has been written.
1052 * @li The completion_condition function object returns 0.
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.
1060 * @param s The stream to which the data is to be written. The type must support
1061 * the AsyncWriteStream concept.
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.
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
1070 * @code std::size_t completion_condition(
1071 * // Result of latest async_write_some operation.
1072 * const boost::system::error_code& error,
1074 * // Number of bytes transferred so far.
1075 * std::size_t bytes_transferred
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.
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
1084 * @code void handler(
1085 * const boost::system::error_code& error, // Result of operation.
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.
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().
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);
1107 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
1108 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
1109 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
1111 /// Start an asynchronous operation to write all of the supplied data to a
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
1119 * @li All of the data in the supplied dynamic buffer sequence has been written.
1121 * @li An error occurred.
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.
1129 * @param s The stream to which the data is to be written. The type must support
1130 * the AsyncWriteStream concept.
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.
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
1141 * @code void handler(
1142 * const boost::system::error_code& error, // Result of operation.
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.
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().
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),
1166 is_dynamic_buffer_v2<DynamicBuffer_v2>::value
1169 /// Start an asynchronous operation to write a certain amount of data to a
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
1177 * @li All of the data in the supplied dynamic buffer sequence has been written.
1179 * @li The completion_condition function object returns 0.
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.
1187 * @param s The stream to which the data is to be written. The type must support
1188 * the AsyncWriteStream concept.
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.
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
1199 * @code std::size_t completion_condition(
1200 * // Result of latest async_write_some operation.
1201 * const boost::system::error_code& error,
1203 * // Number of bytes transferred so far.
1204 * std::size_t bytes_transferred
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.
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
1213 * @code void handler(
1214 * const boost::system::error_code& error, // Result of operation.
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.
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().
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,
1236 is_dynamic_buffer_v2<DynamicBuffer_v2>::value
1242 } // namespace boost
1244 #include <boost/asio/detail/pop_options.hpp>
1246 #include <boost/asio/impl/write.hpp>
1248 #endif // BOOST_ASIO_WRITE_HPP