Chris@16: // Chris@16: // read.hpp Chris@16: // ~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_READ_HPP Chris@16: #define BOOST_ASIO_READ_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /** Chris@16: * @defgroup read boost::asio::read Chris@16: * Chris@16: * @brief Attempt to read a certain amount of data from a stream before Chris@16: * returning. Chris@16: */ Chris@16: /*@{*/ Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffers are full. That is, the bytes transferred is equal to Chris@16: * the sum of the buffer sizes. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param buffers One or more buffers into which the data will be read. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to read from the Chris@16: * stream. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: * Chris@16: * @par Example Chris@16: * To read into a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::read(s, boost::asio::buffer(data, size)); @endcode Chris@16: * See the @ref buffer documentation for information on reading into multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::read( Chris@16: * s, buffers, Chris@16: * boost::asio::transfer_all()); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers); Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffers are full. That is, the bytes transferred is equal to Chris@16: * the sum of the buffer sizes. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param buffers One or more buffers into which the data will be read. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to read from the Chris@16: * stream. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @par Example Chris@16: * To read into a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::read(s, boost::asio::buffer(data, size), ec); @endcode Chris@16: * See the @ref buffer documentation for information on reading into multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::read( Chris@16: * s, buffers, Chris@16: * boost::asio::transfer_all(), ec); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffers are full. That is, the bytes transferred is equal to Chris@16: * the sum of the buffer sizes. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param buffers One or more buffers into which the data will be read. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to read from the Chris@16: * stream. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the read operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest read_some operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the read operation is complete. A non-zero Chris@16: * return value indicates the maximum number of bytes to be read on the next Chris@16: * call to the stream's read_some function. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: * Chris@16: * @par Example Chris@16: * To read into a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::read(s, boost::asio::buffer(data, size), Chris@16: * boost::asio::transfer_at_least(32)); @endcode Chris@16: * See the @ref buffer documentation for information on reading into multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, Chris@16: CompletionCondition completion_condition); Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffers are full. That is, the bytes transferred is equal to Chris@16: * the sum of the buffer sizes. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param buffers One or more buffers into which the data will be read. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to read from the Chris@16: * stream. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the read operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest read_some operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the read operation is complete. A non-zero Chris@16: * return value indicates the maximum number of bytes to be read on the next Chris@16: * call to the stream's read_some function. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes read. If an error occurs, returns the total Chris@16: * number of bytes successfully transferred prior to the error. Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, Chris@16: CompletionCondition completion_condition, boost::system::error_code& ec); Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffer is full (that is, it has reached maximum size). Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param b The basic_streambuf object into which the data will be read. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::read( Chris@16: * s, b, Chris@16: * boost::asio::transfer_all()); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, basic_streambuf& b); Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffer is full (that is, it has reached maximum size). Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param b The basic_streambuf object into which the data will be read. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::read( Chris@16: * s, b, Chris@16: * boost::asio::transfer_all(), ec); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, basic_streambuf& b, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffer is full (that is, it has reached maximum size). Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param b The basic_streambuf object into which the data will be read. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the read operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest read_some operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the read operation is complete. A non-zero Chris@16: * return value indicates the maximum number of bytes to be read on the next Chris@16: * call to the stream's read_some function. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, basic_streambuf& b, Chris@16: CompletionCondition completion_condition); Chris@16: Chris@16: /// Attempt to read a certain amount of data from a stream before returning. Chris@16: /** Chris@16: * This function is used to read a certain number of bytes of data from a Chris@16: * stream. The call will block until one of the following conditions is true: Chris@16: * Chris@16: * @li The supplied buffer is full (that is, it has reached maximum size). Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * read_some function. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the SyncReadStream concept. Chris@16: * Chris@16: * @param b The basic_streambuf object into which the data will be read. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the read operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest read_some operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the read operation is complete. A non-zero Chris@16: * return value indicates the maximum number of bytes to be read on the next Chris@16: * call to the stream's read_some function. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes read. If an error occurs, returns the total Chris@16: * number of bytes successfully transferred prior to the error. Chris@16: */ Chris@16: template Chris@16: std::size_t read(SyncReadStream& s, basic_streambuf& b, Chris@16: CompletionCondition completion_condition, boost::system::error_code& ec); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /*@}*/ Chris@16: /** Chris@16: * @defgroup async_read boost::asio::async_read Chris@16: * Chris@16: * @brief Start an asynchronous operation to read a certain amount of data from Chris@16: * a stream. Chris@16: */ Chris@16: /*@{*/ Chris@16: Chris@16: /// Start an asynchronous operation to read a certain amount of data from a Chris@16: /// stream. Chris@16: /** Chris@16: * This function is used to asynchronously read a certain number of bytes of Chris@16: * data from a stream. The function call always returns immediately. The Chris@16: * asynchronous operation will continue until one of the following conditions is Chris@16: * true: Chris@16: * Chris@16: * @li The supplied buffers are full. That is, the bytes transferred is equal to Chris@16: * the sum of the buffer sizes. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * async_read_some function, and is known as a composed operation. The Chris@16: * program must ensure that the stream performs no other read operations (such Chris@16: * as async_read, the stream's async_read_some function, or any other composed Chris@16: * operations that perform reads) until this operation completes. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the AsyncReadStream concept. Chris@16: * Chris@16: * @param buffers One or more buffers into which the data will be read. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to read from the Chris@16: * stream. Although the buffers object may be copied as necessary, ownership of Chris@16: * the underlying memory blocks is retained by the caller, which must guarantee Chris@16: * that they remain valid until the handler is called. Chris@16: * Chris@16: * @param handler The handler to be called when the read operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * const boost::system::error_code& error, // Result of operation. Chris@16: * Chris@16: * std::size_t bytes_transferred // Number of bytes copied into the Chris@16: * // buffers. If an error occurred, Chris@16: * // this will be the number of Chris@16: * // bytes successfully transferred Chris@16: * // prior to the error. Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: * Chris@16: * @par Example Chris@16: * To read into a single data buffer use the @ref buffer function as follows: Chris@16: * @code Chris@16: * boost::asio::async_read(s, boost::asio::buffer(data, size), handler); Chris@16: * @endcode Chris@16: * See the @ref buffer documentation for information on reading into multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::async_read( Chris@16: * s, buffers, Chris@16: * boost::asio::transfer_all(), Chris@16: * handler); @endcode Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_read(AsyncReadStream& s, const MutableBufferSequence& buffers, Chris@16: BOOST_ASIO_MOVE_ARG(ReadHandler) handler); Chris@16: Chris@16: /// Start an asynchronous operation to read a certain amount of data from a Chris@16: /// stream. Chris@16: /** Chris@16: * This function is used to asynchronously read a certain number of bytes of Chris@16: * data from a stream. The function call always returns immediately. The Chris@16: * asynchronous operation will continue until one of the following conditions is Chris@16: * true: Chris@16: * Chris@16: * @li The supplied buffers are full. That is, the bytes transferred is equal to Chris@16: * the sum of the buffer sizes. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the AsyncReadStream concept. Chris@16: * Chris@16: * @param buffers One or more buffers into which the data will be read. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to read from the Chris@16: * stream. Although the buffers object may be copied as necessary, ownership of Chris@16: * the underlying memory blocks is retained by the caller, which must guarantee Chris@16: * that they remain valid until the handler is called. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the read operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest async_read_some operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the read operation is complete. A non-zero Chris@16: * return value indicates the maximum number of bytes to be read on the next Chris@16: * call to the stream's async_read_some function. Chris@16: * Chris@16: * @param handler The handler to be called when the read operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * const boost::system::error_code& error, // Result of operation. Chris@16: * Chris@16: * std::size_t bytes_transferred // Number of bytes copied into the Chris@16: * // buffers. If an error occurred, Chris@16: * // this will be the number of Chris@16: * // bytes successfully transferred Chris@16: * // prior to the error. Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: * Chris@16: * @par Example Chris@16: * To read into a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::async_read(s, Chris@16: * boost::asio::buffer(data, size), Chris@16: * boost::asio::transfer_at_least(32), Chris@16: * handler); @endcode Chris@16: * See the @ref buffer documentation for information on reading into multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_read(AsyncReadStream& s, const MutableBufferSequence& buffers, Chris@16: CompletionCondition completion_condition, Chris@16: BOOST_ASIO_MOVE_ARG(ReadHandler) handler); Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /// Start an asynchronous operation to read a certain amount of data from a Chris@16: /// stream. Chris@16: /** Chris@16: * This function is used to asynchronously read a certain number of bytes of Chris@16: * data from a stream. The function call always returns immediately. The Chris@16: * asynchronous operation will continue until one of the following conditions is Chris@16: * true: Chris@16: * Chris@16: * @li The supplied buffer is full (that is, it has reached maximum size). Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * async_read_some function, and is known as a composed operation. The Chris@16: * program must ensure that the stream performs no other read operations (such Chris@16: * as async_read, the stream's async_read_some function, or any other composed Chris@16: * operations that perform reads) until this operation completes. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the AsyncReadStream concept. Chris@16: * Chris@16: * @param b A basic_streambuf object into which the data will be read. Ownership Chris@16: * of the streambuf is retained by the caller, which must guarantee that it Chris@16: * remains valid until the handler is called. Chris@16: * Chris@16: * @param handler The handler to be called when the read operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * const boost::system::error_code& error, // Result of operation. Chris@16: * Chris@16: * std::size_t bytes_transferred // Number of bytes copied into the Chris@16: * // buffers. If an error occurred, Chris@16: * // this will be the number of Chris@16: * // bytes successfully transferred Chris@16: * // prior to the error. Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::async_read( Chris@16: * s, b, Chris@16: * boost::asio::transfer_all(), Chris@16: * handler); @endcode Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_read(AsyncReadStream& s, basic_streambuf& b, Chris@16: BOOST_ASIO_MOVE_ARG(ReadHandler) handler); Chris@16: Chris@16: /// Start an asynchronous operation to read a certain amount of data from a Chris@16: /// stream. Chris@16: /** Chris@16: * This function is used to asynchronously read a certain number of bytes of Chris@16: * data from a stream. The function call always returns immediately. The Chris@16: * asynchronous operation will continue until one of the following conditions is Chris@16: * true: Chris@16: * Chris@16: * @li The supplied buffer is full (that is, it has reached maximum size). Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the stream's Chris@16: * async_read_some function, and is known as a composed operation. The Chris@16: * program must ensure that the stream performs no other read operations (such Chris@16: * as async_read, the stream's async_read_some function, or any other composed Chris@16: * operations that perform reads) until this operation completes. Chris@16: * Chris@16: * @param s The stream from which the data is to be read. The type must support Chris@16: * the AsyncReadStream concept. Chris@16: * Chris@16: * @param b A basic_streambuf object into which the data will be read. Ownership Chris@16: * of the streambuf is retained by the caller, which must guarantee that it Chris@16: * remains valid until the handler is called. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the read operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest async_read_some operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the read operation is complete. A non-zero Chris@16: * return value indicates the maximum number of bytes to be read on the next Chris@16: * call to the stream's async_read_some function. Chris@16: * Chris@16: * @param handler The handler to be called when the read operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * const boost::system::error_code& error, // Result of operation. Chris@16: * Chris@16: * std::size_t bytes_transferred // Number of bytes copied into the Chris@16: * // buffers. If an error occurred, Chris@16: * // this will be the number of Chris@16: * // bytes successfully transferred Chris@16: * // prior to the error. Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_read(AsyncReadStream& s, basic_streambuf& b, Chris@16: CompletionCondition completion_condition, Chris@16: BOOST_ASIO_MOVE_ARG(ReadHandler) handler); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /*@}*/ Chris@16: Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_READ_HPP