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