xref: /aosp_15_r20/external/parameter-framework/asio-1.10.6/include/asio/write.hpp (revision c33452fb792a5495ec310a9626f2638b053af5dd)
1*c33452fbSAndroid Build Coastguard Worker //
2*c33452fbSAndroid Build Coastguard Worker // write.hpp
3*c33452fbSAndroid Build Coastguard Worker // ~~~~~~~~~
4*c33452fbSAndroid Build Coastguard Worker //
5*c33452fbSAndroid Build Coastguard Worker // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6*c33452fbSAndroid Build Coastguard Worker //
7*c33452fbSAndroid Build Coastguard Worker // Distributed under the Boost Software License, Version 1.0. (See accompanying
8*c33452fbSAndroid Build Coastguard Worker // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9*c33452fbSAndroid Build Coastguard Worker //
10*c33452fbSAndroid Build Coastguard Worker 
11*c33452fbSAndroid Build Coastguard Worker #ifndef ASIO_WRITE_HPP
12*c33452fbSAndroid Build Coastguard Worker #define ASIO_WRITE_HPP
13*c33452fbSAndroid Build Coastguard Worker 
14*c33452fbSAndroid Build Coastguard Worker 
15*c33452fbSAndroid Build Coastguard Worker #include "asio/detail/config.hpp"
16*c33452fbSAndroid Build Coastguard Worker #include <cstddef>
17*c33452fbSAndroid Build Coastguard Worker #include "asio/async_result.hpp"
18*c33452fbSAndroid Build Coastguard Worker #include "asio/basic_streambuf_fwd.hpp"
19*c33452fbSAndroid Build Coastguard Worker #include "asio/error.hpp"
20*c33452fbSAndroid Build Coastguard Worker 
21*c33452fbSAndroid Build Coastguard Worker #include "asio/detail/push_options.hpp"
22*c33452fbSAndroid Build Coastguard Worker 
23*c33452fbSAndroid Build Coastguard Worker namespace asio {
24*c33452fbSAndroid Build Coastguard Worker 
25*c33452fbSAndroid Build Coastguard Worker /**
26*c33452fbSAndroid Build Coastguard Worker  * @defgroup write asio::write
27*c33452fbSAndroid Build Coastguard Worker  *
28*c33452fbSAndroid Build Coastguard Worker  * @brief Write a certain amount of data to a stream before returning.
29*c33452fbSAndroid Build Coastguard Worker  */
30*c33452fbSAndroid Build Coastguard Worker /*@{*/
31*c33452fbSAndroid Build Coastguard Worker 
32*c33452fbSAndroid Build Coastguard Worker /// Write all of the supplied data to a stream before returning.
33*c33452fbSAndroid Build Coastguard Worker /**
34*c33452fbSAndroid Build Coastguard Worker  * This function is used to write a certain number of bytes of data to a stream.
35*c33452fbSAndroid Build Coastguard Worker  * The call will block until one of the following conditions is true:
36*c33452fbSAndroid Build Coastguard Worker  *
37*c33452fbSAndroid Build Coastguard Worker  * @li All of the data in the supplied buffers has been written. That is, the
38*c33452fbSAndroid Build Coastguard Worker  * bytes transferred is equal to the sum of the buffer sizes.
39*c33452fbSAndroid Build Coastguard Worker  *
40*c33452fbSAndroid Build Coastguard Worker  * @li An error occurred.
41*c33452fbSAndroid Build Coastguard Worker  *
42*c33452fbSAndroid Build Coastguard Worker  * This operation is implemented in terms of zero or more calls to the stream's
43*c33452fbSAndroid Build Coastguard Worker  * write_some function.
44*c33452fbSAndroid Build Coastguard Worker  *
45*c33452fbSAndroid Build Coastguard Worker  * @param s The stream to which the data is to be written. The type must support
46*c33452fbSAndroid Build Coastguard Worker  * the SyncWriteStream concept.
47*c33452fbSAndroid Build Coastguard Worker  *
48*c33452fbSAndroid Build Coastguard Worker  * @param buffers One or more buffers containing the data to be written. The sum
49*c33452fbSAndroid Build Coastguard Worker  * of the buffer sizes indicates the maximum number of bytes to write to the
50*c33452fbSAndroid Build Coastguard Worker  * stream.
51*c33452fbSAndroid Build Coastguard Worker  *
52*c33452fbSAndroid Build Coastguard Worker  * @returns The number of bytes transferred.
53*c33452fbSAndroid Build Coastguard Worker  *
54*c33452fbSAndroid Build Coastguard Worker  * @throws asio::system_error Thrown on failure.
55*c33452fbSAndroid Build Coastguard Worker  *
56*c33452fbSAndroid Build Coastguard Worker  * @par Example
57*c33452fbSAndroid Build Coastguard Worker  * To write a single data buffer use the @ref buffer function as follows:
58*c33452fbSAndroid Build Coastguard Worker  * @code asio::write(s, asio::buffer(data, size)); @endcode
59*c33452fbSAndroid Build Coastguard Worker  * See the @ref buffer documentation for information on writing multiple
60*c33452fbSAndroid Build Coastguard Worker  * buffers in one go, and how to use it with arrays, boost::array or
61*c33452fbSAndroid Build Coastguard Worker  * std::vector.
62*c33452fbSAndroid Build Coastguard Worker  *
63*c33452fbSAndroid Build Coastguard Worker  * @note This overload is equivalent to calling:
64*c33452fbSAndroid Build Coastguard Worker  * @code asio::write(
65*c33452fbSAndroid Build Coastguard Worker  *     s, buffers,
66*c33452fbSAndroid Build Coastguard Worker  *     asio::transfer_all()); @endcode
67*c33452fbSAndroid Build Coastguard Worker  */
68*c33452fbSAndroid Build Coastguard Worker template <typename SyncWriteStream, typename ConstBufferSequence>
69*c33452fbSAndroid Build Coastguard Worker std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers);
70*c33452fbSAndroid Build Coastguard Worker 
71*c33452fbSAndroid Build Coastguard Worker /// Write all of the supplied data to a stream before returning.
72*c33452fbSAndroid Build Coastguard Worker /**
73*c33452fbSAndroid Build Coastguard Worker  * This function is used to write a certain number of bytes of data to a stream.
74*c33452fbSAndroid Build Coastguard Worker  * The call will block until one of the following conditions is true:
75*c33452fbSAndroid Build Coastguard Worker  *
76*c33452fbSAndroid Build Coastguard Worker  * @li All of the data in the supplied buffers has been written. That is, the
77*c33452fbSAndroid Build Coastguard Worker  * bytes transferred is equal to the sum of the buffer sizes.
78*c33452fbSAndroid Build Coastguard Worker  *
79*c33452fbSAndroid Build Coastguard Worker  * @li An error occurred.
80*c33452fbSAndroid Build Coastguard Worker  *
81*c33452fbSAndroid Build Coastguard Worker  * This operation is implemented in terms of zero or more calls to the stream's
82*c33452fbSAndroid Build Coastguard Worker  * write_some function.
83*c33452fbSAndroid Build Coastguard Worker  *
84*c33452fbSAndroid Build Coastguard Worker  * @param s The stream to which the data is to be written. The type must support
85*c33452fbSAndroid Build Coastguard Worker  * the SyncWriteStream concept.
86*c33452fbSAndroid Build Coastguard Worker  *
87*c33452fbSAndroid Build Coastguard Worker  * @param buffers One or more buffers containing the data to be written. The sum
88*c33452fbSAndroid Build Coastguard Worker  * of the buffer sizes indicates the maximum number of bytes to write to the
89*c33452fbSAndroid Build Coastguard Worker  * stream.
90*c33452fbSAndroid Build Coastguard Worker  *
91*c33452fbSAndroid Build Coastguard Worker  * @param ec Set to indicate what error occurred, if any.
92*c33452fbSAndroid Build Coastguard Worker  *
93*c33452fbSAndroid Build Coastguard Worker  * @returns The number of bytes transferred.
94*c33452fbSAndroid Build Coastguard Worker  *
95*c33452fbSAndroid Build Coastguard Worker  * @par Example
96*c33452fbSAndroid Build Coastguard Worker  * To write a single data buffer use the @ref buffer function as follows:
97*c33452fbSAndroid Build Coastguard Worker  * @code asio::write(s, asio::buffer(data, size), ec); @endcode
98*c33452fbSAndroid Build Coastguard Worker  * See the @ref buffer documentation for information on writing multiple
99*c33452fbSAndroid Build Coastguard Worker  * buffers in one go, and how to use it with arrays, boost::array or
100*c33452fbSAndroid Build Coastguard Worker  * std::vector.
101*c33452fbSAndroid Build Coastguard Worker  *
102*c33452fbSAndroid Build Coastguard Worker  * @note This overload is equivalent to calling:
103*c33452fbSAndroid Build Coastguard Worker  * @code asio::write(
104*c33452fbSAndroid Build Coastguard Worker  *     s, buffers,
105*c33452fbSAndroid Build Coastguard Worker  *     asio::transfer_all(), ec); @endcode
106*c33452fbSAndroid Build Coastguard Worker  */
107*c33452fbSAndroid Build Coastguard Worker template <typename SyncWriteStream, typename ConstBufferSequence>
108*c33452fbSAndroid Build Coastguard Worker std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
109*c33452fbSAndroid Build Coastguard Worker     asio::error_code& ec);
110*c33452fbSAndroid Build Coastguard Worker 
111*c33452fbSAndroid Build Coastguard Worker /// Write a certain amount of data to a stream before returning.
112*c33452fbSAndroid Build Coastguard Worker /**
113*c33452fbSAndroid Build Coastguard Worker  * This function is used to write a certain number of bytes of data to a stream.
114*c33452fbSAndroid Build Coastguard Worker  * The call will block until one of the following conditions is true:
115*c33452fbSAndroid Build Coastguard Worker  *
116*c33452fbSAndroid Build Coastguard Worker  * @li All of the data in the supplied buffers has been written. That is, the
117*c33452fbSAndroid Build Coastguard Worker  * bytes transferred is equal to the sum of the buffer sizes.
118*c33452fbSAndroid Build Coastguard Worker  *
119*c33452fbSAndroid Build Coastguard Worker  * @li The completion_condition function object returns 0.
120*c33452fbSAndroid Build Coastguard Worker  *
121*c33452fbSAndroid Build Coastguard Worker  * This operation is implemented in terms of zero or more calls to the stream's
122*c33452fbSAndroid Build Coastguard Worker  * write_some function.
123*c33452fbSAndroid Build Coastguard Worker  *
124*c33452fbSAndroid Build Coastguard Worker  * @param s The stream to which the data is to be written. The type must support
125*c33452fbSAndroid Build Coastguard Worker  * the SyncWriteStream concept.
126*c33452fbSAndroid Build Coastguard Worker  *
127*c33452fbSAndroid Build Coastguard Worker  * @param buffers One or more buffers containing the data to be written. The sum
128*c33452fbSAndroid Build Coastguard Worker  * of the buffer sizes indicates the maximum number of bytes to write to the
129*c33452fbSAndroid Build Coastguard Worker  * stream.
130*c33452fbSAndroid Build Coastguard Worker  *
131*c33452fbSAndroid Build Coastguard Worker  * @param completion_condition The function object to be called to determine
132*c33452fbSAndroid Build Coastguard Worker  * whether the write operation is complete. The signature of the function object
133*c33452fbSAndroid Build Coastguard Worker  * must be:
134*c33452fbSAndroid Build Coastguard Worker  * @code std::size_t completion_condition(
135*c33452fbSAndroid Build Coastguard Worker  *   // Result of latest write_some operation.
136*c33452fbSAndroid Build Coastguard Worker  *   const asio::error_code& error,
137*c33452fbSAndroid Build Coastguard Worker  *
138*c33452fbSAndroid Build Coastguard Worker  *   // Number of bytes transferred so far.
139*c33452fbSAndroid Build Coastguard Worker  *   std::size_t bytes_transferred
140*c33452fbSAndroid Build Coastguard Worker  * ); @endcode
141*c33452fbSAndroid Build Coastguard Worker  * A return value of 0 indicates that the write operation is complete. A
142*c33452fbSAndroid Build Coastguard Worker  * non-zero return value indicates the maximum number of bytes to be written on
143*c33452fbSAndroid Build Coastguard Worker  * the next call to the stream's write_some function.
144*c33452fbSAndroid Build Coastguard Worker  *
145*c33452fbSAndroid Build Coastguard Worker  * @returns The number of bytes transferred.
146*c33452fbSAndroid Build Coastguard Worker  *
147*c33452fbSAndroid Build Coastguard Worker  * @throws asio::system_error Thrown on failure.
148*c33452fbSAndroid Build Coastguard Worker  *
149*c33452fbSAndroid Build Coastguard Worker  * @par Example
150*c33452fbSAndroid Build Coastguard Worker  * To write a single data buffer use the @ref buffer function as follows:
151*c33452fbSAndroid Build Coastguard Worker  * @code asio::write(s, asio::buffer(data, size),
152*c33452fbSAndroid Build Coastguard Worker  *     asio::transfer_at_least(32)); @endcode
153*c33452fbSAndroid Build Coastguard Worker  * See the @ref buffer documentation for information on writing multiple
154*c33452fbSAndroid Build Coastguard Worker  * buffers in one go, and how to use it with arrays, boost::array or
155*c33452fbSAndroid Build Coastguard Worker  * std::vector.
156*c33452fbSAndroid Build Coastguard Worker  */
157*c33452fbSAndroid Build Coastguard Worker template <typename SyncWriteStream, typename ConstBufferSequence,
158*c33452fbSAndroid Build Coastguard Worker     typename CompletionCondition>
159*c33452fbSAndroid Build Coastguard Worker std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
160*c33452fbSAndroid Build Coastguard Worker     CompletionCondition completion_condition);
161*c33452fbSAndroid Build Coastguard Worker 
162*c33452fbSAndroid Build Coastguard Worker /// Write a certain amount of data to a stream before returning.
163*c33452fbSAndroid Build Coastguard Worker /**
164*c33452fbSAndroid Build Coastguard Worker  * This function is used to write a certain number of bytes of data to a stream.
165*c33452fbSAndroid Build Coastguard Worker  * The call will block until one of the following conditions is true:
166*c33452fbSAndroid Build Coastguard Worker  *
167*c33452fbSAndroid Build Coastguard Worker  * @li All of the data in the supplied buffers has been written. That is, the
168*c33452fbSAndroid Build Coastguard Worker  * bytes transferred is equal to the sum of the buffer sizes.
169*c33452fbSAndroid Build Coastguard Worker  *
170*c33452fbSAndroid Build Coastguard Worker  * @li The completion_condition function object returns 0.
171*c33452fbSAndroid Build Coastguard Worker  *
172*c33452fbSAndroid Build Coastguard Worker  * This operation is implemented in terms of zero or more calls to the stream's
173*c33452fbSAndroid Build Coastguard Worker  * write_some function.
174*c33452fbSAndroid Build Coastguard Worker  *
175*c33452fbSAndroid Build Coastguard Worker  * @param s The stream to which the data is to be written. The type must support
176*c33452fbSAndroid Build Coastguard Worker  * the SyncWriteStream concept.
177*c33452fbSAndroid Build Coastguard Worker  *
178*c33452fbSAndroid Build Coastguard Worker  * @param buffers One or more buffers containing the data to be written. The sum
179*c33452fbSAndroid Build Coastguard Worker  * of the buffer sizes indicates the maximum number of bytes to write to the
180*c33452fbSAndroid Build Coastguard Worker  * stream.
181*c33452fbSAndroid Build Coastguard Worker  *
182*c33452fbSAndroid Build Coastguard Worker  * @param completion_condition The function object to be called to determine
183*c33452fbSAndroid Build Coastguard Worker  * whether the write operation is complete. The signature of the function object
184*c33452fbSAndroid Build Coastguard Worker  * must be:
185*c33452fbSAndroid Build Coastguard Worker  * @code std::size_t completion_condition(
186*c33452fbSAndroid Build Coastguard Worker  *   // Result of latest write_some operation.
187*c33452fbSAndroid Build Coastguard Worker  *   const asio::error_code& error,
188*c33452fbSAndroid Build Coastguard Worker  *
189*c33452fbSAndroid Build Coastguard Worker  *   // Number of bytes transferred so far.
190*c33452fbSAndroid Build Coastguard Worker  *   std::size_t bytes_transferred
191*c33452fbSAndroid Build Coastguard Worker  * ); @endcode
192*c33452fbSAndroid Build Coastguard Worker  * A return value of 0 indicates that the write operation is complete. A
193*c33452fbSAndroid Build Coastguard Worker  * non-zero return value indicates the maximum number of bytes to be written on
194*c33452fbSAndroid Build Coastguard Worker  * the next call to the stream's write_some function.
195*c33452fbSAndroid Build Coastguard Worker  *
196*c33452fbSAndroid Build Coastguard Worker  * @param ec Set to indicate what error occurred, if any.
197*c33452fbSAndroid Build Coastguard Worker  *
198*c33452fbSAndroid Build Coastguard Worker  * @returns The number of bytes written. If an error occurs, returns the total
199*c33452fbSAndroid Build Coastguard Worker  * number of bytes successfully transferred prior to the error.
200*c33452fbSAndroid Build Coastguard Worker  */
201*c33452fbSAndroid Build Coastguard Worker template <typename SyncWriteStream, typename ConstBufferSequence,
202*c33452fbSAndroid Build Coastguard Worker     typename CompletionCondition>
203*c33452fbSAndroid Build Coastguard Worker std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
204*c33452fbSAndroid Build Coastguard Worker     CompletionCondition completion_condition, asio::error_code& ec);
205*c33452fbSAndroid Build Coastguard Worker 
206*c33452fbSAndroid Build Coastguard Worker 
207*c33452fbSAndroid Build Coastguard Worker /*@}*/
208*c33452fbSAndroid Build Coastguard Worker /**
209*c33452fbSAndroid Build Coastguard Worker  * @defgroup async_write asio::async_write
210*c33452fbSAndroid Build Coastguard Worker  *
211*c33452fbSAndroid Build Coastguard Worker  * @brief Start an asynchronous operation to write a certain amount of data to a
212*c33452fbSAndroid Build Coastguard Worker  * stream.
213*c33452fbSAndroid Build Coastguard Worker  */
214*c33452fbSAndroid Build Coastguard Worker /*@{*/
215*c33452fbSAndroid Build Coastguard Worker 
216*c33452fbSAndroid Build Coastguard Worker /// Start an asynchronous operation to write all of the supplied data to a
217*c33452fbSAndroid Build Coastguard Worker /// stream.
218*c33452fbSAndroid Build Coastguard Worker /**
219*c33452fbSAndroid Build Coastguard Worker  * This function is used to asynchronously write a certain number of bytes of
220*c33452fbSAndroid Build Coastguard Worker  * data to a stream. The function call always returns immediately. The
221*c33452fbSAndroid Build Coastguard Worker  * asynchronous operation will continue until one of the following conditions
222*c33452fbSAndroid Build Coastguard Worker  * is true:
223*c33452fbSAndroid Build Coastguard Worker  *
224*c33452fbSAndroid Build Coastguard Worker  * @li All of the data in the supplied buffers has been written. That is, the
225*c33452fbSAndroid Build Coastguard Worker  * bytes transferred is equal to the sum of the buffer sizes.
226*c33452fbSAndroid Build Coastguard Worker  *
227*c33452fbSAndroid Build Coastguard Worker  * @li An error occurred.
228*c33452fbSAndroid Build Coastguard Worker  *
229*c33452fbSAndroid Build Coastguard Worker  * This operation is implemented in terms of zero or more calls to the stream's
230*c33452fbSAndroid Build Coastguard Worker  * async_write_some function, and is known as a <em>composed operation</em>. The
231*c33452fbSAndroid Build Coastguard Worker  * program must ensure that the stream performs no other write operations (such
232*c33452fbSAndroid Build Coastguard Worker  * as async_write, the stream's async_write_some function, or any other composed
233*c33452fbSAndroid Build Coastguard Worker  * operations that perform writes) until this operation completes.
234*c33452fbSAndroid Build Coastguard Worker  *
235*c33452fbSAndroid Build Coastguard Worker  * @param s The stream to which the data is to be written. The type must support
236*c33452fbSAndroid Build Coastguard Worker  * the AsyncWriteStream concept.
237*c33452fbSAndroid Build Coastguard Worker  *
238*c33452fbSAndroid Build Coastguard Worker  * @param buffers One or more buffers containing the data to be written.
239*c33452fbSAndroid Build Coastguard Worker  * Although the buffers object may be copied as necessary, ownership of the
240*c33452fbSAndroid Build Coastguard Worker  * underlying memory blocks is retained by the caller, which must guarantee
241*c33452fbSAndroid Build Coastguard Worker  * that they remain valid until the handler is called.
242*c33452fbSAndroid Build Coastguard Worker  *
243*c33452fbSAndroid Build Coastguard Worker  * @param handler The handler to be called when the write operation completes.
244*c33452fbSAndroid Build Coastguard Worker  * Copies will be made of the handler as required. The function signature of
245*c33452fbSAndroid Build Coastguard Worker  * the handler must be:
246*c33452fbSAndroid Build Coastguard Worker  * @code void handler(
247*c33452fbSAndroid Build Coastguard Worker  *   const asio::error_code& error, // Result of operation.
248*c33452fbSAndroid Build Coastguard Worker  *
249*c33452fbSAndroid Build Coastguard Worker  *   std::size_t bytes_transferred           // Number of bytes written from the
250*c33452fbSAndroid Build Coastguard Worker  *                                           // buffers. If an error occurred,
251*c33452fbSAndroid Build Coastguard Worker  *                                           // this will be less than the sum
252*c33452fbSAndroid Build Coastguard Worker  *                                           // of the buffer sizes.
253*c33452fbSAndroid Build Coastguard Worker  * ); @endcode
254*c33452fbSAndroid Build Coastguard Worker  * Regardless of whether the asynchronous operation completes immediately or
255*c33452fbSAndroid Build Coastguard Worker  * not, the handler will not be invoked from within this function. Invocation of
256*c33452fbSAndroid Build Coastguard Worker  * the handler will be performed in a manner equivalent to using
257*c33452fbSAndroid Build Coastguard Worker  * asio::io_service::post().
258*c33452fbSAndroid Build Coastguard Worker  *
259*c33452fbSAndroid Build Coastguard Worker  * @par Example
260*c33452fbSAndroid Build Coastguard Worker  * To write a single data buffer use the @ref buffer function as follows:
261*c33452fbSAndroid Build Coastguard Worker  * @code
262*c33452fbSAndroid Build Coastguard Worker  * asio::async_write(s, asio::buffer(data, size), handler);
263*c33452fbSAndroid Build Coastguard Worker  * @endcode
264*c33452fbSAndroid Build Coastguard Worker  * See the @ref buffer documentation for information on writing multiple
265*c33452fbSAndroid Build Coastguard Worker  * buffers in one go, and how to use it with arrays, boost::array or
266*c33452fbSAndroid Build Coastguard Worker  * std::vector.
267*c33452fbSAndroid Build Coastguard Worker  */
268*c33452fbSAndroid Build Coastguard Worker template <typename AsyncWriteStream, typename ConstBufferSequence,
269*c33452fbSAndroid Build Coastguard Worker     typename WriteHandler>
270*c33452fbSAndroid Build Coastguard Worker ASIO_INITFN_RESULT_TYPE(WriteHandler,
271*c33452fbSAndroid Build Coastguard Worker     void (asio::error_code, std::size_t))
272*c33452fbSAndroid Build Coastguard Worker async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
273*c33452fbSAndroid Build Coastguard Worker     ASIO_MOVE_ARG(WriteHandler) handler);
274*c33452fbSAndroid Build Coastguard Worker 
275*c33452fbSAndroid Build Coastguard Worker /// Start an asynchronous operation to write a certain amount of data to a
276*c33452fbSAndroid Build Coastguard Worker /// stream.
277*c33452fbSAndroid Build Coastguard Worker /**
278*c33452fbSAndroid Build Coastguard Worker  * This function is used to asynchronously write a certain number of bytes of
279*c33452fbSAndroid Build Coastguard Worker  * data to a stream. The function call always returns immediately. The
280*c33452fbSAndroid Build Coastguard Worker  * asynchronous operation will continue until one of the following conditions
281*c33452fbSAndroid Build Coastguard Worker  * is true:
282*c33452fbSAndroid Build Coastguard Worker  *
283*c33452fbSAndroid Build Coastguard Worker  * @li All of the data in the supplied buffers has been written. That is, the
284*c33452fbSAndroid Build Coastguard Worker  * bytes transferred is equal to the sum of the buffer sizes.
285*c33452fbSAndroid Build Coastguard Worker  *
286*c33452fbSAndroid Build Coastguard Worker  * @li The completion_condition function object returns 0.
287*c33452fbSAndroid Build Coastguard Worker  *
288*c33452fbSAndroid Build Coastguard Worker  * This operation is implemented in terms of zero or more calls to the stream's
289*c33452fbSAndroid Build Coastguard Worker  * async_write_some function, and is known as a <em>composed operation</em>. The
290*c33452fbSAndroid Build Coastguard Worker  * program must ensure that the stream performs no other write operations (such
291*c33452fbSAndroid Build Coastguard Worker  * as async_write, the stream's async_write_some function, or any other composed
292*c33452fbSAndroid Build Coastguard Worker  * operations that perform writes) until this operation completes.
293*c33452fbSAndroid Build Coastguard Worker  *
294*c33452fbSAndroid Build Coastguard Worker  * @param s The stream to which the data is to be written. The type must support
295*c33452fbSAndroid Build Coastguard Worker  * the AsyncWriteStream concept.
296*c33452fbSAndroid Build Coastguard Worker  *
297*c33452fbSAndroid Build Coastguard Worker  * @param buffers One or more buffers containing the data to be written.
298*c33452fbSAndroid Build Coastguard Worker  * Although the buffers object may be copied as necessary, ownership of the
299*c33452fbSAndroid Build Coastguard Worker  * underlying memory blocks is retained by the caller, which must guarantee
300*c33452fbSAndroid Build Coastguard Worker  * that they remain valid until the handler is called.
301*c33452fbSAndroid Build Coastguard Worker  *
302*c33452fbSAndroid Build Coastguard Worker  * @param completion_condition The function object to be called to determine
303*c33452fbSAndroid Build Coastguard Worker  * whether the write operation is complete. The signature of the function object
304*c33452fbSAndroid Build Coastguard Worker  * must be:
305*c33452fbSAndroid Build Coastguard Worker  * @code std::size_t completion_condition(
306*c33452fbSAndroid Build Coastguard Worker  *   // Result of latest async_write_some operation.
307*c33452fbSAndroid Build Coastguard Worker  *   const asio::error_code& error,
308*c33452fbSAndroid Build Coastguard Worker  *
309*c33452fbSAndroid Build Coastguard Worker  *   // Number of bytes transferred so far.
310*c33452fbSAndroid Build Coastguard Worker  *   std::size_t bytes_transferred
311*c33452fbSAndroid Build Coastguard Worker  * ); @endcode
312*c33452fbSAndroid Build Coastguard Worker  * A return value of 0 indicates that the write operation is complete. A
313*c33452fbSAndroid Build Coastguard Worker  * non-zero return value indicates the maximum number of bytes to be written on
314*c33452fbSAndroid Build Coastguard Worker  * the next call to the stream's async_write_some function.
315*c33452fbSAndroid Build Coastguard Worker  *
316*c33452fbSAndroid Build Coastguard Worker  * @param handler The handler to be called when the write operation completes.
317*c33452fbSAndroid Build Coastguard Worker  * Copies will be made of the handler as required. The function signature of the
318*c33452fbSAndroid Build Coastguard Worker  * handler must be:
319*c33452fbSAndroid Build Coastguard Worker  * @code void handler(
320*c33452fbSAndroid Build Coastguard Worker  *   const asio::error_code& error, // Result of operation.
321*c33452fbSAndroid Build Coastguard Worker  *
322*c33452fbSAndroid Build Coastguard Worker  *   std::size_t bytes_transferred           // Number of bytes written from the
323*c33452fbSAndroid Build Coastguard Worker  *                                           // buffers. If an error occurred,
324*c33452fbSAndroid Build Coastguard Worker  *                                           // this will be less than the sum
325*c33452fbSAndroid Build Coastguard Worker  *                                           // of the buffer sizes.
326*c33452fbSAndroid Build Coastguard Worker  * ); @endcode
327*c33452fbSAndroid Build Coastguard Worker  * Regardless of whether the asynchronous operation completes immediately or
328*c33452fbSAndroid Build Coastguard Worker  * not, the handler will not be invoked from within this function. Invocation of
329*c33452fbSAndroid Build Coastguard Worker  * the handler will be performed in a manner equivalent to using
330*c33452fbSAndroid Build Coastguard Worker  * asio::io_service::post().
331*c33452fbSAndroid Build Coastguard Worker  *
332*c33452fbSAndroid Build Coastguard Worker  * @par Example
333*c33452fbSAndroid Build Coastguard Worker  * To write a single data buffer use the @ref buffer function as follows:
334*c33452fbSAndroid Build Coastguard Worker  * @code asio::async_write(s,
335*c33452fbSAndroid Build Coastguard Worker  *     asio::buffer(data, size),
336*c33452fbSAndroid Build Coastguard Worker  *     asio::transfer_at_least(32),
337*c33452fbSAndroid Build Coastguard Worker  *     handler); @endcode
338*c33452fbSAndroid Build Coastguard Worker  * See the @ref buffer documentation for information on writing multiple
339*c33452fbSAndroid Build Coastguard Worker  * buffers in one go, and how to use it with arrays, boost::array or
340*c33452fbSAndroid Build Coastguard Worker  * std::vector.
341*c33452fbSAndroid Build Coastguard Worker  */
342*c33452fbSAndroid Build Coastguard Worker template <typename AsyncWriteStream, typename ConstBufferSequence,
343*c33452fbSAndroid Build Coastguard Worker     typename CompletionCondition, typename WriteHandler>
344*c33452fbSAndroid Build Coastguard Worker ASIO_INITFN_RESULT_TYPE(WriteHandler,
345*c33452fbSAndroid Build Coastguard Worker     void (asio::error_code, std::size_t))
346*c33452fbSAndroid Build Coastguard Worker async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
347*c33452fbSAndroid Build Coastguard Worker     CompletionCondition completion_condition,
348*c33452fbSAndroid Build Coastguard Worker     ASIO_MOVE_ARG(WriteHandler) handler);
349*c33452fbSAndroid Build Coastguard Worker 
350*c33452fbSAndroid Build Coastguard Worker 
351*c33452fbSAndroid Build Coastguard Worker /*@}*/
352*c33452fbSAndroid Build Coastguard Worker 
353*c33452fbSAndroid Build Coastguard Worker } // namespace asio
354*c33452fbSAndroid Build Coastguard Worker 
355*c33452fbSAndroid Build Coastguard Worker #include "asio/detail/pop_options.hpp"
356*c33452fbSAndroid Build Coastguard Worker 
357*c33452fbSAndroid Build Coastguard Worker #include "asio/impl/write.hpp"
358*c33452fbSAndroid Build Coastguard Worker 
359*c33452fbSAndroid Build Coastguard Worker #endif // ASIO_WRITE_HPP
360