|
||||
File indexing completed on 2025-01-18 09:29:12
0001 // 0002 // write.hpp 0003 // ~~~~~~~~~ 0004 // 0005 // Copyright (c) 2003-2023 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 0190 /// Write a certain amount of data to a stream before returning. 0191 /** 0192 * This function is used to write a certain number of bytes of data to a stream. 0193 * The call will block until one of the following conditions is true: 0194 * 0195 * @li All of the data in the supplied buffers has been written. That is, the 0196 * bytes transferred is equal to the sum of the buffer sizes. 0197 * 0198 * @li The completion_condition function object returns 0. 0199 * 0200 * This operation is implemented in terms of zero or more calls to the stream's 0201 * write_some function. 0202 * 0203 * @param s The stream to which the data is to be written. The type must support 0204 * the SyncWriteStream concept. 0205 * 0206 * @param buffers One or more buffers containing the data to be written. The sum 0207 * of the buffer sizes indicates the maximum number of bytes to write to the 0208 * stream. 0209 * 0210 * @param completion_condition The function object to be called to determine 0211 * whether the write operation is complete. The signature of the function object 0212 * must be: 0213 * @code std::size_t completion_condition( 0214 * // Result of latest write_some operation. 0215 * const boost::system::error_code& error, 0216 * 0217 * // Number of bytes transferred so far. 0218 * std::size_t bytes_transferred 0219 * ); @endcode 0220 * A return value of 0 indicates that the write operation is complete. A 0221 * non-zero return value indicates the maximum number of bytes to be written on 0222 * the next call to the stream's write_some function. 0223 * 0224 * @param ec Set to indicate what error occurred, if any. 0225 * 0226 * @returns The number of bytes written. If an error occurs, returns the total 0227 * number of bytes successfully transferred prior to the error. 0228 */ 0229 template <typename SyncWriteStream, typename ConstBufferSequence, 0230 typename CompletionCondition> 0231 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers, 0232 CompletionCondition completion_condition, boost::system::error_code& ec, 0233 constraint_t< 0234 is_const_buffer_sequence<ConstBufferSequence>::value 0235 > = 0); 0236 0237 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0238 0239 /// Write all of the supplied data to a stream before returning. 0240 /** 0241 * This function is used to write a certain number of bytes of data to a stream. 0242 * The call will block until one of the following conditions is true: 0243 * 0244 * @li All of the data in the supplied dynamic buffer sequence has been written. 0245 * 0246 * @li An error occurred. 0247 * 0248 * This operation is implemented in terms of zero or more calls to the stream's 0249 * write_some function. 0250 * 0251 * @param s The stream to which the data is to be written. The type must support 0252 * the SyncWriteStream concept. 0253 * 0254 * @param buffers The dynamic buffer sequence from which data will be written. 0255 * Successfully written data is automatically consumed from the buffers. 0256 * 0257 * @returns The number of bytes transferred. 0258 * 0259 * @throws boost::system::system_error Thrown on failure. 0260 * 0261 * @note This overload is equivalent to calling: 0262 * @code boost::asio::write( 0263 * s, buffers, 0264 * boost::asio::transfer_all()); @endcode 0265 */ 0266 template <typename SyncWriteStream, typename DynamicBuffer_v1> 0267 std::size_t write(SyncWriteStream& s, 0268 DynamicBuffer_v1&& buffers, 0269 constraint_t< 0270 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0271 > = 0, 0272 constraint_t< 0273 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0274 > = 0); 0275 0276 /// Write all of the supplied data to a stream before returning. 0277 /** 0278 * This function is used to write a certain number of bytes of data to a stream. 0279 * The call will block until one of the following conditions is true: 0280 * 0281 * @li All of the data in the supplied dynamic buffer sequence has been written. 0282 * 0283 * @li An error occurred. 0284 * 0285 * This operation is implemented in terms of zero or more calls to the stream's 0286 * write_some function. 0287 * 0288 * @param s The stream to which the data is to be written. The type must support 0289 * the SyncWriteStream concept. 0290 * 0291 * @param buffers The dynamic buffer sequence from which data will be written. 0292 * Successfully written data is automatically consumed from the buffers. 0293 * 0294 * @param ec Set to indicate what error occurred, if any. 0295 * 0296 * @returns The number of bytes transferred. 0297 * 0298 * @note This overload is equivalent to calling: 0299 * @code boost::asio::write( 0300 * s, buffers, 0301 * boost::asio::transfer_all(), ec); @endcode 0302 */ 0303 template <typename SyncWriteStream, typename DynamicBuffer_v1> 0304 std::size_t write(SyncWriteStream& s, 0305 DynamicBuffer_v1&& buffers, 0306 boost::system::error_code& ec, 0307 constraint_t< 0308 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0309 > = 0, 0310 constraint_t< 0311 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0312 > = 0); 0313 0314 /// Write a certain amount of data to a stream before returning. 0315 /** 0316 * This function is used to write a certain number of bytes of data to a stream. 0317 * The call will block until one of the following conditions is true: 0318 * 0319 * @li All of the data in the supplied dynamic buffer sequence has been written. 0320 * 0321 * @li The completion_condition function object returns 0. 0322 * 0323 * This operation is implemented in terms of zero or more calls to the stream's 0324 * write_some function. 0325 * 0326 * @param s The stream to which the data is to be written. The type must support 0327 * the SyncWriteStream concept. 0328 * 0329 * @param buffers The dynamic buffer sequence from which data will be written. 0330 * Successfully written data is automatically consumed from the buffers. 0331 * 0332 * @param completion_condition The function object to be called to determine 0333 * whether the write operation is complete. The signature of the function object 0334 * must be: 0335 * @code std::size_t completion_condition( 0336 * // Result of latest write_some operation. 0337 * const boost::system::error_code& error, 0338 * 0339 * // Number of bytes transferred so far. 0340 * std::size_t bytes_transferred 0341 * ); @endcode 0342 * A return value of 0 indicates that the write operation is complete. A 0343 * non-zero return value indicates the maximum number of bytes to be written on 0344 * the next call to the stream's write_some function. 0345 * 0346 * @returns The number of bytes transferred. 0347 * 0348 * @throws boost::system::system_error Thrown on failure. 0349 */ 0350 template <typename SyncWriteStream, typename DynamicBuffer_v1, 0351 typename CompletionCondition> 0352 std::size_t write(SyncWriteStream& s, 0353 DynamicBuffer_v1&& buffers, 0354 CompletionCondition completion_condition, 0355 constraint_t< 0356 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0357 > = 0, 0358 constraint_t< 0359 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0360 > = 0); 0361 0362 /// Write a certain amount of data to a stream before returning. 0363 /** 0364 * This function is used to write a certain number of bytes of data to a stream. 0365 * The call will block until one of the following conditions is true: 0366 * 0367 * @li All of the data in the supplied dynamic buffer sequence has been written. 0368 * 0369 * @li The completion_condition function object returns 0. 0370 * 0371 * This operation is implemented in terms of zero or more calls to the stream's 0372 * write_some function. 0373 * 0374 * @param s The stream to which the data is to be written. The type must support 0375 * the SyncWriteStream concept. 0376 * 0377 * @param buffers The dynamic buffer sequence from which data will be written. 0378 * Successfully written data is automatically consumed from the buffers. 0379 * 0380 * @param completion_condition The function object to be called to determine 0381 * whether the write operation is complete. The signature of the function object 0382 * must be: 0383 * @code std::size_t completion_condition( 0384 * // Result of latest write_some operation. 0385 * const boost::system::error_code& error, 0386 * 0387 * // Number of bytes transferred so far. 0388 * std::size_t bytes_transferred 0389 * ); @endcode 0390 * A return value of 0 indicates that the write operation is complete. A 0391 * non-zero return value indicates the maximum number of bytes to be written on 0392 * the next call to the stream's write_some function. 0393 * 0394 * @param ec Set to indicate what error occurred, if any. 0395 * 0396 * @returns The number of bytes written. If an error occurs, returns the total 0397 * number of bytes successfully transferred prior to the error. 0398 */ 0399 template <typename SyncWriteStream, typename DynamicBuffer_v1, 0400 typename CompletionCondition> 0401 std::size_t write(SyncWriteStream& s, 0402 DynamicBuffer_v1&& buffers, 0403 CompletionCondition completion_condition, boost::system::error_code& ec, 0404 constraint_t< 0405 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0406 > = 0, 0407 constraint_t< 0408 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0409 > = 0); 0410 0411 #if !defined(BOOST_ASIO_NO_EXTENSIONS) 0412 #if !defined(BOOST_ASIO_NO_IOSTREAM) 0413 0414 /// Write all of the supplied data to a stream before returning. 0415 /** 0416 * This function is used to write a certain number of bytes of data to a stream. 0417 * The call will block until one of the following conditions is true: 0418 * 0419 * @li All of the data in the supplied basic_streambuf has been written. 0420 * 0421 * @li An error occurred. 0422 * 0423 * This operation is implemented in terms of zero or more calls to the stream's 0424 * write_some function. 0425 * 0426 * @param s The stream to which the data is to be written. The type must support 0427 * the SyncWriteStream concept. 0428 * 0429 * @param b The basic_streambuf object from which data will be written. 0430 * 0431 * @returns The number of bytes transferred. 0432 * 0433 * @throws boost::system::system_error Thrown on failure. 0434 * 0435 * @note This overload is equivalent to calling: 0436 * @code boost::asio::write( 0437 * s, b, 0438 * boost::asio::transfer_all()); @endcode 0439 */ 0440 template <typename SyncWriteStream, typename Allocator> 0441 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b); 0442 0443 /// Write all of the supplied data to a stream before returning. 0444 /** 0445 * This function is used to write a certain number of bytes of data to a stream. 0446 * The call will block until one of the following conditions is true: 0447 * 0448 * @li All of the data in the supplied basic_streambuf has been written. 0449 * 0450 * @li An error occurred. 0451 * 0452 * This operation is implemented in terms of zero or more calls to the stream's 0453 * write_some function. 0454 * 0455 * @param s The stream to which the data is to be written. The type must support 0456 * the SyncWriteStream concept. 0457 * 0458 * @param b The basic_streambuf object from which data will be written. 0459 * 0460 * @param ec Set to indicate what error occurred, if any. 0461 * 0462 * @returns The number of bytes transferred. 0463 * 0464 * @note This overload is equivalent to calling: 0465 * @code boost::asio::write( 0466 * s, b, 0467 * boost::asio::transfer_all(), ec); @endcode 0468 */ 0469 template <typename SyncWriteStream, typename Allocator> 0470 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b, 0471 boost::system::error_code& ec); 0472 0473 /// Write a certain amount of data to a stream before returning. 0474 /** 0475 * This function is used to write a certain number of bytes of data to a stream. 0476 * The call will block until one of the following conditions is true: 0477 * 0478 * @li All of the data in the supplied basic_streambuf has been written. 0479 * 0480 * @li The completion_condition function object returns 0. 0481 * 0482 * This operation is implemented in terms of zero or more calls to the stream's 0483 * write_some function. 0484 * 0485 * @param s The stream to which the data is to be written. The type must support 0486 * the SyncWriteStream concept. 0487 * 0488 * @param b The basic_streambuf object from which data will be written. 0489 * 0490 * @param completion_condition The function object to be called to determine 0491 * whether the write operation is complete. The signature of the function object 0492 * must be: 0493 * @code std::size_t completion_condition( 0494 * // Result of latest write_some operation. 0495 * const boost::system::error_code& error, 0496 * 0497 * // Number of bytes transferred so far. 0498 * std::size_t bytes_transferred 0499 * ); @endcode 0500 * A return value of 0 indicates that the write operation is complete. A 0501 * non-zero return value indicates the maximum number of bytes to be written on 0502 * the next call to the stream's write_some function. 0503 * 0504 * @returns The number of bytes transferred. 0505 * 0506 * @throws boost::system::system_error Thrown on failure. 0507 */ 0508 template <typename SyncWriteStream, typename Allocator, 0509 typename CompletionCondition> 0510 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b, 0511 CompletionCondition completion_condition); 0512 0513 /// Write a certain amount of data to a stream before returning. 0514 /** 0515 * This function is used to write a certain number of bytes of data to a stream. 0516 * The call will block until one of the following conditions is true: 0517 * 0518 * @li All of the data in the supplied basic_streambuf has been written. 0519 * 0520 * @li The completion_condition function object returns 0. 0521 * 0522 * This operation is implemented in terms of zero or more calls to the stream's 0523 * write_some function. 0524 * 0525 * @param s The stream to which the data is to be written. The type must support 0526 * the SyncWriteStream concept. 0527 * 0528 * @param b The basic_streambuf object from which data will be written. 0529 * 0530 * @param completion_condition The function object to be called to determine 0531 * whether the write operation is complete. The signature of the function object 0532 * must be: 0533 * @code std::size_t completion_condition( 0534 * // Result of latest write_some operation. 0535 * const boost::system::error_code& error, 0536 * 0537 * // Number of bytes transferred so far. 0538 * std::size_t bytes_transferred 0539 * ); @endcode 0540 * A return value of 0 indicates that the write operation is complete. A 0541 * non-zero return value indicates the maximum number of bytes to be written on 0542 * the next call to the stream's write_some function. 0543 * 0544 * @param ec Set to indicate what error occurred, if any. 0545 * 0546 * @returns The number of bytes written. If an error occurs, returns the total 0547 * number of bytes successfully transferred prior to the error. 0548 */ 0549 template <typename SyncWriteStream, typename Allocator, 0550 typename CompletionCondition> 0551 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b, 0552 CompletionCondition completion_condition, boost::system::error_code& ec); 0553 0554 #endif // !defined(BOOST_ASIO_NO_IOSTREAM) 0555 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS) 0556 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0557 0558 /// Write all of the supplied data to a stream before returning. 0559 /** 0560 * This function is used to write a certain number of bytes of data to a stream. 0561 * The call will block until one of the following conditions is true: 0562 * 0563 * @li All of the data in the supplied dynamic buffer sequence has been written. 0564 * 0565 * @li An error occurred. 0566 * 0567 * This operation is implemented in terms of zero or more calls to the stream's 0568 * write_some function. 0569 * 0570 * @param s The stream to which the data is to be written. The type must support 0571 * the SyncWriteStream concept. 0572 * 0573 * @param buffers The dynamic buffer sequence from which data will be written. 0574 * Successfully written data is automatically consumed from the buffers. 0575 * 0576 * @returns The number of bytes transferred. 0577 * 0578 * @throws boost::system::system_error Thrown on failure. 0579 * 0580 * @note This overload is equivalent to calling: 0581 * @code boost::asio::write( 0582 * s, buffers, 0583 * boost::asio::transfer_all()); @endcode 0584 */ 0585 template <typename SyncWriteStream, typename DynamicBuffer_v2> 0586 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0587 constraint_t< 0588 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0589 > = 0); 0590 0591 /// Write all of the supplied data to a stream before returning. 0592 /** 0593 * This function is used to write a certain number of bytes of data to a stream. 0594 * The call will block until one of the following conditions is true: 0595 * 0596 * @li All of the data in the supplied dynamic buffer sequence has been written. 0597 * 0598 * @li An error occurred. 0599 * 0600 * This operation is implemented in terms of zero or more calls to the stream's 0601 * write_some function. 0602 * 0603 * @param s The stream to which the data is to be written. The type must support 0604 * the SyncWriteStream concept. 0605 * 0606 * @param buffers The dynamic buffer sequence from which data will be written. 0607 * Successfully written data is automatically consumed from the buffers. 0608 * 0609 * @param ec Set to indicate what error occurred, if any. 0610 * 0611 * @returns The number of bytes transferred. 0612 * 0613 * @note This overload is equivalent to calling: 0614 * @code boost::asio::write( 0615 * s, buffers, 0616 * boost::asio::transfer_all(), ec); @endcode 0617 */ 0618 template <typename SyncWriteStream, typename DynamicBuffer_v2> 0619 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0620 boost::system::error_code& ec, 0621 constraint_t< 0622 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0623 > = 0); 0624 0625 /// Write a certain amount of data to a stream before returning. 0626 /** 0627 * This function is used to write a certain number of bytes of data to a stream. 0628 * The call will block until one of the following conditions is true: 0629 * 0630 * @li All of the data in the supplied dynamic buffer sequence has been written. 0631 * 0632 * @li The completion_condition function object returns 0. 0633 * 0634 * This operation is implemented in terms of zero or more calls to the stream's 0635 * write_some function. 0636 * 0637 * @param s The stream to which the data is to be written. The type must support 0638 * the SyncWriteStream concept. 0639 * 0640 * @param buffers The dynamic buffer sequence from which data will be written. 0641 * Successfully written data is automatically consumed from the buffers. 0642 * 0643 * @param completion_condition The function object to be called to determine 0644 * whether the write operation is complete. The signature of the function object 0645 * must be: 0646 * @code std::size_t completion_condition( 0647 * // Result of latest write_some operation. 0648 * const boost::system::error_code& error, 0649 * 0650 * // Number of bytes transferred so far. 0651 * std::size_t bytes_transferred 0652 * ); @endcode 0653 * A return value of 0 indicates that the write operation is complete. A 0654 * non-zero return value indicates the maximum number of bytes to be written on 0655 * the next call to the stream's write_some function. 0656 * 0657 * @returns The number of bytes transferred. 0658 * 0659 * @throws boost::system::system_error Thrown on failure. 0660 */ 0661 template <typename SyncWriteStream, typename DynamicBuffer_v2, 0662 typename CompletionCondition> 0663 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0664 CompletionCondition completion_condition, 0665 constraint_t< 0666 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0667 > = 0); 0668 0669 /// Write a certain amount of data to a stream before returning. 0670 /** 0671 * This function is used to write a certain number of bytes of data to a stream. 0672 * The call will block until one of the following conditions is true: 0673 * 0674 * @li All of the data in the supplied dynamic buffer sequence has been written. 0675 * 0676 * @li The completion_condition function object returns 0. 0677 * 0678 * This operation is implemented in terms of zero or more calls to the stream's 0679 * write_some function. 0680 * 0681 * @param s The stream to which the data is to be written. The type must support 0682 * the SyncWriteStream concept. 0683 * 0684 * @param buffers The dynamic buffer sequence from which data will be written. 0685 * Successfully written data is automatically consumed from the buffers. 0686 * 0687 * @param completion_condition The function object to be called to determine 0688 * whether the write operation is complete. The signature of the function object 0689 * must be: 0690 * @code std::size_t completion_condition( 0691 * // Result of latest write_some operation. 0692 * const boost::system::error_code& error, 0693 * 0694 * // Number of bytes transferred so far. 0695 * std::size_t bytes_transferred 0696 * ); @endcode 0697 * A return value of 0 indicates that the write operation is complete. A 0698 * non-zero return value indicates the maximum number of bytes to be written on 0699 * the next call to the stream's write_some function. 0700 * 0701 * @param ec Set to indicate what error occurred, if any. 0702 * 0703 * @returns The number of bytes written. If an error occurs, returns the total 0704 * number of bytes successfully transferred prior to the error. 0705 */ 0706 template <typename SyncWriteStream, typename DynamicBuffer_v2, 0707 typename CompletionCondition> 0708 std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers, 0709 CompletionCondition completion_condition, boost::system::error_code& ec, 0710 constraint_t< 0711 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 0712 > = 0); 0713 0714 /*@}*/ 0715 /** 0716 * @defgroup async_write boost::asio::async_write 0717 * 0718 * @brief The @c async_write function is a composed asynchronous operation that 0719 * writes a certain amount of data to a stream before completion. 0720 */ 0721 /*@{*/ 0722 0723 /// Start an asynchronous operation to write all of the supplied data to a 0724 /// stream. 0725 /** 0726 * This function is used to asynchronously write a certain number of bytes of 0727 * data to a stream. It is an initiating function for an @ref 0728 * asynchronous_operation, and always returns immediately. The asynchronous 0729 * operation will continue until one of the following conditions is true: 0730 * 0731 * @li All of the data in the supplied buffers has been written. That is, the 0732 * bytes transferred is equal to the sum of the buffer sizes. 0733 * 0734 * @li An error occurred. 0735 * 0736 * This operation is implemented in terms of zero or more calls to the stream's 0737 * async_write_some function, and is known as a <em>composed operation</em>. The 0738 * program must ensure that the stream performs no other write operations (such 0739 * as async_write, the stream's async_write_some function, or any other composed 0740 * operations that perform writes) until this operation completes. 0741 * 0742 * @param s The stream to which the data is to be written. The type must support 0743 * the AsyncWriteStream concept. 0744 * 0745 * @param buffers One or more buffers containing the data to be written. 0746 * Although the buffers object may be copied as necessary, ownership of the 0747 * underlying memory blocks is retained by the caller, which must guarantee 0748 * that they remain valid until the completion handler is called. 0749 * 0750 * @param token The @ref completion_token that will be used to produce a 0751 * completion handler, which will be called when the write completes. 0752 * Potential completion tokens include @ref use_future, @ref use_awaitable, 0753 * @ref yield_context, or a function object with the correct completion 0754 * signature. The function signature of the completion handler must be: 0755 * @code void handler( 0756 * // Result of operation. 0757 * const boost::system::error_code& error, 0758 * 0759 * // Number of bytes written from the buffers. If an error 0760 * // occurred, this will be less than the sum of the buffer sizes. 0761 * std::size_t bytes_transferred 0762 * ); @endcode 0763 * Regardless of whether the asynchronous operation completes immediately or 0764 * not, the completion handler will not be invoked from within this function. 0765 * On immediate completion, invocation of the handler will be performed in a 0766 * manner equivalent to using boost::asio::post(). 0767 * 0768 * @par Completion Signature 0769 * @code void(boost::system::error_code, std::size_t) @endcode 0770 * 0771 * @par Example 0772 * To write a single data buffer use the @ref buffer function as follows: 0773 * @code 0774 * boost::asio::async_write(s, boost::asio::buffer(data, size), handler); 0775 * @endcode 0776 * See the @ref buffer documentation for information on writing multiple 0777 * buffers in one go, and how to use it with arrays, boost::array or 0778 * std::vector. 0779 * 0780 * @par Per-Operation Cancellation 0781 * This asynchronous operation supports cancellation for the following 0782 * boost::asio::cancellation_type values: 0783 * 0784 * @li @c cancellation_type::terminal 0785 * 0786 * @li @c cancellation_type::partial 0787 * 0788 * if they are also supported by the @c AsyncWriteStream type's 0789 * @c async_write_some operation. 0790 */ 0791 template <typename AsyncWriteStream, typename ConstBufferSequence, 0792 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 0793 std::size_t)) WriteToken 0794 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 0795 auto async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers, 0796 WriteToken&& token 0797 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 0798 constraint_t< 0799 is_const_buffer_sequence<ConstBufferSequence>::value 0800 > = 0) 0801 -> decltype( 0802 async_initiate<WriteToken, 0803 void (boost::system::error_code, std::size_t)>( 0804 declval<detail::initiate_async_write<AsyncWriteStream>>(), 0805 token, buffers, transfer_all())); 0806 0807 /// Start an asynchronous operation to write a certain amount of data to a 0808 /// stream. 0809 /** 0810 * This function is used to asynchronously write a certain number of bytes of 0811 * data to a stream. It is an initiating function for an @ref 0812 * asynchronous_operation, and always returns immediately. The asynchronous 0813 * operation will continue until one of the following conditions is true: 0814 * 0815 * @li All of the data in the supplied buffers has been written. That is, the 0816 * bytes transferred is equal to the sum of the buffer sizes. 0817 * 0818 * @li The completion_condition function object returns 0. 0819 * 0820 * This operation is implemented in terms of zero or more calls to the stream's 0821 * async_write_some function, and is known as a <em>composed operation</em>. The 0822 * program must ensure that the stream performs no other write operations (such 0823 * as async_write, the stream's async_write_some function, or any other composed 0824 * operations that perform writes) until this operation completes. 0825 * 0826 * @param s The stream to which the data is to be written. The type must support 0827 * the AsyncWriteStream concept. 0828 * 0829 * @param buffers One or more buffers containing the data to be written. 0830 * Although the buffers object may be copied as necessary, ownership of the 0831 * underlying memory blocks is retained by the caller, which must guarantee 0832 * that they remain valid until the completion handler is called. 0833 * 0834 * @param completion_condition The function object to be called to determine 0835 * whether the write operation is complete. The signature of the function object 0836 * must be: 0837 * @code std::size_t completion_condition( 0838 * // Result of latest async_write_some operation. 0839 * const boost::system::error_code& error, 0840 * 0841 * // Number of bytes transferred so far. 0842 * std::size_t bytes_transferred 0843 * ); @endcode 0844 * A return value of 0 indicates that the write operation is complete. A 0845 * non-zero return value indicates the maximum number of bytes to be written on 0846 * the next call to the stream's async_write_some function. 0847 * 0848 * @param token The @ref completion_token that will be used to produce a 0849 * completion handler, which will be called when the write completes. 0850 * Potential completion tokens include @ref use_future, @ref use_awaitable, 0851 * @ref yield_context, or a function object with the correct completion 0852 * signature. The function signature of the completion handler must be: 0853 * @code void handler( 0854 * // Result of operation. 0855 * const boost::system::error_code& error, 0856 * 0857 * // Number of bytes written from the buffers. If an error 0858 * // occurred, this will be less than the sum of the buffer sizes. 0859 * std::size_t bytes_transferred 0860 * ); @endcode 0861 * Regardless of whether the asynchronous operation completes immediately or 0862 * not, the completion handler will not be invoked from within this function. 0863 * On immediate completion, invocation of the handler will be performed in a 0864 * manner equivalent to using boost::asio::post(). 0865 * 0866 * @par Completion Signature 0867 * @code void(boost::system::error_code, std::size_t) @endcode 0868 * 0869 * @par Example 0870 * To write a single data buffer use the @ref buffer function as follows: 0871 * @code boost::asio::async_write(s, 0872 * boost::asio::buffer(data, size), 0873 * boost::asio::transfer_at_least(32), 0874 * handler); @endcode 0875 * See the @ref buffer documentation for information on writing multiple 0876 * buffers in one go, and how to use it with arrays, boost::array or 0877 * std::vector. 0878 * 0879 * @par Per-Operation Cancellation 0880 * This asynchronous operation supports cancellation for the following 0881 * boost::asio::cancellation_type values: 0882 * 0883 * @li @c cancellation_type::terminal 0884 * 0885 * @li @c cancellation_type::partial 0886 * 0887 * if they are also supported by the @c AsyncWriteStream type's 0888 * @c async_write_some operation. 0889 */ 0890 template <typename AsyncWriteStream, 0891 typename ConstBufferSequence, typename CompletionCondition, 0892 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 0893 std::size_t)) WriteToken> 0894 auto async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers, 0895 CompletionCondition completion_condition, 0896 WriteToken&& token, 0897 constraint_t< 0898 is_const_buffer_sequence<ConstBufferSequence>::value 0899 > = 0) 0900 -> decltype( 0901 async_initiate<WriteToken, 0902 void (boost::system::error_code, std::size_t)>( 0903 declval<detail::initiate_async_write<AsyncWriteStream>>(), 0904 token, buffers, 0905 static_cast<CompletionCondition&&>(completion_condition))); 0906 0907 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 0908 0909 /// Start an asynchronous operation to write all of the supplied data to a 0910 /// stream. 0911 /** 0912 * This function is used to asynchronously write a certain number of bytes of 0913 * data to a stream. It is an initiating function for an @ref 0914 * asynchronous_operation, and always returns immediately. The asynchronous 0915 * operation will continue until one of the following conditions is true: 0916 * 0917 * @li All of the data in the supplied dynamic buffer sequence has been written. 0918 * 0919 * @li An error occurred. 0920 * 0921 * This operation is implemented in terms of zero or more calls to the stream's 0922 * async_write_some function, and is known as a <em>composed operation</em>. The 0923 * program must ensure that the stream performs no other write operations (such 0924 * as async_write, the stream's async_write_some function, or any other composed 0925 * operations that perform writes) until this operation completes. 0926 * 0927 * @param s The stream to which the data is to be written. The type must support 0928 * the AsyncWriteStream concept. 0929 * 0930 * @param buffers The dynamic buffer sequence from which data will be written. 0931 * Although the buffers object may be copied as necessary, ownership of the 0932 * underlying memory blocks is retained by the caller, which must guarantee 0933 * that they remain valid until the completion handler is called. Successfully 0934 * written data is automatically consumed from the buffers. 0935 * 0936 * @param token The @ref completion_token that will be used to produce a 0937 * completion handler, which will be called when the write completes. 0938 * Potential completion tokens include @ref use_future, @ref use_awaitable, 0939 * @ref yield_context, or a function object with the correct completion 0940 * signature. The function signature of the completion handler must be: 0941 * @code void handler( 0942 * // Result of operation. 0943 * const boost::system::error_code& error, 0944 * 0945 * // Number of bytes written from the buffers. If an error 0946 * // occurred, this will be less than the sum of the buffer sizes. 0947 * std::size_t bytes_transferred 0948 * ); @endcode 0949 * Regardless of whether the asynchronous operation completes immediately or 0950 * not, the completion handler will not be invoked from within this function. 0951 * On immediate completion, invocation of the handler will be performed in a 0952 * manner equivalent to using boost::asio::post(). 0953 * 0954 * @par Completion Signature 0955 * @code void(boost::system::error_code, std::size_t) @endcode 0956 * 0957 * @par Per-Operation Cancellation 0958 * This asynchronous operation supports cancellation for the following 0959 * boost::asio::cancellation_type values: 0960 * 0961 * @li @c cancellation_type::terminal 0962 * 0963 * @li @c cancellation_type::partial 0964 * 0965 * if they are also supported by the @c AsyncWriteStream type's 0966 * @c async_write_some operation. 0967 */ 0968 template <typename AsyncWriteStream, typename DynamicBuffer_v1, 0969 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 0970 std::size_t)) WriteToken 0971 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 0972 auto async_write(AsyncWriteStream& s, DynamicBuffer_v1&& buffers, 0973 WriteToken&& token 0974 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 0975 constraint_t< 0976 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 0977 > = 0, 0978 constraint_t< 0979 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 0980 > = 0) 0981 -> decltype( 0982 async_initiate<WriteToken, 0983 void (boost::system::error_code, std::size_t)>( 0984 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 0985 token, static_cast<DynamicBuffer_v1&&>(buffers), 0986 transfer_all())); 0987 0988 /// Start an asynchronous operation to write a certain amount of data to a 0989 /// stream. 0990 /** 0991 * This function is used to asynchronously write a certain number of bytes of 0992 * data to a stream. It is an initiating function for an @ref 0993 * asynchronous_operation, and always returns immediately. The asynchronous 0994 * operation will continue until one of the following conditions is true: 0995 * 0996 * @li All of the data in the supplied dynamic buffer sequence has been written. 0997 * 0998 * @li The completion_condition function object returns 0. 0999 * 1000 * This operation is implemented in terms of zero or more calls to the stream's 1001 * async_write_some function, and is known as a <em>composed operation</em>. The 1002 * program must ensure that the stream performs no other write operations (such 1003 * as async_write, the stream's async_write_some function, or any other composed 1004 * operations that perform writes) until this operation completes. 1005 * 1006 * @param s The stream to which the data is to be written. The type must support 1007 * the AsyncWriteStream concept. 1008 * 1009 * @param buffers The dynamic buffer sequence from which data will be written. 1010 * Although the buffers object may be copied as necessary, ownership of the 1011 * underlying memory blocks is retained by the caller, which must guarantee 1012 * that they remain valid until the completion handler is called. Successfully 1013 * written data is automatically consumed from the buffers. 1014 * 1015 * @param completion_condition The function object to be called to determine 1016 * whether the write operation is complete. The signature of the function object 1017 * must be: 1018 * @code std::size_t completion_condition( 1019 * // Result of latest async_write_some operation. 1020 * const boost::system::error_code& error, 1021 * 1022 * // Number of bytes transferred so far. 1023 * std::size_t bytes_transferred 1024 * ); @endcode 1025 * A return value of 0 indicates that the write operation is complete. A 1026 * non-zero return value indicates the maximum number of bytes to be written on 1027 * the next call to the stream's async_write_some function. 1028 * 1029 * @param token The @ref completion_token that will be used to produce a 1030 * completion handler, which will be called when the write completes. 1031 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1032 * @ref yield_context, or a function object with the correct completion 1033 * signature. The function signature of the completion handler must be: 1034 * @code void handler( 1035 * // Result of operation. 1036 * const boost::system::error_code& error, 1037 * 1038 * // Number of bytes written from the buffers. If an error 1039 * // occurred, this will be less than the sum of the buffer sizes. 1040 * std::size_t bytes_transferred 1041 * ); @endcode 1042 * Regardless of whether the asynchronous operation completes immediately or 1043 * not, the completion handler will not be invoked from within this function. 1044 * On immediate completion, invocation of the handler will be performed in a 1045 * manner equivalent to using boost::asio::post(). 1046 * 1047 * @par Completion Signature 1048 * @code void(boost::system::error_code, std::size_t) @endcode 1049 * 1050 * @par Per-Operation Cancellation 1051 * This asynchronous operation supports cancellation for the following 1052 * boost::asio::cancellation_type values: 1053 * 1054 * @li @c cancellation_type::terminal 1055 * 1056 * @li @c cancellation_type::partial 1057 * 1058 * if they are also supported by the @c AsyncWriteStream type's 1059 * @c async_write_some operation. 1060 */ 1061 template <typename AsyncWriteStream, 1062 typename DynamicBuffer_v1, typename CompletionCondition, 1063 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1064 std::size_t)) WriteToken> 1065 auto async_write(AsyncWriteStream& s, DynamicBuffer_v1&& buffers, 1066 CompletionCondition completion_condition, WriteToken&& token, 1067 constraint_t< 1068 is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value 1069 > = 0, 1070 constraint_t< 1071 !is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value 1072 > = 0) 1073 -> decltype( 1074 async_initiate<WriteToken, 1075 void (boost::system::error_code, std::size_t)>( 1076 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1077 token, static_cast<DynamicBuffer_v1&&>(buffers), 1078 static_cast<CompletionCondition&&>(completion_condition))); 1079 1080 #if !defined(BOOST_ASIO_NO_EXTENSIONS) 1081 #if !defined(BOOST_ASIO_NO_IOSTREAM) 1082 1083 /// Start an asynchronous operation to write all of the supplied data to a 1084 /// stream. 1085 /** 1086 * This function is used to asynchronously write a certain number of bytes of 1087 * data to a stream. It is an initiating function for an @ref 1088 * asynchronous_operation, and always returns immediately. The asynchronous 1089 * operation will continue until one of the following conditions is true: 1090 * 1091 * @li All of the data in the supplied basic_streambuf has been written. 1092 * 1093 * @li An error occurred. 1094 * 1095 * This operation is implemented in terms of zero or more calls to the stream's 1096 * async_write_some function, and is known as a <em>composed operation</em>. The 1097 * program must ensure that the stream performs no other write operations (such 1098 * as async_write, the stream's async_write_some function, or any other composed 1099 * operations that perform writes) until this operation completes. 1100 * 1101 * @param s The stream to which the data is to be written. The type must support 1102 * the AsyncWriteStream concept. 1103 * 1104 * @param b A basic_streambuf object from which data will be written. Ownership 1105 * of the streambuf is retained by the caller, which must guarantee that it 1106 * remains valid until the completion handler is called. 1107 * 1108 * @param token The @ref completion_token that will be used to produce a 1109 * completion handler, which will be called when the write completes. 1110 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1111 * @ref yield_context, or a function object with the correct completion 1112 * signature. The function signature of the completion handler must be: 1113 * @code void handler( 1114 * // Result of operation. 1115 * const boost::system::error_code& error, 1116 * 1117 * // Number of bytes written from the buffers. If an error 1118 * // occurred, this will be less than the sum of the buffer sizes. 1119 * std::size_t bytes_transferred 1120 * ); @endcode 1121 * Regardless of whether the asynchronous operation completes immediately or 1122 * not, the completion handler will not be invoked from within this function. 1123 * On immediate completion, invocation of the handler will be performed in a 1124 * manner equivalent to using boost::asio::post(). 1125 * 1126 * @par Completion Signature 1127 * @code void(boost::system::error_code, std::size_t) @endcode 1128 * 1129 * @par Per-Operation Cancellation 1130 * This asynchronous operation supports cancellation for the following 1131 * boost::asio::cancellation_type values: 1132 * 1133 * @li @c cancellation_type::terminal 1134 * 1135 * @li @c cancellation_type::partial 1136 * 1137 * if they are also supported by the @c AsyncWriteStream type's 1138 * @c async_write_some operation. 1139 */ 1140 template <typename AsyncWriteStream, typename Allocator, 1141 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1142 std::size_t)) WriteToken 1143 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1144 auto async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b, 1145 WriteToken&& token 1146 = default_completion_token_t<typename AsyncWriteStream::executor_type>()) 1147 -> decltype( 1148 async_initiate<WriteToken, 1149 void (boost::system::error_code, std::size_t)>( 1150 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1151 token, basic_streambuf_ref<Allocator>(b), transfer_all())); 1152 1153 /// Start an asynchronous operation to write a certain amount of data to a 1154 /// stream. 1155 /** 1156 * This function is used to asynchronously write a certain number of bytes of 1157 * data to a stream. It is an initiating function for an @ref 1158 * asynchronous_operation, and always returns immediately. The asynchronous 1159 * operation will continue until one of the following conditions is true: 1160 * 1161 * @li All of the data in the supplied basic_streambuf has been written. 1162 * 1163 * @li The completion_condition function object returns 0. 1164 * 1165 * This operation is implemented in terms of zero or more calls to the stream's 1166 * async_write_some function, and is known as a <em>composed operation</em>. The 1167 * program must ensure that the stream performs no other write operations (such 1168 * as async_write, the stream's async_write_some function, or any other composed 1169 * operations that perform writes) until this operation completes. 1170 * 1171 * @param s The stream to which the data is to be written. The type must support 1172 * the AsyncWriteStream concept. 1173 * 1174 * @param b A basic_streambuf object from which data will be written. Ownership 1175 * of the streambuf is retained by the caller, which must guarantee that it 1176 * remains valid until the completion handler is called. 1177 * 1178 * @param completion_condition The function object to be called to determine 1179 * whether the write operation is complete. The signature of the function object 1180 * must be: 1181 * @code std::size_t completion_condition( 1182 * // Result of latest async_write_some operation. 1183 * const boost::system::error_code& error, 1184 * 1185 * // Number of bytes transferred so far. 1186 * std::size_t bytes_transferred 1187 * ); @endcode 1188 * A return value of 0 indicates that the write operation is complete. A 1189 * non-zero return value indicates the maximum number of bytes to be written on 1190 * the next call to the stream's async_write_some function. 1191 * 1192 * @param token The @ref completion_token that will be used to produce a 1193 * completion handler, which will be called when the write completes. 1194 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1195 * @ref yield_context, or a function object with the correct completion 1196 * signature. The function signature of the completion handler must be: 1197 * @code void handler( 1198 * // Result of operation. 1199 * const boost::system::error_code& error, 1200 * 1201 * // Number of bytes written from the buffers. If an error 1202 * // occurred, this will be less than the sum of the buffer sizes. 1203 * std::size_t bytes_transferred 1204 * ); @endcode 1205 * Regardless of whether the asynchronous operation completes immediately or 1206 * not, the completion handler will not be invoked from within this function. 1207 * On immediate completion, invocation of the handler will be performed in a 1208 * manner equivalent to using boost::asio::post(). 1209 * 1210 * @par Completion Signature 1211 * @code void(boost::system::error_code, std::size_t) @endcode 1212 * 1213 * @par Per-Operation Cancellation 1214 * This asynchronous operation supports cancellation for the following 1215 * boost::asio::cancellation_type values: 1216 * 1217 * @li @c cancellation_type::terminal 1218 * 1219 * @li @c cancellation_type::partial 1220 * 1221 * if they are also supported by the @c AsyncWriteStream type's 1222 * @c async_write_some operation. 1223 */ 1224 template <typename AsyncWriteStream, 1225 typename Allocator, typename CompletionCondition, 1226 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1227 std::size_t)) WriteToken> 1228 auto async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b, 1229 CompletionCondition completion_condition, WriteToken&& token) 1230 -> decltype( 1231 async_initiate<WriteToken, 1232 void (boost::system::error_code, std::size_t)>( 1233 declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(), 1234 token, basic_streambuf_ref<Allocator>(b), 1235 static_cast<CompletionCondition&&>(completion_condition))); 1236 1237 #endif // !defined(BOOST_ASIO_NO_IOSTREAM) 1238 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS) 1239 #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) 1240 1241 /// Start an asynchronous operation to write all of the supplied data to a 1242 /// stream. 1243 /** 1244 * This function is used to asynchronously write a certain number of bytes of 1245 * data to a stream. It is an initiating function for an @ref 1246 * asynchronous_operation, and always returns immediately. The asynchronous 1247 * operation will continue until one of the following conditions is true: 1248 * 1249 * @li All of the data in the supplied dynamic buffer sequence has been written. 1250 * 1251 * @li An error occurred. 1252 * 1253 * This operation is implemented in terms of zero or more calls to the stream's 1254 * async_write_some function, and is known as a <em>composed operation</em>. The 1255 * program must ensure that the stream performs no other write operations (such 1256 * as async_write, the stream's async_write_some function, or any other composed 1257 * operations that perform writes) until this operation completes. 1258 * 1259 * @param s The stream to which the data is to be written. The type must support 1260 * the AsyncWriteStream concept. 1261 * 1262 * @param buffers The dynamic buffer sequence from which data will be written. 1263 * Although the buffers object may be copied as necessary, ownership of the 1264 * underlying memory blocks is retained by the caller, which must guarantee 1265 * that they remain valid until the completion handler is called. Successfully 1266 * written data is automatically consumed from the buffers. 1267 * 1268 * @param token The @ref completion_token that will be used to produce a 1269 * completion handler, which will be called when the write completes. 1270 * Potential completion tokens include @ref use_future, @ref use_awaitable, 1271 * @ref yield_context, or a function object with the correct completion 1272 * signature. The function signature of the completion handler must be: 1273 * @code void handler( 1274 * // Result of operation. 1275 * const boost::system::error_code& error, 1276 * 1277 * // Number of bytes written from the buffers. If an error 1278 * // occurred, this will be less than the sum of the buffer sizes. 1279 * std::size_t bytes_transferred 1280 * ); @endcode 1281 * Regardless of whether the asynchronous operation completes immediately or 1282 * not, the completion handler will not be invoked from within this function. 1283 * On immediate completion, invocation of the handler will be performed in a 1284 * manner equivalent to using boost::asio::post(). 1285 * 1286 * @par Completion Signature 1287 * @code void(boost::system::error_code, std::size_t) @endcode 1288 * 1289 * @par Per-Operation Cancellation 1290 * This asynchronous operation supports cancellation for the following 1291 * boost::asio::cancellation_type values: 1292 * 1293 * @li @c cancellation_type::terminal 1294 * 1295 * @li @c cancellation_type::partial 1296 * 1297 * if they are also supported by the @c AsyncWriteStream type's 1298 * @c async_write_some operation. 1299 */ 1300 template <typename AsyncWriteStream, typename DynamicBuffer_v2, 1301 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1302 std::size_t)) WriteToken 1303 = default_completion_token_t<typename AsyncWriteStream::executor_type>> 1304 auto async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers, 1305 WriteToken&& token 1306 = default_completion_token_t<typename AsyncWriteStream::executor_type>(), 1307 constraint_t< 1308 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 1309 > = 0) 1310 -> decltype( 1311 async_initiate<WriteToken, 1312 void (boost::system::error_code, std::size_t)>( 1313 declval<detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>>(), 1314 token, static_cast<DynamicBuffer_v2&&>(buffers), 1315 transfer_all())); 1316 1317 /// Start an asynchronous operation to write a certain amount of data to a 1318 /// stream. 1319 /** 1320 * This function is used to asynchronously write a certain number of bytes of 1321 * data to a stream. It is an initiating function for an @ref 1322 * asynchronous_operation, and always returns immediately. The asynchronous 1323 * operation will continue until one of the following conditions is true: 1324 * 1325 * @li All of the data in the supplied dynamic buffer sequence has been written. 1326 * 1327 * @li The completion_condition function object returns 0. 1328 * 1329 * This operation is implemented in terms of zero or more calls to the stream's 1330 * async_write_some function, and is known as a <em>composed operation</em>. The 1331 * program must ensure that the stream performs no other write operations (such 1332 * as async_write, the stream's async_write_some function, or any other composed 1333 * operations that perform writes) until this operation completes. 1334 * 1335 * @param s The stream to which the data is to be written. The type must support 1336 * the AsyncWriteStream concept. 1337 * 1338 * @param buffers The dynamic buffer sequence from which data will be written. 1339 * Although the buffers object may be copied as necessary, ownership of the 1340 * underlying memory blocks is retained by the caller, which must guarantee 1341 * that they remain valid until the completion handler is called. Successfully 1342 * written data is automatically consumed from the buffers. 1343 * 1344 * @param completion_condition The function object to be called to determine 1345 * whether the write operation is complete. The signature of the function object 1346 * must be: 1347 * @code std::size_t completion_condition( 1348 * // Result of latest async_write_some operation. 1349 * const boost::system::error_code& error, 1350 * 1351 * // Number of bytes transferred so far. 1352 * std::size_t bytes_transferred 1353 * ); @endcode 1354 * A return value of 0 indicates that the write operation is complete. A 1355 * non-zero return value indicates the maximum number of bytes to be written on 1356 * the next call to the stream's async_write_some function. 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::post(). 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, 1391 typename DynamicBuffer_v2, typename CompletionCondition, 1392 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, 1393 std::size_t)) WriteToken> 1394 auto async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers, 1395 CompletionCondition completion_condition, 1396 WriteToken&& token, 1397 constraint_t< 1398 is_dynamic_buffer_v2<DynamicBuffer_v2>::value 1399 > = 0) 1400 -> decltype( 1401 async_initiate<WriteToken, 1402 void (boost::system::error_code, std::size_t)>( 1403 declval<detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>>(), 1404 token, static_cast<DynamicBuffer_v2&&>(buffers), 1405 static_cast<CompletionCondition&&>(completion_condition))); 1406 1407 /*@}*/ 1408 1409 } // namespace asio 1410 } // namespace boost 1411 1412 #include <boost/asio/detail/pop_options.hpp> 1413 1414 #include <boost/asio/impl/write.hpp> 1415 1416 #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 |