![]() |
|
|||
File indexing completed on 2025-07-12 08:08:29
0001 // 0002 // write.hpp 0003 // ~~~~~~~~~ 0004 // 0005 // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) 0006 // 0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0009 // 0010 0011 #ifndef BOOST_ASIO_WRITE_HPP 0012 #define BOOST_ASIO_WRITE_HPP 0013 0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 0015 # pragma once 0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 0017 0018 #include <boost/asio/detail/config.hpp> 0019 #include <cstddef> 0020 #include <boost/asio/async_result.hpp> 0021 #include <boost/asio/buffer.hpp> 0022 #include <boost/asio/completion_condition.hpp> 0023 #include <boost/asio/error.hpp> 0024 0025 #if !defined(BOOST_ASIO_NO_EXTENSIONS) 0026 # include <boost/asio/basic_streambuf_fwd.hpp> 0027 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS) 0028 0029 #include <boost/asio/detail/push_options.hpp> 0030 0031 namespace boost { 0032 namespace asio { 0033 namespace detail { 0034 0035 template <typename> class initiate_async_write; 0036 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0037 template <typename> class initiate_async_write_dynbuf_v1; 0038 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0039 template <typename> class initiate_async_write_dynbuf_v2; 0040 0041 } // namespace detail 0042 0043 /** 0044 * @defgroup write boost::asio::write 0045 * 0046 * @brief The @c write function is a composed operation that writes a certain 0047 * amount of data to a stream before returning. 0048 */ 0049 /*@{*/ 0050 0051 /// Write all of the supplied data to a stream before returning. 0052 /** 0053 * This function is used to write a certain number of bytes of data to a stream. 0054 * The call will block until one of the following conditions is true: 0055 * 0056 * @li All of the data in the supplied buffers has been written. That is, the 0057 * bytes transferred is equal to the sum of the buffer sizes. 0058 * 0059 * @li An error occurred. 0060 * 0061 * This operation is implemented in terms of zero or more calls to the stream's 0062 * write_some function. 0063 * 0064 * @param s The stream to which the data is to be written. The type must support 0065 * the SyncWriteStream concept. 0066 * 0067 * @param buffers One or more buffers containing the data to be written. The sum 0068 * of the buffer sizes indicates the maximum number of bytes to write to the 0069 * stream. 0070 * 0071 * @returns The number of bytes transferred. 0072 * 0073 * @throws boost::system::system_error Thrown on failure. 0074 * 0075 * @par Example 0076 * To write a single data buffer use the @ref buffer function as follows: 0077 * @code boost::asio::write(s, boost::asio::buffer(data, size)); @endcode 0078 * See the @ref buffer documentation for information on writing multiple 0079 * buffers in one go, and how to use it with arrays, boost::array or 0080 * std::vector. 0081 * 0082 * @note This overload is equivalent to calling: 0083 * @code boost::asio::write( 0084 * s, buffers, 0085 * boost::asio::transfer_all()); @endcode 0086 */ 0087 template <typename SyncWriteStream, typename ConstBufferSequence> 0088 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers, 0089 constraint_t< 0090 is_const_buffer_sequence<ConstBufferSequence>::value 0091 > = 0); 0092 0093 /// Write all of the supplied data to a stream before returning. 0094 /** 0095 * This function is used to write a certain number of bytes of data to a stream. 0096 * The call will block until one of the following conditions is true: 0097 * 0098 * @li All of the data in the supplied buffers has been written. That is, the 0099 * bytes transferred is equal to the sum of the buffer sizes. 0100 * 0101 * @li An error occurred. 0102 * 0103 * This operation is implemented in terms of zero or more calls to the stream's 0104 * write_some function. 0105 * 0106 * @param s The stream to which the data is to be written. The type must support 0107 * the SyncWriteStream concept. 0108 * 0109 * @param buffers One or more buffers containing the data to be written. The sum 0110 * of the buffer sizes indicates the maximum number of bytes to write to the 0111 * stream. 0112 * 0113 * @param ec Set to indicate what error occurred, if any. 0114 * 0115 * @returns The number of bytes transferred. 0116 * 0117 * @par Example 0118 * To write a single data buffer use the @ref buffer function as follows: 0119 * @code boost::asio::write(s, boost::asio::buffer(data, size), ec); @endcode 0120 * See the @ref buffer documentation for information on writing multiple 0121 * buffers in one go, and how to use it with arrays, boost::array or 0122 * std::vector. 0123 * 0124 * @note This overload is equivalent to calling: 0125 * @code boost::asio::write( 0126 * s, buffers, 0127 * boost::asio::transfer_all(), ec); @endcode 0128 */ 0129 template <typename SyncWriteStream, typename ConstBufferSequence> 0130 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers, 0131 boost::system::error_code& ec, 0132 constraint_t< 0133 is_const_buffer_sequence<ConstBufferSequence>::value 0134 > = 0); 0135 0136 /// Write a certain amount of data to a stream before returning. 0137 /** 0138 * This function is used to write a certain number of bytes of data to a stream. 0139 * The call will block until one of the following conditions is true: 0140 * 0141 * @li All of the data in the supplied buffers has been written. That is, the 0142 * bytes transferred is equal to the sum of the buffer sizes. 0143 * 0144 * @li The completion_condition function object returns 0. 0145 * 0146 * This operation is implemented in terms of zero or more calls to the stream's 0147 * write_some function. 0148 * 0149 * @param s The stream to which the data is to be written. The type must support 0150 * the SyncWriteStream concept. 0151 * 0152 * @param buffers One or more buffers containing the data to be written. The sum 0153 * of the buffer sizes indicates the maximum number of bytes to write to the 0154 * stream. 0155 * 0156 * @param completion_condition The function object to be called to determine 0157 * whether the write operation is complete. The signature of the function object 0158 * must be: 0159 * @code std::size_t completion_condition( 0160 * // Result of latest write_some operation. 0161 * const boost::system::error_code& error, 0162 * 0163 * // Number of bytes transferred so far. 0164 * std::size_t bytes_transferred 0165 * ); @endcode 0166 * A return value of 0 indicates that the write operation is complete. A 0167 * non-zero return value indicates the maximum number of bytes to be written on 0168 * the next call to the stream's write_some function. 0169 * 0170 * @returns The number of bytes transferred. 0171 * 0172 * @throws boost::system::system_error Thrown on failure. 0173 * 0174 * @par Example 0175 * To write a single data buffer use the @ref buffer function as follows: 0176 * @code boost::asio::write(s, boost::asio::buffer(data, size), 0177 * boost::asio::transfer_at_least(32)); @endcode 0178 * See the @ref buffer documentation for information on writing multiple 0179 * buffers in one go, and how to use it with arrays, boost::array or 0180 * std::vector. 0181 */ 0182 template <typename SyncWriteStream, typename ConstBufferSequence, 0183 typename CompletionCondition> 0184 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers, 0185 CompletionCondition completion_condition, 0186 constraint_t< 0187 is_const_buffer_sequence<ConstBufferSequence>::value 0188 > = 0, 0189 constraint_t< 0190 is_completion_condition<CompletionCondition>::value 0191 > = 0); 0192 0193 /// Write a certain amount of data to a stream before returning. 0194 /** 0195 * This function is used to write a certain number of bytes of data to a stream. 0196 * The call will block until one of the following conditions is true: 0197 * 0198 * @li All of the data in the supplied buffers has been written. That is, the 0199 * bytes transferred is equal to the sum of the buffer sizes. 0200 * 0201 * @li The completion_condition function object returns 0. 0202 * 0203 * This operation is implemented in terms of zero or more calls to the stream's 0204 * write_some function. 0205 * 0206 * @param s The stream to which the data is to be written. The type must support 0207 * the SyncWriteStream concept. 0208 * 0209 * @param buffers One or more buffers containing the data to be written. The sum 0210 * of the buffer sizes indicates the maximum number of bytes to write to the 0211 * stream. 0212 * 0213 * @param completion_condition The function object to be called to determine 0214 * whether the write operation is complete. The signature of the function object 0215 * must be: 0216 * @code std::size_t completion_condition( 0217 * // Result of latest write_some operation. 0218 * const boost::system::error_code& error, 0219 * 0220 * // Number of bytes transferred so far. 0221 * std::size_t bytes_transferred 0222 * ); @endcode 0223 * A return value of 0 indicates that the write operation is complete. A 0224 * non-zero return value indicates the maximum number of bytes to be written on 0225 * the next call to the stream's write_some function. 0226 * 0227 * @param ec Set to indicate what error occurred, if any. 0228 * 0229 * @returns The number of bytes written. If an error occurs, returns the total 0230 * number of bytes successfully transferred prior to the error. 0231 */ 0232 template <typename SyncWriteStream, typename ConstBufferSequence, 0233 typename CompletionCondition> 0234 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers, 0235 CompletionCondition completion_condition, boost::system::error_code& ec, 0236 constraint_t< 0237 is_const_buffer_sequence<ConstBufferSequence>::value 0238 > = 0, 0239 constraint_t< 0240 is_completion_condition<CompletionCondition>::value 0241 > = 0); 0242 0243 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0244 0245 /// Write all of the supplied data to a stream before returning. 0246 /** 0247 * This function is used to write a certain number of bytes of data to a stream. 0248 * The call will block until one of the following conditions is true: 0249 * 0250 * @li All of the data in the supplied dynamic buffer sequence has been written. 0251 * 0252 * @li An error occurred. 0253 * 0254 * This operation is implemented in terms of zero or more calls to the stream's 0255 * write_some function. 0256 * 0257 * @param s The stream to which the data is to be written. The type must support 0258 * the SyncWriteStream concept. 0259 * 0260 * @param buffers The dynamic buffer sequence from which data will be written. 0261 * Successfully written data is automatically consumed from the buffers. 0262 * 0263 * @returns The number of bytes transferred. 0264 * 0265 * @throws boost::system::system_error Thrown on failure. 0266 * 0267 * @note This overload is equivalent to calling: 0268 * @code boost::asio::write( 0269 * s, buffers, 0270 * boost::asio::transfer_all()); @endcode 0271 */ 0272 template <typename SyncWriteStream, typename DynamicBuffer_v1> 0273 std::size_t write(SyncWriteStream& s, 0274 DynamicBuffer_v1&& buffers, 0275 constraint_t< 0276 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0277 > = 0, 0278 constraint_t< 0279 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0280 > = 0); 0281 0282 /// Write all of the supplied data to a stream before returning. 0283 /** 0284 * This function is used to write a certain number of bytes of data to a stream. 0285 * The call will block until one of the following conditions is true: 0286 * 0287 * @li All of the data in the supplied dynamic buffer sequence has been written. 0288 * 0289 * @li An error occurred. 0290 * 0291 * This operation is implemented in terms of zero or more calls to the stream's 0292 * write_some function. 0293 * 0294 * @param s The stream to which the data is to be written. The type must support 0295 * the SyncWriteStream concept. 0296 * 0297 * @param buffers The dynamic buffer sequence from which data will be written. 0298 * Successfully written data is automatically consumed from the buffers. 0299 * 0300 * @param ec Set to indicate what error occurred, if any. 0301 * 0302 * @returns The number of bytes transferred. 0303 * 0304 * @note This overload is equivalent to calling: 0305 * @code boost::asio::write( 0306 * s, buffers, 0307 * boost::asio::transfer_all(), ec); @endcode 0308 */ 0309 template <typename SyncWriteStream, typename DynamicBuffer_v1> 0310 std::size_t write(SyncWriteStream& s, 0311 DynamicBuffer_v1&& buffers, 0312 boost::system::error_code& ec, 0313 constraint_t< 0314 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0315 > = 0, 0316 constraint_t< 0317 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0318 > = 0); 0319 0320 /// Write a certain amount of data to a stream before returning. 0321 /** 0322 * This function is used to write a certain number of bytes of data to a stream. 0323 * The call will block until one of the following conditions is true: 0324 * 0325 * @li All of the data in the supplied dynamic buffer sequence has been written. 0326 * 0327 * @li The completion_condition function object returns 0. 0328 * 0329 * This operation is implemented in terms of zero or more calls to the stream's 0330 * write_some function. 0331 * 0332 * @param s The stream to which the data is to be written. The type must support 0333 * the SyncWriteStream concept. 0334 * 0335 * @param buffers The dynamic buffer sequence from which data will be written. 0336 * Successfully written data is automatically consumed from the buffers. 0337 * 0338 * @param completion_condition The function object to be called to determine 0339 * whether the write operation is complete. The signature of the function object 0340 * must be: 0341 * @code std::size_t completion_condition( 0342 * // Result of latest write_some operation. 0343 * const boost::system::error_code& error, 0344 * 0345 * // Number of bytes transferred so far. 0346 * std::size_t bytes_transferred 0347 * ); @endcode 0348 * A return value of 0 indicates that the write operation is complete. A 0349 * non-zero return value indicates the maximum number of bytes to be written on 0350 * the next call to the stream's write_some function. 0351 * 0352 * @returns The number of bytes transferred. 0353 * 0354 * @throws boost::system::system_error Thrown on failure. 0355 */ 0356 template <typename SyncWriteStream, typename DynamicBuffer_v1, 0357 typename CompletionCondition> 0358 std::size_t write(SyncWriteStream& s, 0359 DynamicBuffer_v1&& buffers, 0360 CompletionCondition completion_condition, 0361 constraint_t< 0362 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0363 > = 0, 0364 constraint_t< 0365 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0366 > = 0, 0367 constraint_t< 0368 is_completion_condition<CompletionCondition>::value 0369 > = 0); 0370 0371 /// Write a certain amount of data to a stream before returning. 0372 /** 0373 * This function is used to write a certain number of bytes of data to a stream. 0374 * The call will block until one of the following conditions is true: 0375 * 0376 * @li All of the data in the supplied dynamic buffer sequence has been written. 0377 * 0378 * @li The completion_condition function object returns 0. 0379 * 0380 * This operation is implemented in terms of zero or more calls to the stream's 0381 * write_some function. 0382 * 0383 * @param s The stream to which the data is to be written. The type must support 0384 * the SyncWriteStream concept. 0385 * 0386 * @param buffers The dynamic buffer sequence from which data will be written. 0387 * Successfully written data is automatically consumed from the buffers. 0388 * 0389 * @param completion_condition The function object to be called to determine 0390 * whether the write operation is complete. The signature of the function object 0391 * must be: 0392 * @code std::size_t completion_condition( 0393 * // Result of latest write_some operation. 0394 * const boost::system::error_code& error, 0395 * 0396 * // Number of bytes transferred so far. 0397 * std::size_t bytes_transferred 0398 * ); @endcode 0399 * A return value of 0 indicates that the write operation is complete. A 0400 * non-zero return value indicates the maximum number of bytes to be written on 0401 * the next call to the stream's write_some function. 0402 * 0403 * @param ec Set to indicate what error occurred, if any. 0404 * 0405 * @returns The number of bytes written. If an error occurs, returns the total 0406 * number of bytes successfully transferred prior to the error. 0407 */ 0408 template <typename SyncWriteStream, typename DynamicBuffer_v1, 0409 typename CompletionCondition> 0410 std::size_t write(SyncWriteStream& s, 0411 DynamicBuffer_v1&& buffers, 0412 CompletionCondition completion_condition, boost::system::error_code& ec, 0413 constraint_t< 0414 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0415 > = 0, 0416 constraint_t< 0417 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0418 > = 0, 0419 constraint_t< 0420 is_completion_condition<CompletionCondition>::value 0421 > = 0); 0422 0423 #if !defined(BOOST_ASIO_NO_EXTENSIONS) 0424 #if !defined(BOOST_ASIO_NO_IOSTREAM) 0425 0426 /// Write all of the supplied data to a stream before returning. 0427 /** 0428 * This function is used to write a certain number of bytes of data to a stream. 0429 * The call will block until one of the following conditions is true: 0430 * 0431 * @li All of the data in the supplied basic_streambuf has been written. 0432 * 0433 * @li An error occurred. 0434 * 0435 * This operation is implemented in terms of zero or more calls to the stream's 0436 * write_some function. 0437 * 0438 * @param s The stream to which the data is to be written. The type must support 0439 * the SyncWriteStream concept. 0440 * 0441 * @param b The basic_streambuf object from which data will be written. 0442 * 0443 * @returns The number of bytes transferred. 0444 * 0445 * @throws boost::system::system_error Thrown on failure. 0446 * 0447 * @note This overload is equivalent to calling: 0448 * @code boost::asio::write( 0449 * s, b, 0450 * boost::asio::transfer_all()); @endcode 0451 */ 0452 template <typename SyncWriteStream, typename Allocator> 0453 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b); 0454 0455 /// Write all of the supplied data to a stream before returning. 0456 /** 0457 * This function is used to write a certain number of bytes of data to a stream. 0458 * The call will block until one of the following conditions is true: 0459 * 0460 * @li All of the data in the supplied basic_streambuf has been written. 0461 * 0462 * @li An error occurred. 0463 * 0464 * This operation is implemented in terms of zero or more calls to the stream's 0465 * write_some function. 0466 * 0467 * @param s The stream to which the data is to be written. The type must support 0468 * the SyncWriteStream concept. 0469 * 0470 * @param b The basic_streambuf object from which data will be written. 0471 * 0472 * @param ec Set to indicate what error occurred, if any. 0473 * 0474 * @returns The number of bytes transferred. 0475 * 0476 * @note This overload is equivalent to calling: 0477 * @code boost::asio::write( 0478 * s, b, 0479 * boost::asio::transfer_all(), ec); @endcode 0480 */ 0481 template <typename SyncWriteStream, typename Allocator> 0482 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b, 0483 boost::system::error_code& ec); 0484 0485 /// Write a certain amount of data to a stream before returning. 0486 /** 0487 * This function is used to write a certain number of bytes of data to a stream. 0488 * The call will block until one of the following conditions is true: 0489 * 0490 * @li All of the data in the supplied basic_streambuf has been written. 0491 * 0492 * @li The completion_condition function object returns 0. 0493 * 0494 * This operation is implemented in terms of zero or more calls to the stream's 0495 * write_some function. 0496 * 0497 * @param s The stream to which the data is to be written. The type must support 0498 * the SyncWriteStream concept. 0499 * 0500 * @param b The basic_streambuf object from which data will be written. 0501 * 0502 * @param completion_condition The function object to be called to determine 0503 * whether the write operation is complete. The signature of the function object 0504 * must be: 0505 * @code std::size_t completion_condition( 0506 * // Result of latest write_some operation. 0507 * const boost::system::error_code& error, 0508 * 0509 * // Number of bytes transferred so far. 0510 * std::size_t bytes_transferred 0511 * ); @endcode 0512 * A return value of 0 indicates that the write operation is complete. A 0513 * non-zero return value indicates the maximum number of bytes to be written on 0514 * the next call to the stream's write_some function. 0515 * 0516 * @returns The number of bytes transferred. 0517 * 0518 * @throws boost::system::system_error Thrown on failure. 0519 */ 0520 template <typename SyncWriteStream, typename Allocator, 0521 typename CompletionCondition> 0522 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b, 0523 CompletionCondition completion_condition, 0524 constraint_t< 0525 is_completion_condition<CompletionCondition>::value 0526 > = 0); 0527 0528 /// Write a certain amount of data to a stream before returning. 0529 /** 0530 * This function is used to write a certain number of bytes of data to a stream. 0531 * The call will block until one of the following conditions is true: 0532 * 0533 * @li All of the data in the supplied basic_streambuf has been written. 0534 * 0535 * @li The completion_condition function object returns 0. 0536 * 0537 * This operation is implemented in terms of zero or more calls to the stream's 0538 * write_some function. 0539 * 0540 * @param s The stream to which the data is to be written. The type must support 0541 * the SyncWriteStream concept. 0542 * 0543 * @param b The basic_streambuf object from which data will be written. 0544 * 0545 * @param completion_condition The function object to be called to determine 0546 * whether the write operation is complete. The signature of the function object 0547 * must be: 0548 * @code std::size_t completion_condition( 0549 * // Result of latest write_some operation. 0550 * const boost::system::error_code& error, 0551 * 0552 * // Number of bytes transferred so far. 0553 * std::size_t bytes_transferred 0554 * ); @endcode 0555 * A return value of 0 indicates that the write operation is complete. A 0556 * non-zero return value indicates the maximum number of bytes to be written on 0557 * the next call to the stream's write_some function. 0558 * 0559 * @param ec Set to indicate what error occurred, if any. 0560 * 0561 * @returns The number of bytes written. If an error occurs, returns the total 0562 * number of bytes successfully transferred prior to the error. 0563 */ 0564 template <typename SyncWriteStream, typename Allocator, 0565 typename CompletionCondition> 0566 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b, 0567 CompletionCondition completion_condition, boost::system::error_code& ec, 0568 constraint_t< 0569 is_completion_condition<CompletionCondition>::value 0570 > = 0); 0571 0572 #endif // !defined(BOOST_ASIO_NO_IOSTREAM) 0573 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS) 0574 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0575 0576 /// Write all of the supplied data to a stream before returning. 0577 /** 0578 * This function is used to write a certain number of bytes of data to a stream. 0579 * The call will block until one of the following conditions is true: 0580 * 0581 * @li All of the data in the supplied dynamic buffer sequence has been written. 0582 * 0583 * @li An error occurred. 0584 * 0585 * This operation is implemented in terms of zero or more calls to the stream's 0586 * write_some function. 0587 * 0588 * @param s The stream to which the data is to be written. The type must support 0589 * the SyncWriteStream concept. 0590 * 0591 * @param buffers The dynamic buffer sequence from which data will be written. 0592 * Successfully written data is automatically consumed from the buffers. 0593 * 0594 * @returns The number of bytes transferred. 0595 * 0596 * @throws boost::system::system_error Thrown on failure. 0597 * 0598 * @note This overload is equivalent to calling: 0599 * @code boost::asio::write( 0600 * s, buffers, 0601 * boost::asio::transfer_all()); @endcode 0602 */ 0603 template <typename SyncWriteStream, typename DynamicBuffer_v2> 0604 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0605 constraint_t< 0606 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0607 > = 0); 0608 0609 /// Write all of the supplied data to a stream before returning. 0610 /** 0611 * This function is used to write a certain number of bytes of data to a stream. 0612 * The call will block until one of the following conditions is true: 0613 * 0614 * @li All of the data in the supplied dynamic buffer sequence has been written. 0615 * 0616 * @li An error occurred. 0617 * 0618 * This operation is implemented in terms of zero or more calls to the stream's 0619 * write_some function. 0620 * 0621 * @param s The stream to which the data is to be written. The type must support 0622 * the SyncWriteStream concept. 0623 * 0624 * @param buffers The dynamic buffer sequence from which data will be written. 0625 * Successfully written data is automatically consumed from the buffers. 0626 * 0627 * @param ec Set to indicate what error occurred, if any. 0628 * 0629 * @returns The number of bytes transferred. 0630 * 0631 * @note This overload is equivalent to calling: 0632 * @code boost::asio::write( 0633 * s, buffers, 0634 * boost::asio::transfer_all(), ec); @endcode 0635 */ 0636 template <typename SyncWriteStream, typename DynamicBuffer_v2> 0637 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0638 boost::system::error_code& ec, 0639 constraint_t< 0640 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0641 > = 0); 0642 0643 /// Write a certain amount of data to a stream before returning. 0644 /** 0645 * This function is used to write a certain number of bytes of data to a stream. 0646 * The call will block until one of the following conditions is true: 0647 * 0648 * @li All of the data in the supplied dynamic buffer sequence has been written. 0649 * 0650 * @li The completion_condition function object returns 0. 0651 * 0652 * This operation is implemented in terms of zero or more calls to the stream's 0653 * write_some function. 0654 * 0655 * @param s The stream to which the data is to be written. The type must support 0656 * the SyncWriteStream concept. 0657 * 0658 * @param buffers The dynamic buffer sequence from which data will be written. 0659 * Successfully written data is automatically consumed from the buffers. 0660 * 0661 * @param completion_condition The function object to be called to determine 0662 * whether the write operation is complete. The signature of the function object 0663 * must be: 0664 * @code std::size_t completion_condition( 0665 * // Result of latest write_some operation. 0666 * const boost::system::error_code& error, 0667 * 0668 * // Number of bytes transferred so far. 0669 * std::size_t bytes_transferred 0670 * ); @endcode 0671 * A return value of 0 indicates that the write operation is complete. A 0672 * non-zero return value indicates the maximum number of bytes to be written on 0673 * the next call to the stream's write_some function. 0674 * 0675 * @returns The number of bytes transferred. 0676 * 0677 * @throws boost::system::system_error Thrown on failure. 0678 */ 0679 template <typename SyncWriteStream, typename DynamicBuffer_v2, 0680 typename CompletionCondition> 0681 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0682 CompletionCondition completion_condition, 0683 constraint_t< 0684 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0685 > = 0, 0686 constraint_t< 0687 is_completion_condition<CompletionCondition>::value 0688 > = 0); 0689 0690 /// Write a certain amount of data to a stream before returning. 0691 /** 0692 * This function is used to write a certain number of bytes of data to a stream. 0693 * The call will block until one of the following conditions is true: 0694 * 0695 * @li All of the data in the supplied dynamic buffer sequence has been written. 0696 * 0697 * @li The completion_condition function object returns 0. 0698 * 0699 * This operation is implemented in terms of zero or more calls to the stream's 0700 * write_some function. 0701 * 0702 * @param s The stream to which the data is to be written. The type must support 0703 * the SyncWriteStream concept. 0704 * 0705 * @param buffers The dynamic buffer sequence from which data will be written. 0706 * Successfully written data is automatically consumed from the buffers. 0707 * 0708 * @param completion_condition The function object to be called to determine 0709 * whether the write operation is complete. The signature of the function object 0710 * must be: 0711 * @code std::size_t completion_condition( 0712 * // Result of latest write_some operation. 0713 * const boost::system::error_code& error, 0714 * 0715 * // Number of bytes transferred so far. 0716 * std::size_t bytes_transferred 0717 * ); @endcode 0718 * A return value of 0 indicates that the write operation is complete. A 0719 * non-zero return value indicates the maximum number of bytes to be written on 0720 * the next call to the stream's write_some function. 0721 * 0722 * @param ec Set to indicate what error occurred, if any. 0723 * 0724 * @returns The number of bytes written. If an error occurs, returns the total 0725 * number of bytes successfully transferred prior to the error. 0726 */ 0727 template <typename SyncWriteStream, typename DynamicBuffer_v2, 0728 typename CompletionCondition> 0729 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0730 CompletionCondition completion_condition, boost::system::error_code& ec, 0731 constraint_t< 0732 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0733 > = 0, 0734 constraint_t< 0735 is_completion_condition<CompletionCondition>::value 0736 > = 0); 0737 0738 /*@}*/ 0739 /** 0740 * @defgroup async_write boost::asio::async_write 0741 * 0742 * @brief The @c async_write function is a composed asynchronous operation that 0743 * writes a certain amount of data to a stream before completion. 0744 */ 0745 /*@{*/ 0746 0747 /// Start an asynchronous operation to write all of the supplied data to a 0748 /// stream. 0749 /** 0750 * This function is used to asynchronously write a certain number of bytes of 0751 * data to a stream. It is an initiating function for an @ref 0752 * asynchronous_operation, and always returns immediately. The asynchronous 0753 * operation will continue until one of the following conditions is true: 0754 * 0755 * @li All of the data in the supplied buffers has been written. That is, the 0756 * bytes transferred is equal to the sum of the buffer sizes. 0757 * 0758 * @li An error occurred. 0759 * 0760 * This operation is implemented in terms of zero or more calls to the stream's 0761 * async_write_some function, and is known as a <em>composed operation</em>. The 0762 * program must ensure that the stream performs no other write operations (such 0763 * as async_write, the stream's async_write_some function, or any other composed 0764 * operations that perform writes) until this operation completes. 0765 * 0766 * @param s The stream to which the data is to be written. The type must support 0767 * the AsyncWriteStream concept. 0768 * 0769 * @param buffers One or more buffers containing the data to be written. 0770 * Although the buffers object may be copied as necessary, ownership of the 0771 * underlying memory blocks is retained by the caller, which must guarantee 0772 * that they remain valid until the completion handler is called. 0773 * 0774 * @param token The @ref completion_token that will be used to produce a 0775 * completion handler, which will be called when the write completes. 0776 * Potential completion tokens include @ref use_future, @ref use_awaitable, 0777 * @ref yield_context, or a function object with the correct completion 0778 * signature. The function signature of the completion handler must be: 0779 * @code void handler( 0780 * // Result of operation. 0781 * const boost::system::error_code& error, 0782 * 0783 * // Number of bytes written from the buffers. If an error 0784 * // occurred, this will be less than the sum of the buffer sizes. 0785 * std::size_t bytes_transferred 0786 * ); @endcode 0787 * Regardless of whether the asynchronous operation completes immediately or 0788 * not, the completion handler will not be invoked from within this function. 0789 * On immediate completion, invocation of the handler will be performed in a 0790 * manner equivalent to using boost::asio::async_immediate(). 0791 * 0792 * @par Completion Signature 0793 * @code void(boost::system::error_code, std::size_t) @endcode 0794 * 0795 * @par Example 0796 * To write a single data buffer use the @ref buffer function as follows: 0797 * @code 0798 * boost::asio::async_write(s, boost::asio::buffer(data, size), handler); 0799 * @endcode 0800 * See the @ref buffer documentation for information on writing multiple 0801 * buffers in one go, and how to use it with arrays, boost::array or 0802 * std::vector. 0803 * 0804 * @par Per-Operation Cancellation 0805 * This asynchronous operation supports cancellation for the following 0806 * boost::asio::cancellation_type values: 0807 * 0808 * @li @c cancellation_type::terminal 0809 * 0810 * @li @c cancellation_type::partial 0811 * 0812 * if they are also supported by the @c AsyncWriteStream type's 0813 * @c async_write_some operation. 0814 */ 0815 template <typename AsyncWriteStream, typename ConstBufferSequence, 0816 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 0817 std::size_t)) WriteToken 0818 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 0819 inline auto async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers, 0820 WriteToken&& token 0821 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 0822 constraint_t< 0823 is_const_buffer_sequence<ConstBufferSequence>::value 0824 > = 0, 0825 constraint_t< 0826 !is_completion_condition<decay_t<WriteToken>>::value 0827 > = 0) 0828 -> decltype( 0829 async_initiate<WriteToken, 0830 void (boost::system::error_code, std::size_t)>( 0831 declval<detail::initiate_async_write<AsyncWriteStream>>(), 0832 token, buffers, transfer_all())) 0833 { 0834 return async_initiate<WriteToken, 0835 void (boost::system::error_code, std::size_t)>( 0836 detail::initiate_async_write<AsyncWriteStream>(s), 0837 token, buffers, transfer_all()); 0838 } 0839 0840 /// Start an asynchronous operation to write a certain amount of data to a 0841 /// stream. 0842 /** 0843 * This function is used to asynchronously write a certain number of bytes of 0844 * data to a stream. It is an initiating function for an @ref 0845 * asynchronous_operation, and always returns immediately. The asynchronous 0846 * operation will continue until one of the following conditions is true: 0847 * 0848 * @li All of the data in the supplied buffers has been written. That is, the 0849 * bytes transferred is equal to the sum of the buffer sizes. 0850 * 0851 * @li The completion_condition function object returns 0. 0852 * 0853 * This operation is implemented in terms of zero or more calls to the stream's 0854 * async_write_some function, and is known as a <em>composed operation</em>. The 0855 * program must ensure that the stream performs no other write operations (such 0856 * as async_write, the stream's async_write_some function, or any other composed 0857 * operations that perform writes) until this operation completes. 0858 * 0859 * @param s The stream to which the data is to be written. The type must support 0860 * the AsyncWriteStream concept. 0861 * 0862 * @param buffers One or more buffers containing the data to be written. 0863 * Although the buffers object may be copied as necessary, ownership of the 0864 * underlying memory blocks is retained by the caller, which must guarantee 0865 * that they remain valid until the completion handler is called. 0866 * 0867 * @param completion_condition The function object to be called to determine 0868 * whether the write operation is complete. The signature of the function object 0869 * must be: 0870 * @code std::size_t completion_condition( 0871 * // Result of latest async_write_some operation. 0872 * const boost::system::error_code& error, 0873 * 0874 * // Number of bytes transferred so far. 0875 * std::size_t bytes_transferred 0876 * ); @endcode 0877 * A return value of 0 indicates that the write operation is complete. A 0878 * non-zero return value indicates the maximum number of bytes to be written on 0879 * the next call to the stream's async_write_some function. 0880 * 0881 * @param token The @ref completion_token that will be used to produce a 0882 * completion handler, which will be called when the write completes. 0883 * Potential completion tokens include @ref use_future, @ref use_awaitable, 0884 * @ref yield_context, or a function object with the correct completion 0885 * signature. The function signature of the completion handler must be: 0886 * @code void handler( 0887 * // Result of operation. 0888 * const boost::system::error_code& error, 0889 * 0890 * // Number of bytes written from the buffers. If an error 0891 * // occurred, this will be less than the sum of the buffer sizes. 0892 * std::size_t bytes_transferred 0893 * ); @endcode 0894 * Regardless of whether the asynchronous operation completes immediately or 0895 * not, the completion handler will not be invoked from within this function. 0896 * On immediate completion, invocation of the handler will be performed in a 0897 * manner equivalent to using boost::asio::async_immediate(). 0898 * 0899 * @par Completion Signature 0900 * @code void(boost::system::error_code, std::size_t) @endcode 0901 * 0902 * @par Example 0903 * To write a single data buffer use the @ref buffer function as follows: 0904 * @code boost::asio::async_write(s, 0905 * boost::asio::buffer(data, size), 0906 * boost::asio::transfer_at_least(32), 0907 * handler); @endcode 0908 * See the @ref buffer documentation for information on writing multiple 0909 * buffers in one go, and how to use it with arrays, boost::array or 0910 * std::vector. 0911 * 0912 * @par Per-Operation Cancellation 0913 * This asynchronous operation supports cancellation for the following 0914 * boost::asio::cancellation_type values: 0915 * 0916 * @li @c cancellation_type::terminal 0917 * 0918 * @li @c cancellation_type::partial 0919 * 0920 * if they are also supported by the @c AsyncWriteStream type's 0921 * @c async_write_some operation. 0922 */ 0923 template <typename AsyncWriteStream, 0924 typename ConstBufferSequence, typename CompletionCondition, 0925 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 0926 std::size_t)) WriteToken 0927 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 0928 inline auto async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers, 0929 CompletionCondition completion_condition, 0930 WriteToken&& token 0931 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 0932 constraint_t< 0933 is_const_buffer_sequence<ConstBufferSequence>::value 0934 > = 0, 0935 constraint_t< 0936 is_completion_condition<CompletionCondition>::value 0937 > = 0) 0938 -> decltype( 0939 async_initiate<WriteToken, 0940 void (boost::system::error_code, std::size_t)>( 0941 declval<detail::initiate_async_write<AsyncWriteStream>>(), 0942 token, buffers, 0943 static_cast<CompletionCondition&&>(completion_condition))) 0944 { 0945 return async_initiate<WriteToken, 0946 void (boost::system::error_code, std::size_t)>( 0947 detail::initiate_async_write<AsyncWriteStream>(s), 0948 token, buffers, 0949 static_cast<CompletionCondition&&>(completion_condition)); 0950 } 0951 0952 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0953 0954 /// Start an asynchronous operation to write all of the supplied data to a 0955 /// stream. 0956 /** 0957 * This function is used to asynchronously write a certain number of bytes of 0958 * data to a stream. It is an initiating function for an @ref 0959 * asynchronous_operation, and always returns immediately. The asynchronous 0960 * operation will continue until one of the following conditions is true: 0961 * 0962 * @li All of the data in the supplied dynamic buffer sequence has been written. 0963 * 0964 * @li An error occurred. 0965 * 0966 * This operation is implemented in terms of zero or more calls to the stream's 0967 * async_write_some function, and is known as a <em>composed operation</em>. The 0968 * program must ensure that the stream performs no other write operations (such 0969 * as async_write, the stream's async_write_some function, or any other composed 0970 * operations that perform writes) until this operation completes. 0971 * 0972 * @param s The stream to which the data is to be written. The type must support 0973 * the AsyncWriteStream concept. 0974 * 0975 * @param buffers The dynamic buffer sequence from which data will be written. 0976 * Although the buffers object may be copied as necessary, ownership of the 0977 * underlying memory blocks is retained by the caller, which must guarantee 0978 * that they remain valid until the completion handler is called. Successfully 0979 * written data is automatically consumed from the buffers. 0980 * 0981 * @param token The @ref completion_token that will be used to produce a 0982 * completion handler, which will be called when the write completes. 0983 * Potential completion tokens include @ref use_future, @ref use_awaitable, 0984 * @ref yield_context, or a function object with the correct completion 0985 * signature. The function signature of the completion handler must be: 0986 * @code void handler( 0987 * // Result of operation. 0988 * const boost::system::error_code& error, 0989 * 0990 * // Number of bytes written from the buffers. If an error 0991 * // occurred, this will be less than the sum of the buffer sizes. 0992 * std::size_t bytes_transferred 0993 * ); @endcode 0994 * Regardless of whether the asynchronous operation completes immediately or 0995 * not, the completion handler will not be invoked from within this function. 0996 * On immediate completion, invocation of the handler will be performed in a 0997 * manner equivalent to using boost::asio::async_immediate(). 0998 * 0999 * @par Completion Signature 1000 * @code void(boost::system::error_code, std::size_t) @endcode 1001 * 1002 * @par Per-Operation Cancellation 1003 * This asynchronous operation supports cancellation for the following 1004 * boost::asio::cancellation_type values: 1005 * 1006 * @li @c cancellation_type::terminal 1007 * 1008 * @li @c cancellation_type::partial 1009 * 1010 * if they are also supported by the @c AsyncWriteStream type's 1011 * @c async_write_some operation. 1012 */ 1013 template <typename AsyncWriteStream, typename DynamicBuffer_v1, 1014 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1015 std::size_t)) WriteToken 1016 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1017 inline auto async_write(AsyncWriteStream& s, DynamicBuffer_v1&& buffers, 1018 WriteToken&& token 1019 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1020 constraint_t< 1021 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 1022 > = 0, 1023 constraint_t< 1024 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 1025 > = 0, 1026 constraint_t< 1027 !is_completion_condition<decay_t<WriteToken>>::value 1028 > = 0) 1029 -> decltype( 1030 async_initiate<WriteToken, 1031 void (boost::system::error_code, std::size_t)>( 1032 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1033 token, static_cast<DynamicBuffer_v1&&>(buffers), 1034 transfer_all())) 1035 { 1036 return async_initiate<WriteToken, 1037 void (boost::system::error_code, std::size_t)>( 1038 detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s), 1039 token, static_cast<DynamicBuffer_v1&&>(buffers), 1040 transfer_all()); 1041 } 1042 1043 /// Start an asynchronous operation to write a certain amount of data to a 1044 /// stream. 1045 /** 1046 * This function is used to asynchronously write a certain number of bytes of 1047 * data to a stream. It is an initiating function for an @ref 1048 * asynchronous_operation, and always returns immediately. The asynchronous 1049 * operation will continue until one of the following conditions is true: 1050 * 1051 * @li All of the data in the supplied dynamic buffer sequence has been written. 1052 * 1053 * @li The completion_condition function object returns 0. 1054 * 1055 * This operation is implemented in terms of zero or more calls to the stream's 1056 * async_write_some function, and is known as a <em>composed operation</em>. The 1057 * program must ensure that the stream performs no other write operations (such 1058 * as async_write, the stream's async_write_some function, or any other composed 1059 * operations that perform writes) until this operation completes. 1060 * 1061 * @param s The stream to which the data is to be written. The type must support 1062 * the AsyncWriteStream concept. 1063 * 1064 * @param buffers The dynamic buffer sequence from which data will be written. 1065 * Although the buffers object may be copied as necessary, ownership of the 1066 * underlying memory blocks is retained by the caller, which must guarantee 1067 * that they remain valid until the completion handler is called. Successfully 1068 * written data is automatically consumed from the buffers. 1069 * 1070 * @param completion_condition The function object to be called to determine 1071 * whether the write operation is complete. The signature of the function object 1072 * must be: 1073 * @code std::size_t completion_condition( 1074 * // Result of latest async_write_some operation. 1075 * const boost::system::error_code& error, 1076 * 1077 * // Number of bytes transferred so far. 1078 * std::size_t bytes_transferred 1079 * ); @endcode 1080 * A return value of 0 indicates that the write operation is complete. A 1081 * non-zero return value indicates the maximum number of bytes to be written on 1082 * the next call to the stream's async_write_some function. 1083 * 1084 * @param token The @ref completion_token that will be used to produce a 1085 * completion handler, which will be called when the write completes. 1086 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1087 * @ref yield_context, or a function object with the correct completion 1088 * signature. The function signature of the completion handler must be: 1089 * @code void handler( 1090 * // Result of operation. 1091 * const boost::system::error_code& error, 1092 * 1093 * // Number of bytes written from the buffers. If an error 1094 * // occurred, this will be less than the sum of the buffer sizes. 1095 * std::size_t bytes_transferred 1096 * ); @endcode 1097 * Regardless of whether the asynchronous operation completes immediately or 1098 * not, the completion handler will not be invoked from within this function. 1099 * On immediate completion, invocation of the handler will be performed in a 1100 * manner equivalent to using boost::asio::async_immediate(). 1101 * 1102 * @par Completion Signature 1103 * @code void(boost::system::error_code, std::size_t) @endcode 1104 * 1105 * @par Per-Operation Cancellation 1106 * This asynchronous operation supports cancellation for the following 1107 * boost::asio::cancellation_type values: 1108 * 1109 * @li @c cancellation_type::terminal 1110 * 1111 * @li @c cancellation_type::partial 1112 * 1113 * if they are also supported by the @c AsyncWriteStream type's 1114 * @c async_write_some operation. 1115 */ 1116 template <typename AsyncWriteStream, 1117 typename DynamicBuffer_v1, typename CompletionCondition, 1118 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1119 std::size_t)) WriteToken 1120 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1121 inline auto async_write(AsyncWriteStream& s, DynamicBuffer_v1&& buffers, 1122 CompletionCondition completion_condition, 1123 WriteToken&& token 1124 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1125 constraint_t< 1126 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 1127 > = 0, 1128 constraint_t< 1129 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 1130 > = 0, 1131 constraint_t< 1132 is_completion_condition<CompletionCondition>::value 1133 > = 0) 1134 -> decltype( 1135 async_initiate<WriteToken, 1136 void (boost::system::error_code, std::size_t)>( 1137 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1138 token, static_cast<DynamicBuffer_v1&&>(buffers), 1139 static_cast<CompletionCondition&&>(completion_condition))) 1140 { 1141 return async_initiate<WriteToken, 1142 void (boost::system::error_code, std::size_t)>( 1143 detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s), 1144 token, static_cast<DynamicBuffer_v1&&>(buffers), 1145 static_cast<CompletionCondition&&>(completion_condition)); 1146 } 1147 1148 #if !defined(BOOST_ASIO_NO_EXTENSIONS) 1149 #if !defined(BOOST_ASIO_NO_IOSTREAM) 1150 1151 /// Start an asynchronous operation to write all of the supplied data to a 1152 /// stream. 1153 /** 1154 * This function is used to asynchronously write a certain number of bytes of 1155 * data to a stream. It is an initiating function for an @ref 1156 * asynchronous_operation, and always returns immediately. The asynchronous 1157 * operation will continue until one of the following conditions is true: 1158 * 1159 * @li All of the data in the supplied basic_streambuf has been written. 1160 * 1161 * @li An error occurred. 1162 * 1163 * This operation is implemented in terms of zero or more calls to the stream's 1164 * async_write_some function, and is known as a <em>composed operation</em>. The 1165 * program must ensure that the stream performs no other write operations (such 1166 * as async_write, the stream's async_write_some function, or any other composed 1167 * operations that perform writes) until this operation completes. 1168 * 1169 * @param s The stream to which the data is to be written. The type must support 1170 * the AsyncWriteStream concept. 1171 * 1172 * @param b A basic_streambuf object from which data will be written. Ownership 1173 * of the streambuf is retained by the caller, which must guarantee that it 1174 * remains valid until the completion handler is called. 1175 * 1176 * @param token The @ref completion_token that will be used to produce a 1177 * completion handler, which will be called when the write completes. 1178 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1179 * @ref yield_context, or a function object with the correct completion 1180 * signature. The function signature of the completion handler must be: 1181 * @code void handler( 1182 * // Result of operation. 1183 * const boost::system::error_code& error, 1184 * 1185 * // Number of bytes written from the buffers. If an error 1186 * // occurred, this will be less than the sum of the buffer sizes. 1187 * std::size_t bytes_transferred 1188 * ); @endcode 1189 * Regardless of whether the asynchronous operation completes immediately or 1190 * not, the completion handler will not be invoked from within this function. 1191 * On immediate completion, invocation of the handler will be performed in a 1192 * manner equivalent to using boost::asio::async_immediate(). 1193 * 1194 * @par Completion Signature 1195 * @code void(boost::system::error_code, std::size_t) @endcode 1196 * 1197 * @par Per-Operation Cancellation 1198 * This asynchronous operation supports cancellation for the following 1199 * boost::asio::cancellation_type values: 1200 * 1201 * @li @c cancellation_type::terminal 1202 * 1203 * @li @c cancellation_type::partial 1204 * 1205 * if they are also supported by the @c AsyncWriteStream type's 1206 * @c async_write_some operation. 1207 */ 1208 template <typename AsyncWriteStream, typename Allocator, 1209 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1210 std::size_t)) WriteToken 1211 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1212 inline auto async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b, 1213 WriteToken&& token 1214 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1215 constraint_t< 1216 !is_completion_condition<decay_t<WriteToken>>::value 1217 > = 0) 1218 -> decltype( 1219 async_initiate<WriteToken, 1220 void (boost::system::error_code, std::size_t)>( 1221 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1222 token, basic_streambuf_ref<Allocator>(b), transfer_all())) 1223 { 1224 return async_initiate<WriteToken, 1225 void (boost::system::error_code, std::size_t)>( 1226 detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s), 1227 token, basic_streambuf_ref<Allocator>(b), transfer_all()); 1228 } 1229 1230 /// Start an asynchronous operation to write a certain amount of data to a 1231 /// stream. 1232 /** 1233 * This function is used to asynchronously write a certain number of bytes of 1234 * data to a stream. It is an initiating function for an @ref 1235 * asynchronous_operation, and always returns immediately. The asynchronous 1236 * operation will continue until one of the following conditions is true: 1237 * 1238 * @li All of the data in the supplied basic_streambuf has been written. 1239 * 1240 * @li The completion_condition function object returns 0. 1241 * 1242 * This operation is implemented in terms of zero or more calls to the stream's 1243 * async_write_some function, and is known as a <em>composed operation</em>. The 1244 * program must ensure that the stream performs no other write operations (such 1245 * as async_write, the stream's async_write_some function, or any other composed 1246 * operations that perform writes) until this operation completes. 1247 * 1248 * @param s The stream to which the data is to be written. The type must support 1249 * the AsyncWriteStream concept. 1250 * 1251 * @param b A basic_streambuf object from which data will be written. Ownership 1252 * of the streambuf is retained by the caller, which must guarantee that it 1253 * remains valid until the completion handler is called. 1254 * 1255 * @param completion_condition The function object to be called to determine 1256 * whether the write operation is complete. The signature of the function object 1257 * must be: 1258 * @code std::size_t completion_condition( 1259 * // Result of latest async_write_some operation. 1260 * const boost::system::error_code& error, 1261 * 1262 * // Number of bytes transferred so far. 1263 * std::size_t bytes_transferred 1264 * ); @endcode 1265 * A return value of 0 indicates that the write operation is complete. A 1266 * non-zero return value indicates the maximum number of bytes to be written on 1267 * the next call to the stream's async_write_some function. 1268 * 1269 * @param token The @ref completion_token that will be used to produce a 1270 * completion handler, which will be called when the write completes. 1271 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1272 * @ref yield_context, or a function object with the correct completion 1273 * signature. The function signature of the completion handler must be: 1274 * @code void handler( 1275 * // Result of operation. 1276 * const boost::system::error_code& error, 1277 * 1278 * // Number of bytes written from the buffers. If an error 1279 * // occurred, this will be less than the sum of the buffer sizes. 1280 * std::size_t bytes_transferred 1281 * ); @endcode 1282 * Regardless of whether the asynchronous operation completes immediately or 1283 * not, the completion handler will not be invoked from within this function. 1284 * On immediate completion, invocation of the handler will be performed in a 1285 * manner equivalent to using boost::asio::async_immediate(). 1286 * 1287 * @par Completion Signature 1288 * @code void(boost::system::error_code, std::size_t) @endcode 1289 * 1290 * @par Per-Operation Cancellation 1291 * This asynchronous operation supports cancellation for the following 1292 * boost::asio::cancellation_type values: 1293 * 1294 * @li @c cancellation_type::terminal 1295 * 1296 * @li @c cancellation_type::partial 1297 * 1298 * if they are also supported by the @c AsyncWriteStream type's 1299 * @c async_write_some operation. 1300 */ 1301 template <typename AsyncWriteStream, 1302 typename Allocator, typename CompletionCondition, 1303 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1304 std::size_t)) WriteToken 1305 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1306 inline auto async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b, 1307 CompletionCondition completion_condition, 1308 WriteToken&& token 1309 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1310 constraint_t< 1311 is_completion_condition<CompletionCondition>::value 1312 > = 0) 1313 -> decltype( 1314 async_initiate<WriteToken, 1315 void (boost::system::error_code, std::size_t)>( 1316 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1317 token, basic_streambuf_ref<Allocator>(b), 1318 static_cast<CompletionCondition&&>(completion_condition))) 1319 { 1320 return async_initiate<WriteToken, 1321 void (boost::system::error_code, std::size_t)>( 1322 detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s), 1323 token, basic_streambuf_ref<Allocator>(b), 1324 static_cast<CompletionCondition&&>(completion_condition)); 1325 } 1326 1327 #endif // !defined(BOOST_ASIO_NO_IOSTREAM) 1328 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS) 1329 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 1330 1331 /// Start an asynchronous operation to write all of the supplied data to a 1332 /// stream. 1333 /** 1334 * This function is used to asynchronously write a certain number of bytes of 1335 * data to a stream. It is an initiating function for an @ref 1336 * asynchronous_operation, and always returns immediately. The asynchronous 1337 * operation will continue until one of the following conditions is true: 1338 * 1339 * @li All of the data in the supplied dynamic buffer sequence has been written. 1340 * 1341 * @li An error occurred. 1342 * 1343 * This operation is implemented in terms of zero or more calls to the stream's 1344 * async_write_some function, and is known as a <em>composed operation</em>. The 1345 * program must ensure that the stream performs no other write operations (such 1346 * as async_write, the stream's async_write_some function, or any other composed 1347 * operations that perform writes) until this operation completes. 1348 * 1349 * @param s The stream to which the data is to be written. The type must support 1350 * the AsyncWriteStream concept. 1351 * 1352 * @param buffers The dynamic buffer sequence from which data will be written. 1353 * Although the buffers object may be copied as necessary, ownership of the 1354 * underlying memory blocks is retained by the caller, which must guarantee 1355 * that they remain valid until the completion handler is called. Successfully 1356 * written data is automatically consumed from the buffers. 1357 * 1358 * @param token The @ref completion_token that will be used to produce a 1359 * completion handler, which will be called when the write completes. 1360 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1361 * @ref yield_context, or a function object with the correct completion 1362 * signature. The function signature of the completion handler must be: 1363 * @code void handler( 1364 * // Result of operation. 1365 * const boost::system::error_code& error, 1366 * 1367 * // Number of bytes written from the buffers. If an error 1368 * // occurred, this will be less than the sum of the buffer sizes. 1369 * std::size_t bytes_transferred 1370 * ); @endcode 1371 * Regardless of whether the asynchronous operation completes immediately or 1372 * not, the completion handler will not be invoked from within this function. 1373 * On immediate completion, invocation of the handler will be performed in a 1374 * manner equivalent to using boost::asio::async_immediate(). 1375 * 1376 * @par Completion Signature 1377 * @code void(boost::system::error_code, std::size_t) @endcode 1378 * 1379 * @par Per-Operation Cancellation 1380 * This asynchronous operation supports cancellation for the following 1381 * boost::asio::cancellation_type values: 1382 * 1383 * @li @c cancellation_type::terminal 1384 * 1385 * @li @c cancellation_type::partial 1386 * 1387 * if they are also supported by the @c AsyncWriteStream type's 1388 * @c async_write_some operation. 1389 */ 1390 template <typename AsyncWriteStream, typename DynamicBuffer_v2, 1391 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1392 std::size_t)) WriteToken 1393 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1394 inline auto async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers, 1395 WriteToken&& token 1396 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1397 constraint_t< 1398 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 1399 > = 0, 1400 constraint_t< 1401 !is_completion_condition<decay_t<WriteToken>>::value 1402 > = 0) 1403 -> decltype( 1404 async_initiate<WriteToken, 1405 void (boost::system::error_code, std::size_t)>( 1406 declval<detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>>(), 1407 token, static_cast<DynamicBuffer_v2&&>(buffers), 1408 transfer_all())) 1409 { 1410 return async_initiate<WriteToken, 1411 void (boost::system::error_code, std::size_t)>( 1412 detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>(s), 1413 token, static_cast<DynamicBuffer_v2&&>(buffers), 1414 transfer_all()); 1415 } 1416 1417 /// Start an asynchronous operation to write a certain amount of data to a 1418 /// stream. 1419 /** 1420 * This function is used to asynchronously write a certain number of bytes of 1421 * data to a stream. It is an initiating function for an @ref 1422 * asynchronous_operation, and always returns immediately. The asynchronous 1423 * operation will continue until one of the following conditions is true: 1424 * 1425 * @li All of the data in the supplied dynamic buffer sequence has been written. 1426 * 1427 * @li The completion_condition function object returns 0. 1428 * 1429 * This operation is implemented in terms of zero or more calls to the stream's 1430 * async_write_some function, and is known as a <em>composed operation</em>. The 1431 * program must ensure that the stream performs no other write operations (such 1432 * as async_write, the stream's async_write_some function, or any other composed 1433 * operations that perform writes) until this operation completes. 1434 * 1435 * @param s The stream to which the data is to be written. The type must support 1436 * the AsyncWriteStream concept. 1437 * 1438 * @param buffers The dynamic buffer sequence from which data will be written. 1439 * Although the buffers object may be copied as necessary, ownership of the 1440 * underlying memory blocks is retained by the caller, which must guarantee 1441 * that they remain valid until the completion handler is called. Successfully 1442 * written data is automatically consumed from the buffers. 1443 * 1444 * @param completion_condition The function object to be called to determine 1445 * whether the write operation is complete. The signature of the function object 1446 * must be: 1447 * @code std::size_t completion_condition( 1448 * // Result of latest async_write_some operation. 1449 * const boost::system::error_code& error, 1450 * 1451 * // Number of bytes transferred so far. 1452 * std::size_t bytes_transferred 1453 * ); @endcode 1454 * A return value of 0 indicates that the write operation is complete. A 1455 * non-zero return value indicates the maximum number of bytes to be written on 1456 * the next call to the stream's async_write_some function. 1457 * 1458 * @param token The @ref completion_token that will be used to produce a 1459 * completion handler, which will be called when the write completes. 1460 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1461 * @ref yield_context, or a function object with the correct completion 1462 * signature. The function signature of the completion handler must be: 1463 * @code void handler( 1464 * // Result of operation. 1465 * const boost::system::error_code& error, 1466 * 1467 * // Number of bytes written from the buffers. If an error 1468 * // occurred, this will be less than the sum of the buffer sizes. 1469 * std::size_t bytes_transferred 1470 * ); @endcode 1471 * Regardless of whether the asynchronous operation completes immediately or 1472 * not, the completion handler will not be invoked from within this function. 1473 * On immediate completion, invocation of the handler will be performed in a 1474 * manner equivalent to using boost::asio::async_immediate(). 1475 * 1476 * @par Completion Signature 1477 * @code void(boost::system::error_code, std::size_t) @endcode 1478 * 1479 * @par Per-Operation Cancellation 1480 * This asynchronous operation supports cancellation for the following 1481 * boost::asio::cancellation_type values: 1482 * 1483 * @li @c cancellation_type::terminal 1484 * 1485 * @li @c cancellation_type::partial 1486 * 1487 * if they are also supported by the @c AsyncWriteStream type's 1488 * @c async_write_some operation. 1489 */ 1490 template <typename AsyncWriteStream, 1491 typename DynamicBuffer_v2, typename CompletionCondition, 1492 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1493 std::size_t)) WriteToken 1494 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1495 inline auto async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers, 1496 CompletionCondition completion_condition, 1497 WriteToken&& token 1498 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1499 constraint_t< 1500 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 1501 > = 0, 1502 constraint_t< 1503 is_completion_condition<CompletionCondition>::value 1504 > = 0) 1505 -> decltype( 1506 async_initiate<WriteToken, 1507 void (boost::system::error_code, std::size_t)>( 1508 declval<detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>>(), 1509 token, static_cast<DynamicBuffer_v2&&>(buffers), 1510 static_cast<CompletionCondition&&>(completion_condition))) 1511 { 1512 return async_initiate<WriteToken, 1513 void (boost::system::error_code, std::size_t)>( 1514 detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>(s), 1515 token, static_cast<DynamicBuffer_v2&&>(buffers), 1516 static_cast<CompletionCondition&&>(completion_condition)); 1517 } 1518 1519 /*@}*/ 1520 1521 } // namespace asio 1522 } // namespace boost 1523 1524 #include <boost/asio/detail/pop_options.hpp> 1525 1526 #include <boost/asio/impl/write.hpp> 1527 1528 #endif // BOOST_ASIO_WRITE_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |