annotate DEPENDENCIES/generic/include/boost/asio/write.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // write.hpp
Chris@16 3 // ~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_WRITE_HPP
Chris@16 12 #define BOOST_ASIO_WRITE_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19 #include <cstddef>
Chris@16 20 #include <boost/asio/async_result.hpp>
Chris@16 21 #include <boost/asio/basic_streambuf_fwd.hpp>
Chris@16 22 #include <boost/asio/error.hpp>
Chris@16 23
Chris@16 24 #include <boost/asio/detail/push_options.hpp>
Chris@16 25
Chris@16 26 namespace boost {
Chris@16 27 namespace asio {
Chris@16 28
Chris@16 29 /**
Chris@16 30 * @defgroup write boost::asio::write
Chris@16 31 *
Chris@16 32 * @brief Write a certain amount of data to a stream before returning.
Chris@16 33 */
Chris@16 34 /*@{*/
Chris@16 35
Chris@16 36 /// Write all of the supplied data to a stream before returning.
Chris@16 37 /**
Chris@16 38 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 39 * The call will block until one of the following conditions is true:
Chris@16 40 *
Chris@16 41 * @li All of the data in the supplied buffers has been written. That is, the
Chris@16 42 * bytes transferred is equal to the sum of the buffer sizes.
Chris@16 43 *
Chris@16 44 * @li An error occurred.
Chris@16 45 *
Chris@16 46 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 47 * write_some function.
Chris@16 48 *
Chris@16 49 * @param s The stream to which the data is to be written. The type must support
Chris@16 50 * the SyncWriteStream concept.
Chris@16 51 *
Chris@16 52 * @param buffers One or more buffers containing the data to be written. The sum
Chris@16 53 * of the buffer sizes indicates the maximum number of bytes to write to the
Chris@16 54 * stream.
Chris@16 55 *
Chris@16 56 * @returns The number of bytes transferred.
Chris@16 57 *
Chris@16 58 * @throws boost::system::system_error Thrown on failure.
Chris@16 59 *
Chris@16 60 * @par Example
Chris@16 61 * To write a single data buffer use the @ref buffer function as follows:
Chris@16 62 * @code boost::asio::write(s, boost::asio::buffer(data, size)); @endcode
Chris@16 63 * See the @ref buffer documentation for information on writing multiple
Chris@16 64 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 65 * std::vector.
Chris@16 66 *
Chris@16 67 * @note This overload is equivalent to calling:
Chris@16 68 * @code boost::asio::write(
Chris@16 69 * s, buffers,
Chris@16 70 * boost::asio::transfer_all()); @endcode
Chris@16 71 */
Chris@16 72 template <typename SyncWriteStream, typename ConstBufferSequence>
Chris@16 73 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers);
Chris@16 74
Chris@16 75 /// Write all of the supplied data to a stream before returning.
Chris@16 76 /**
Chris@16 77 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 78 * The call will block until one of the following conditions is true:
Chris@16 79 *
Chris@16 80 * @li All of the data in the supplied buffers has been written. That is, the
Chris@16 81 * bytes transferred is equal to the sum of the buffer sizes.
Chris@16 82 *
Chris@16 83 * @li An error occurred.
Chris@16 84 *
Chris@16 85 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 86 * write_some function.
Chris@16 87 *
Chris@16 88 * @param s The stream to which the data is to be written. The type must support
Chris@16 89 * the SyncWriteStream concept.
Chris@16 90 *
Chris@16 91 * @param buffers One or more buffers containing the data to be written. The sum
Chris@16 92 * of the buffer sizes indicates the maximum number of bytes to write to the
Chris@16 93 * stream.
Chris@16 94 *
Chris@16 95 * @param ec Set to indicate what error occurred, if any.
Chris@16 96 *
Chris@16 97 * @returns The number of bytes transferred.
Chris@16 98 *
Chris@16 99 * @par Example
Chris@16 100 * To write a single data buffer use the @ref buffer function as follows:
Chris@16 101 * @code boost::asio::write(s, boost::asio::buffer(data, size), ec); @endcode
Chris@16 102 * See the @ref buffer documentation for information on writing multiple
Chris@16 103 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 104 * std::vector.
Chris@16 105 *
Chris@16 106 * @note This overload is equivalent to calling:
Chris@16 107 * @code boost::asio::write(
Chris@16 108 * s, buffers,
Chris@16 109 * boost::asio::transfer_all(), ec); @endcode
Chris@16 110 */
Chris@16 111 template <typename SyncWriteStream, typename ConstBufferSequence>
Chris@16 112 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
Chris@16 113 boost::system::error_code& ec);
Chris@16 114
Chris@16 115 /// Write a certain amount of data to a stream before returning.
Chris@16 116 /**
Chris@16 117 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 118 * The call will block until one of the following conditions is true:
Chris@16 119 *
Chris@16 120 * @li All of the data in the supplied buffers has been written. That is, the
Chris@16 121 * bytes transferred is equal to the sum of the buffer sizes.
Chris@16 122 *
Chris@16 123 * @li The completion_condition function object returns 0.
Chris@16 124 *
Chris@16 125 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 126 * write_some function.
Chris@16 127 *
Chris@16 128 * @param s The stream to which the data is to be written. The type must support
Chris@16 129 * the SyncWriteStream concept.
Chris@16 130 *
Chris@16 131 * @param buffers One or more buffers containing the data to be written. The sum
Chris@16 132 * of the buffer sizes indicates the maximum number of bytes to write to the
Chris@16 133 * stream.
Chris@16 134 *
Chris@16 135 * @param completion_condition The function object to be called to determine
Chris@16 136 * whether the write operation is complete. The signature of the function object
Chris@16 137 * must be:
Chris@16 138 * @code std::size_t completion_condition(
Chris@16 139 * // Result of latest write_some operation.
Chris@16 140 * const boost::system::error_code& error,
Chris@16 141 *
Chris@16 142 * // Number of bytes transferred so far.
Chris@16 143 * std::size_t bytes_transferred
Chris@16 144 * ); @endcode
Chris@16 145 * A return value of 0 indicates that the write operation is complete. A
Chris@16 146 * non-zero return value indicates the maximum number of bytes to be written on
Chris@16 147 * the next call to the stream's write_some function.
Chris@16 148 *
Chris@16 149 * @returns The number of bytes transferred.
Chris@16 150 *
Chris@16 151 * @throws boost::system::system_error Thrown on failure.
Chris@16 152 *
Chris@16 153 * @par Example
Chris@16 154 * To write a single data buffer use the @ref buffer function as follows:
Chris@16 155 * @code boost::asio::write(s, boost::asio::buffer(data, size),
Chris@16 156 * boost::asio::transfer_at_least(32)); @endcode
Chris@16 157 * See the @ref buffer documentation for information on writing multiple
Chris@16 158 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 159 * std::vector.
Chris@16 160 */
Chris@16 161 template <typename SyncWriteStream, typename ConstBufferSequence,
Chris@16 162 typename CompletionCondition>
Chris@16 163 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
Chris@16 164 CompletionCondition completion_condition);
Chris@16 165
Chris@16 166 /// Write a certain amount of data to a stream before returning.
Chris@16 167 /**
Chris@16 168 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 169 * The call will block until one of the following conditions is true:
Chris@16 170 *
Chris@16 171 * @li All of the data in the supplied buffers has been written. That is, the
Chris@16 172 * bytes transferred is equal to the sum of the buffer sizes.
Chris@16 173 *
Chris@16 174 * @li The completion_condition function object returns 0.
Chris@16 175 *
Chris@16 176 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 177 * write_some function.
Chris@16 178 *
Chris@16 179 * @param s The stream to which the data is to be written. The type must support
Chris@16 180 * the SyncWriteStream concept.
Chris@16 181 *
Chris@16 182 * @param buffers One or more buffers containing the data to be written. The sum
Chris@16 183 * of the buffer sizes indicates the maximum number of bytes to write to the
Chris@16 184 * stream.
Chris@16 185 *
Chris@16 186 * @param completion_condition The function object to be called to determine
Chris@16 187 * whether the write operation is complete. The signature of the function object
Chris@16 188 * must be:
Chris@16 189 * @code std::size_t completion_condition(
Chris@16 190 * // Result of latest write_some operation.
Chris@16 191 * const boost::system::error_code& error,
Chris@16 192 *
Chris@16 193 * // Number of bytes transferred so far.
Chris@16 194 * std::size_t bytes_transferred
Chris@16 195 * ); @endcode
Chris@16 196 * A return value of 0 indicates that the write operation is complete. A
Chris@16 197 * non-zero return value indicates the maximum number of bytes to be written on
Chris@16 198 * the next call to the stream's write_some function.
Chris@16 199 *
Chris@16 200 * @param ec Set to indicate what error occurred, if any.
Chris@16 201 *
Chris@16 202 * @returns The number of bytes written. If an error occurs, returns the total
Chris@16 203 * number of bytes successfully transferred prior to the error.
Chris@16 204 */
Chris@16 205 template <typename SyncWriteStream, typename ConstBufferSequence,
Chris@16 206 typename CompletionCondition>
Chris@16 207 std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
Chris@16 208 CompletionCondition completion_condition, boost::system::error_code& ec);
Chris@16 209
Chris@16 210 #if !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 211
Chris@16 212 /// Write all of the supplied data to a stream before returning.
Chris@16 213 /**
Chris@16 214 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 215 * The call will block until one of the following conditions is true:
Chris@16 216 *
Chris@16 217 * @li All of the data in the supplied basic_streambuf has been written.
Chris@16 218 *
Chris@16 219 * @li An error occurred.
Chris@16 220 *
Chris@16 221 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 222 * write_some function.
Chris@16 223 *
Chris@16 224 * @param s The stream to which the data is to be written. The type must support
Chris@16 225 * the SyncWriteStream concept.
Chris@16 226 *
Chris@16 227 * @param b The basic_streambuf object from which data will be written.
Chris@16 228 *
Chris@16 229 * @returns The number of bytes transferred.
Chris@16 230 *
Chris@16 231 * @throws boost::system::system_error Thrown on failure.
Chris@16 232 *
Chris@16 233 * @note This overload is equivalent to calling:
Chris@16 234 * @code boost::asio::write(
Chris@16 235 * s, b,
Chris@16 236 * boost::asio::transfer_all()); @endcode
Chris@16 237 */
Chris@16 238 template <typename SyncWriteStream, typename Allocator>
Chris@16 239 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b);
Chris@16 240
Chris@16 241 /// Write all of the supplied data to a stream before returning.
Chris@16 242 /**
Chris@16 243 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 244 * The call will block until one of the following conditions is true:
Chris@16 245 *
Chris@16 246 * @li All of the data in the supplied basic_streambuf has been written.
Chris@16 247 *
Chris@16 248 * @li An error occurred.
Chris@16 249 *
Chris@16 250 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 251 * write_some function.
Chris@16 252 *
Chris@16 253 * @param s The stream to which the data is to be written. The type must support
Chris@16 254 * the SyncWriteStream concept.
Chris@16 255 *
Chris@16 256 * @param b The basic_streambuf object from which data will be written.
Chris@16 257 *
Chris@16 258 * @param ec Set to indicate what error occurred, if any.
Chris@16 259 *
Chris@16 260 * @returns The number of bytes transferred.
Chris@16 261 *
Chris@16 262 * @note This overload is equivalent to calling:
Chris@16 263 * @code boost::asio::write(
Chris@16 264 * s, b,
Chris@16 265 * boost::asio::transfer_all(), ec); @endcode
Chris@16 266 */
Chris@16 267 template <typename SyncWriteStream, typename Allocator>
Chris@16 268 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
Chris@16 269 boost::system::error_code& ec);
Chris@16 270
Chris@16 271 /// Write a certain amount of data to a stream before returning.
Chris@16 272 /**
Chris@16 273 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 274 * The call will block until one of the following conditions is true:
Chris@16 275 *
Chris@16 276 * @li All of the data in the supplied basic_streambuf has been written.
Chris@16 277 *
Chris@16 278 * @li The completion_condition function object returns 0.
Chris@16 279 *
Chris@16 280 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 281 * write_some function.
Chris@16 282 *
Chris@16 283 * @param s The stream to which the data is to be written. The type must support
Chris@16 284 * the SyncWriteStream concept.
Chris@16 285 *
Chris@16 286 * @param b The basic_streambuf object from which data will be written.
Chris@16 287 *
Chris@16 288 * @param completion_condition The function object to be called to determine
Chris@16 289 * whether the write operation is complete. The signature of the function object
Chris@16 290 * must be:
Chris@16 291 * @code std::size_t completion_condition(
Chris@16 292 * // Result of latest write_some operation.
Chris@16 293 * const boost::system::error_code& error,
Chris@16 294 *
Chris@16 295 * // Number of bytes transferred so far.
Chris@16 296 * std::size_t bytes_transferred
Chris@16 297 * ); @endcode
Chris@16 298 * A return value of 0 indicates that the write operation is complete. A
Chris@16 299 * non-zero return value indicates the maximum number of bytes to be written on
Chris@16 300 * the next call to the stream's write_some function.
Chris@16 301 *
Chris@16 302 * @returns The number of bytes transferred.
Chris@16 303 *
Chris@16 304 * @throws boost::system::system_error Thrown on failure.
Chris@16 305 */
Chris@16 306 template <typename SyncWriteStream, typename Allocator,
Chris@16 307 typename CompletionCondition>
Chris@16 308 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
Chris@16 309 CompletionCondition completion_condition);
Chris@16 310
Chris@16 311 /// Write a certain amount of data to a stream before returning.
Chris@16 312 /**
Chris@16 313 * This function is used to write a certain number of bytes of data to a stream.
Chris@16 314 * The call will block until one of the following conditions is true:
Chris@16 315 *
Chris@16 316 * @li All of the data in the supplied basic_streambuf has been written.
Chris@16 317 *
Chris@16 318 * @li The completion_condition function object returns 0.
Chris@16 319 *
Chris@16 320 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 321 * write_some function.
Chris@16 322 *
Chris@16 323 * @param s The stream to which the data is to be written. The type must support
Chris@16 324 * the SyncWriteStream concept.
Chris@16 325 *
Chris@16 326 * @param b The basic_streambuf object from which data will be written.
Chris@16 327 *
Chris@16 328 * @param completion_condition The function object to be called to determine
Chris@16 329 * whether the write operation is complete. The signature of the function object
Chris@16 330 * must be:
Chris@16 331 * @code std::size_t completion_condition(
Chris@16 332 * // Result of latest write_some operation.
Chris@16 333 * const boost::system::error_code& error,
Chris@16 334 *
Chris@16 335 * // Number of bytes transferred so far.
Chris@16 336 * std::size_t bytes_transferred
Chris@16 337 * ); @endcode
Chris@16 338 * A return value of 0 indicates that the write operation is complete. A
Chris@16 339 * non-zero return value indicates the maximum number of bytes to be written on
Chris@16 340 * the next call to the stream's write_some function.
Chris@16 341 *
Chris@16 342 * @param ec Set to indicate what error occurred, if any.
Chris@16 343 *
Chris@16 344 * @returns The number of bytes written. If an error occurs, returns the total
Chris@16 345 * number of bytes successfully transferred prior to the error.
Chris@16 346 */
Chris@16 347 template <typename SyncWriteStream, typename Allocator,
Chris@16 348 typename CompletionCondition>
Chris@16 349 std::size_t write(SyncWriteStream& s, basic_streambuf<Allocator>& b,
Chris@16 350 CompletionCondition completion_condition, boost::system::error_code& ec);
Chris@16 351
Chris@16 352 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 353
Chris@16 354 /*@}*/
Chris@16 355 /**
Chris@16 356 * @defgroup async_write boost::asio::async_write
Chris@16 357 *
Chris@16 358 * @brief Start an asynchronous operation to write a certain amount of data to a
Chris@16 359 * stream.
Chris@16 360 */
Chris@16 361 /*@{*/
Chris@16 362
Chris@16 363 /// Start an asynchronous operation to write all of the supplied data to a
Chris@16 364 /// stream.
Chris@16 365 /**
Chris@16 366 * This function is used to asynchronously write a certain number of bytes of
Chris@16 367 * data to a stream. The function call always returns immediately. The
Chris@16 368 * asynchronous operation will continue until one of the following conditions
Chris@16 369 * is true:
Chris@16 370 *
Chris@16 371 * @li All of the data in the supplied buffers has been written. That is, the
Chris@16 372 * bytes transferred is equal to the sum of the buffer sizes.
Chris@16 373 *
Chris@16 374 * @li An error occurred.
Chris@16 375 *
Chris@16 376 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 377 * async_write_some function, and is known as a <em>composed operation</em>. The
Chris@16 378 * program must ensure that the stream performs no other write operations (such
Chris@16 379 * as async_write, the stream's async_write_some function, or any other composed
Chris@16 380 * operations that perform writes) until this operation completes.
Chris@16 381 *
Chris@16 382 * @param s The stream to which the data is to be written. The type must support
Chris@16 383 * the AsyncWriteStream concept.
Chris@16 384 *
Chris@16 385 * @param buffers One or more buffers containing the data to be written.
Chris@16 386 * Although the buffers object may be copied as necessary, ownership of the
Chris@16 387 * underlying memory blocks is retained by the caller, which must guarantee
Chris@16 388 * that they remain valid until the handler is called.
Chris@16 389 *
Chris@16 390 * @param handler The handler to be called when the write operation completes.
Chris@16 391 * Copies will be made of the handler as required. The function signature of
Chris@16 392 * the handler must be:
Chris@16 393 * @code void handler(
Chris@16 394 * const boost::system::error_code& error, // Result of operation.
Chris@16 395 *
Chris@16 396 * std::size_t bytes_transferred // Number of bytes written from the
Chris@16 397 * // buffers. If an error occurred,
Chris@16 398 * // this will be less than the sum
Chris@16 399 * // of the buffer sizes.
Chris@16 400 * ); @endcode
Chris@16 401 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 402 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 403 * the handler will be performed in a manner equivalent to using
Chris@16 404 * boost::asio::io_service::post().
Chris@16 405 *
Chris@16 406 * @par Example
Chris@16 407 * To write a single data buffer use the @ref buffer function as follows:
Chris@16 408 * @code
Chris@16 409 * boost::asio::async_write(s, boost::asio::buffer(data, size), handler);
Chris@16 410 * @endcode
Chris@16 411 * See the @ref buffer documentation for information on writing multiple
Chris@16 412 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 413 * std::vector.
Chris@16 414 */
Chris@16 415 template <typename AsyncWriteStream, typename ConstBufferSequence,
Chris@16 416 typename WriteHandler>
Chris@16 417 BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
Chris@16 418 void (boost::system::error_code, std::size_t))
Chris@16 419 async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
Chris@16 420 BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
Chris@16 421
Chris@16 422 /// Start an asynchronous operation to write a certain amount of data to a
Chris@16 423 /// stream.
Chris@16 424 /**
Chris@16 425 * This function is used to asynchronously write a certain number of bytes of
Chris@16 426 * data to a stream. The function call always returns immediately. The
Chris@16 427 * asynchronous operation will continue until one of the following conditions
Chris@16 428 * is true:
Chris@16 429 *
Chris@16 430 * @li All of the data in the supplied buffers has been written. That is, the
Chris@16 431 * bytes transferred is equal to the sum of the buffer sizes.
Chris@16 432 *
Chris@16 433 * @li The completion_condition function object returns 0.
Chris@16 434 *
Chris@16 435 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 436 * async_write_some function, and is known as a <em>composed operation</em>. The
Chris@16 437 * program must ensure that the stream performs no other write operations (such
Chris@16 438 * as async_write, the stream's async_write_some function, or any other composed
Chris@16 439 * operations that perform writes) until this operation completes.
Chris@16 440 *
Chris@16 441 * @param s The stream to which the data is to be written. The type must support
Chris@16 442 * the AsyncWriteStream concept.
Chris@16 443 *
Chris@16 444 * @param buffers One or more buffers containing the data to be written.
Chris@16 445 * Although the buffers object may be copied as necessary, ownership of the
Chris@16 446 * underlying memory blocks is retained by the caller, which must guarantee
Chris@16 447 * that they remain valid until the handler is called.
Chris@16 448 *
Chris@16 449 * @param completion_condition The function object to be called to determine
Chris@16 450 * whether the write operation is complete. The signature of the function object
Chris@16 451 * must be:
Chris@16 452 * @code std::size_t completion_condition(
Chris@16 453 * // Result of latest async_write_some operation.
Chris@16 454 * const boost::system::error_code& error,
Chris@16 455 *
Chris@16 456 * // Number of bytes transferred so far.
Chris@16 457 * std::size_t bytes_transferred
Chris@16 458 * ); @endcode
Chris@16 459 * A return value of 0 indicates that the write operation is complete. A
Chris@16 460 * non-zero return value indicates the maximum number of bytes to be written on
Chris@16 461 * the next call to the stream's async_write_some function.
Chris@16 462 *
Chris@16 463 * @param handler The handler to be called when the write operation completes.
Chris@16 464 * Copies will be made of the handler as required. The function signature of the
Chris@16 465 * handler must be:
Chris@16 466 * @code void handler(
Chris@16 467 * const boost::system::error_code& error, // Result of operation.
Chris@16 468 *
Chris@16 469 * std::size_t bytes_transferred // Number of bytes written from the
Chris@16 470 * // buffers. If an error occurred,
Chris@16 471 * // this will be less than the sum
Chris@16 472 * // of the buffer sizes.
Chris@16 473 * ); @endcode
Chris@16 474 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 475 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 476 * the handler will be performed in a manner equivalent to using
Chris@16 477 * boost::asio::io_service::post().
Chris@16 478 *
Chris@16 479 * @par Example
Chris@16 480 * To write a single data buffer use the @ref buffer function as follows:
Chris@16 481 * @code boost::asio::async_write(s,
Chris@16 482 * boost::asio::buffer(data, size),
Chris@16 483 * boost::asio::transfer_at_least(32),
Chris@16 484 * handler); @endcode
Chris@16 485 * See the @ref buffer documentation for information on writing multiple
Chris@16 486 * buffers in one go, and how to use it with arrays, boost::array or
Chris@16 487 * std::vector.
Chris@16 488 */
Chris@16 489 template <typename AsyncWriteStream, typename ConstBufferSequence,
Chris@16 490 typename CompletionCondition, typename WriteHandler>
Chris@16 491 BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
Chris@16 492 void (boost::system::error_code, std::size_t))
Chris@16 493 async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
Chris@16 494 CompletionCondition completion_condition,
Chris@16 495 BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
Chris@16 496
Chris@16 497 #if !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 498
Chris@16 499 /// Start an asynchronous operation to write all of the supplied data to a
Chris@16 500 /// stream.
Chris@16 501 /**
Chris@16 502 * This function is used to asynchronously write a certain number of bytes of
Chris@16 503 * data to a stream. The function call always returns immediately. The
Chris@16 504 * asynchronous operation will continue until one of the following conditions
Chris@16 505 * is true:
Chris@16 506 *
Chris@16 507 * @li All of the data in the supplied basic_streambuf has been written.
Chris@16 508 *
Chris@16 509 * @li An error occurred.
Chris@16 510 *
Chris@16 511 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 512 * async_write_some function, and is known as a <em>composed operation</em>. The
Chris@16 513 * program must ensure that the stream performs no other write operations (such
Chris@16 514 * as async_write, the stream's async_write_some function, or any other composed
Chris@16 515 * operations that perform writes) until this operation completes.
Chris@16 516 *
Chris@16 517 * @param s The stream to which the data is to be written. The type must support
Chris@16 518 * the AsyncWriteStream concept.
Chris@16 519 *
Chris@16 520 * @param b A basic_streambuf object from which data will be written. Ownership
Chris@16 521 * of the streambuf is retained by the caller, which must guarantee that it
Chris@16 522 * remains valid until the handler is called.
Chris@16 523 *
Chris@16 524 * @param handler The handler to be called when the write operation completes.
Chris@16 525 * Copies will be made of the handler as required. The function signature of the
Chris@16 526 * handler must be:
Chris@16 527 * @code void handler(
Chris@16 528 * const boost::system::error_code& error, // Result of operation.
Chris@16 529 *
Chris@16 530 * std::size_t bytes_transferred // Number of bytes written from the
Chris@16 531 * // buffers. If an error occurred,
Chris@16 532 * // this will be less than the sum
Chris@16 533 * // of the buffer sizes.
Chris@16 534 * ); @endcode
Chris@16 535 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 536 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 537 * the handler will be performed in a manner equivalent to using
Chris@16 538 * boost::asio::io_service::post().
Chris@16 539 */
Chris@16 540 template <typename AsyncWriteStream, typename Allocator, typename WriteHandler>
Chris@16 541 BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
Chris@16 542 void (boost::system::error_code, std::size_t))
Chris@16 543 async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
Chris@16 544 BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
Chris@16 545
Chris@16 546 /// Start an asynchronous operation to write a certain amount of data to a
Chris@16 547 /// stream.
Chris@16 548 /**
Chris@16 549 * This function is used to asynchronously write a certain number of bytes of
Chris@16 550 * data to a stream. The function call always returns immediately. The
Chris@16 551 * asynchronous operation will continue until one of the following conditions
Chris@16 552 * is true:
Chris@16 553 *
Chris@16 554 * @li All of the data in the supplied basic_streambuf has been written.
Chris@16 555 *
Chris@16 556 * @li The completion_condition function object returns 0.
Chris@16 557 *
Chris@16 558 * This operation is implemented in terms of zero or more calls to the stream's
Chris@16 559 * async_write_some function, and is known as a <em>composed operation</em>. The
Chris@16 560 * program must ensure that the stream performs no other write operations (such
Chris@16 561 * as async_write, the stream's async_write_some function, or any other composed
Chris@16 562 * operations that perform writes) until this operation completes.
Chris@16 563 *
Chris@16 564 * @param s The stream to which the data is to be written. The type must support
Chris@16 565 * the AsyncWriteStream concept.
Chris@16 566 *
Chris@16 567 * @param b A basic_streambuf object from which data will be written. Ownership
Chris@16 568 * of the streambuf is retained by the caller, which must guarantee that it
Chris@16 569 * remains valid until the handler is called.
Chris@16 570 *
Chris@16 571 * @param completion_condition The function object to be called to determine
Chris@16 572 * whether the write operation is complete. The signature of the function object
Chris@16 573 * must be:
Chris@16 574 * @code std::size_t completion_condition(
Chris@16 575 * // Result of latest async_write_some operation.
Chris@16 576 * const boost::system::error_code& error,
Chris@16 577 *
Chris@16 578 * // Number of bytes transferred so far.
Chris@16 579 * std::size_t bytes_transferred
Chris@16 580 * ); @endcode
Chris@16 581 * A return value of 0 indicates that the write operation is complete. A
Chris@16 582 * non-zero return value indicates the maximum number of bytes to be written on
Chris@16 583 * the next call to the stream's async_write_some function.
Chris@16 584 *
Chris@16 585 * @param handler The handler to be called when the write operation completes.
Chris@16 586 * Copies will be made of the handler as required. The function signature of the
Chris@16 587 * handler must be:
Chris@16 588 * @code void handler(
Chris@16 589 * const boost::system::error_code& error, // Result of operation.
Chris@16 590 *
Chris@16 591 * std::size_t bytes_transferred // Number of bytes written from the
Chris@16 592 * // buffers. If an error occurred,
Chris@16 593 * // this will be less than the sum
Chris@16 594 * // of the buffer sizes.
Chris@16 595 * ); @endcode
Chris@16 596 * Regardless of whether the asynchronous operation completes immediately or
Chris@16 597 * not, the handler will not be invoked from within this function. Invocation of
Chris@16 598 * the handler will be performed in a manner equivalent to using
Chris@16 599 * boost::asio::io_service::post().
Chris@16 600 */
Chris@16 601 template <typename AsyncWriteStream, typename Allocator,
Chris@16 602 typename CompletionCondition, typename WriteHandler>
Chris@16 603 BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
Chris@16 604 void (boost::system::error_code, std::size_t))
Chris@16 605 async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b,
Chris@16 606 CompletionCondition completion_condition,
Chris@16 607 BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
Chris@16 608
Chris@16 609 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 610
Chris@16 611 /*@}*/
Chris@16 612
Chris@16 613 } // namespace asio
Chris@16 614 } // namespace boost
Chris@16 615
Chris@16 616 #include <boost/asio/detail/pop_options.hpp>
Chris@16 617
Chris@16 618 #include <boost/asio/impl/write.hpp>
Chris@16 619
Chris@16 620 #endif // BOOST_ASIO_WRITE_HPP