1*c33452fbSAndroid Build Coastguard Worker // 2*c33452fbSAndroid Build Coastguard Worker // read.hpp 3*c33452fbSAndroid Build Coastguard Worker // ~~~~~~~~ 4*c33452fbSAndroid Build Coastguard Worker // 5*c33452fbSAndroid Build Coastguard Worker // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6*c33452fbSAndroid Build Coastguard Worker // 7*c33452fbSAndroid Build Coastguard Worker // Distributed under the Boost Software License, Version 1.0. (See accompanying 8*c33452fbSAndroid Build Coastguard Worker // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9*c33452fbSAndroid Build Coastguard Worker // 10*c33452fbSAndroid Build Coastguard Worker 11*c33452fbSAndroid Build Coastguard Worker #ifndef ASIO_READ_HPP 12*c33452fbSAndroid Build Coastguard Worker #define ASIO_READ_HPP 13*c33452fbSAndroid Build Coastguard Worker 14*c33452fbSAndroid Build Coastguard Worker 15*c33452fbSAndroid Build Coastguard Worker #include "asio/detail/config.hpp" 16*c33452fbSAndroid Build Coastguard Worker #include <cstddef> 17*c33452fbSAndroid Build Coastguard Worker #include "asio/async_result.hpp" 18*c33452fbSAndroid Build Coastguard Worker #include "asio/basic_streambuf_fwd.hpp" 19*c33452fbSAndroid Build Coastguard Worker #include "asio/error.hpp" 20*c33452fbSAndroid Build Coastguard Worker 21*c33452fbSAndroid Build Coastguard Worker #include "asio/detail/push_options.hpp" 22*c33452fbSAndroid Build Coastguard Worker 23*c33452fbSAndroid Build Coastguard Worker namespace asio { 24*c33452fbSAndroid Build Coastguard Worker 25*c33452fbSAndroid Build Coastguard Worker /** 26*c33452fbSAndroid Build Coastguard Worker * @defgroup read asio::read 27*c33452fbSAndroid Build Coastguard Worker * 28*c33452fbSAndroid Build Coastguard Worker * @brief Attempt to read a certain amount of data from a stream before 29*c33452fbSAndroid Build Coastguard Worker * returning. 30*c33452fbSAndroid Build Coastguard Worker */ 31*c33452fbSAndroid Build Coastguard Worker /*@{*/ 32*c33452fbSAndroid Build Coastguard Worker 33*c33452fbSAndroid Build Coastguard Worker /// Attempt to read a certain amount of data from a stream before returning. 34*c33452fbSAndroid Build Coastguard Worker /** 35*c33452fbSAndroid Build Coastguard Worker * This function is used to read a certain number of bytes of data from a 36*c33452fbSAndroid Build Coastguard Worker * stream. The call will block until one of the following conditions is true: 37*c33452fbSAndroid Build Coastguard Worker * 38*c33452fbSAndroid Build Coastguard Worker * @li The supplied buffers are full. That is, the bytes transferred is equal to 39*c33452fbSAndroid Build Coastguard Worker * the sum of the buffer sizes. 40*c33452fbSAndroid Build Coastguard Worker * 41*c33452fbSAndroid Build Coastguard Worker * @li An error occurred. 42*c33452fbSAndroid Build Coastguard Worker * 43*c33452fbSAndroid Build Coastguard Worker * This operation is implemented in terms of zero or more calls to the stream's 44*c33452fbSAndroid Build Coastguard Worker * read_some function. 45*c33452fbSAndroid Build Coastguard Worker * 46*c33452fbSAndroid Build Coastguard Worker * @param s The stream from which the data is to be read. The type must support 47*c33452fbSAndroid Build Coastguard Worker * the SyncReadStream concept. 48*c33452fbSAndroid Build Coastguard Worker * 49*c33452fbSAndroid Build Coastguard Worker * @param buffers One or more buffers into which the data will be read. The sum 50*c33452fbSAndroid Build Coastguard Worker * of the buffer sizes indicates the maximum number of bytes to read from the 51*c33452fbSAndroid Build Coastguard Worker * stream. 52*c33452fbSAndroid Build Coastguard Worker * 53*c33452fbSAndroid Build Coastguard Worker * @returns The number of bytes transferred. 54*c33452fbSAndroid Build Coastguard Worker * 55*c33452fbSAndroid Build Coastguard Worker * @throws asio::system_error Thrown on failure. 56*c33452fbSAndroid Build Coastguard Worker * 57*c33452fbSAndroid Build Coastguard Worker * @par Example 58*c33452fbSAndroid Build Coastguard Worker * To read into a single data buffer use the @ref buffer function as follows: 59*c33452fbSAndroid Build Coastguard Worker * @code asio::read(s, asio::buffer(data, size)); @endcode 60*c33452fbSAndroid Build Coastguard Worker * See the @ref buffer documentation for information on reading into multiple 61*c33452fbSAndroid Build Coastguard Worker * buffers in one go, and how to use it with arrays, boost::array or 62*c33452fbSAndroid Build Coastguard Worker * std::vector. 63*c33452fbSAndroid Build Coastguard Worker * 64*c33452fbSAndroid Build Coastguard Worker * @note This overload is equivalent to calling: 65*c33452fbSAndroid Build Coastguard Worker * @code asio::read( 66*c33452fbSAndroid Build Coastguard Worker * s, buffers, 67*c33452fbSAndroid Build Coastguard Worker * asio::transfer_all()); @endcode 68*c33452fbSAndroid Build Coastguard Worker */ 69*c33452fbSAndroid Build Coastguard Worker template <typename SyncReadStream, typename MutableBufferSequence> 70*c33452fbSAndroid Build Coastguard Worker std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers); 71*c33452fbSAndroid Build Coastguard Worker 72*c33452fbSAndroid Build Coastguard Worker /// Attempt to read a certain amount of data from a stream before returning. 73*c33452fbSAndroid Build Coastguard Worker /** 74*c33452fbSAndroid Build Coastguard Worker * This function is used to read a certain number of bytes of data from a 75*c33452fbSAndroid Build Coastguard Worker * stream. The call will block until one of the following conditions is true: 76*c33452fbSAndroid Build Coastguard Worker * 77*c33452fbSAndroid Build Coastguard Worker * @li The supplied buffers are full. That is, the bytes transferred is equal to 78*c33452fbSAndroid Build Coastguard Worker * the sum of the buffer sizes. 79*c33452fbSAndroid Build Coastguard Worker * 80*c33452fbSAndroid Build Coastguard Worker * @li An error occurred. 81*c33452fbSAndroid Build Coastguard Worker * 82*c33452fbSAndroid Build Coastguard Worker * This operation is implemented in terms of zero or more calls to the stream's 83*c33452fbSAndroid Build Coastguard Worker * read_some function. 84*c33452fbSAndroid Build Coastguard Worker * 85*c33452fbSAndroid Build Coastguard Worker * @param s The stream from which the data is to be read. The type must support 86*c33452fbSAndroid Build Coastguard Worker * the SyncReadStream concept. 87*c33452fbSAndroid Build Coastguard Worker * 88*c33452fbSAndroid Build Coastguard Worker * @param buffers One or more buffers into which the data will be read. The sum 89*c33452fbSAndroid Build Coastguard Worker * of the buffer sizes indicates the maximum number of bytes to read from the 90*c33452fbSAndroid Build Coastguard Worker * stream. 91*c33452fbSAndroid Build Coastguard Worker * 92*c33452fbSAndroid Build Coastguard Worker * @param ec Set to indicate what error occurred, if any. 93*c33452fbSAndroid Build Coastguard Worker * 94*c33452fbSAndroid Build Coastguard Worker * @returns The number of bytes transferred. 95*c33452fbSAndroid Build Coastguard Worker * 96*c33452fbSAndroid Build Coastguard Worker * @par Example 97*c33452fbSAndroid Build Coastguard Worker * To read into a single data buffer use the @ref buffer function as follows: 98*c33452fbSAndroid Build Coastguard Worker * @code asio::read(s, asio::buffer(data, size), ec); @endcode 99*c33452fbSAndroid Build Coastguard Worker * See the @ref buffer documentation for information on reading into multiple 100*c33452fbSAndroid Build Coastguard Worker * buffers in one go, and how to use it with arrays, boost::array or 101*c33452fbSAndroid Build Coastguard Worker * std::vector. 102*c33452fbSAndroid Build Coastguard Worker * 103*c33452fbSAndroid Build Coastguard Worker * @note This overload is equivalent to calling: 104*c33452fbSAndroid Build Coastguard Worker * @code asio::read( 105*c33452fbSAndroid Build Coastguard Worker * s, buffers, 106*c33452fbSAndroid Build Coastguard Worker * asio::transfer_all(), ec); @endcode 107*c33452fbSAndroid Build Coastguard Worker */ 108*c33452fbSAndroid Build Coastguard Worker template <typename SyncReadStream, typename MutableBufferSequence> 109*c33452fbSAndroid Build Coastguard Worker std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, 110*c33452fbSAndroid Build Coastguard Worker asio::error_code& ec); 111*c33452fbSAndroid Build Coastguard Worker 112*c33452fbSAndroid Build Coastguard Worker /// Attempt to read a certain amount of data from a stream before returning. 113*c33452fbSAndroid Build Coastguard Worker /** 114*c33452fbSAndroid Build Coastguard Worker * This function is used to read a certain number of bytes of data from a 115*c33452fbSAndroid Build Coastguard Worker * stream. The call will block until one of the following conditions is true: 116*c33452fbSAndroid Build Coastguard Worker * 117*c33452fbSAndroid Build Coastguard Worker * @li The supplied buffers are full. That is, the bytes transferred is equal to 118*c33452fbSAndroid Build Coastguard Worker * the sum of the buffer sizes. 119*c33452fbSAndroid Build Coastguard Worker * 120*c33452fbSAndroid Build Coastguard Worker * @li The completion_condition function object returns 0. 121*c33452fbSAndroid Build Coastguard Worker * 122*c33452fbSAndroid Build Coastguard Worker * This operation is implemented in terms of zero or more calls to the stream's 123*c33452fbSAndroid Build Coastguard Worker * read_some function. 124*c33452fbSAndroid Build Coastguard Worker * 125*c33452fbSAndroid Build Coastguard Worker * @param s The stream from which the data is to be read. The type must support 126*c33452fbSAndroid Build Coastguard Worker * the SyncReadStream concept. 127*c33452fbSAndroid Build Coastguard Worker * 128*c33452fbSAndroid Build Coastguard Worker * @param buffers One or more buffers into which the data will be read. The sum 129*c33452fbSAndroid Build Coastguard Worker * of the buffer sizes indicates the maximum number of bytes to read from the 130*c33452fbSAndroid Build Coastguard Worker * stream. 131*c33452fbSAndroid Build Coastguard Worker * 132*c33452fbSAndroid Build Coastguard Worker * @param completion_condition The function object to be called to determine 133*c33452fbSAndroid Build Coastguard Worker * whether the read operation is complete. The signature of the function object 134*c33452fbSAndroid Build Coastguard Worker * must be: 135*c33452fbSAndroid Build Coastguard Worker * @code std::size_t completion_condition( 136*c33452fbSAndroid Build Coastguard Worker * // Result of latest read_some operation. 137*c33452fbSAndroid Build Coastguard Worker * const asio::error_code& error, 138*c33452fbSAndroid Build Coastguard Worker * 139*c33452fbSAndroid Build Coastguard Worker * // Number of bytes transferred so far. 140*c33452fbSAndroid Build Coastguard Worker * std::size_t bytes_transferred 141*c33452fbSAndroid Build Coastguard Worker * ); @endcode 142*c33452fbSAndroid Build Coastguard Worker * A return value of 0 indicates that the read operation is complete. A non-zero 143*c33452fbSAndroid Build Coastguard Worker * return value indicates the maximum number of bytes to be read on the next 144*c33452fbSAndroid Build Coastguard Worker * call to the stream's read_some function. 145*c33452fbSAndroid Build Coastguard Worker * 146*c33452fbSAndroid Build Coastguard Worker * @returns The number of bytes transferred. 147*c33452fbSAndroid Build Coastguard Worker * 148*c33452fbSAndroid Build Coastguard Worker * @throws asio::system_error Thrown on failure. 149*c33452fbSAndroid Build Coastguard Worker * 150*c33452fbSAndroid Build Coastguard Worker * @par Example 151*c33452fbSAndroid Build Coastguard Worker * To read into a single data buffer use the @ref buffer function as follows: 152*c33452fbSAndroid Build Coastguard Worker * @code asio::read(s, asio::buffer(data, size), 153*c33452fbSAndroid Build Coastguard Worker * asio::transfer_at_least(32)); @endcode 154*c33452fbSAndroid Build Coastguard Worker * See the @ref buffer documentation for information on reading into multiple 155*c33452fbSAndroid Build Coastguard Worker * buffers in one go, and how to use it with arrays, boost::array or 156*c33452fbSAndroid Build Coastguard Worker * std::vector. 157*c33452fbSAndroid Build Coastguard Worker */ 158*c33452fbSAndroid Build Coastguard Worker template <typename SyncReadStream, typename MutableBufferSequence, 159*c33452fbSAndroid Build Coastguard Worker typename CompletionCondition> 160*c33452fbSAndroid Build Coastguard Worker std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, 161*c33452fbSAndroid Build Coastguard Worker CompletionCondition completion_condition); 162*c33452fbSAndroid Build Coastguard Worker 163*c33452fbSAndroid Build Coastguard Worker /// Attempt to read a certain amount of data from a stream before returning. 164*c33452fbSAndroid Build Coastguard Worker /** 165*c33452fbSAndroid Build Coastguard Worker * This function is used to read a certain number of bytes of data from a 166*c33452fbSAndroid Build Coastguard Worker * stream. The call will block until one of the following conditions is true: 167*c33452fbSAndroid Build Coastguard Worker * 168*c33452fbSAndroid Build Coastguard Worker * @li The supplied buffers are full. That is, the bytes transferred is equal to 169*c33452fbSAndroid Build Coastguard Worker * the sum of the buffer sizes. 170*c33452fbSAndroid Build Coastguard Worker * 171*c33452fbSAndroid Build Coastguard Worker * @li The completion_condition function object returns 0. 172*c33452fbSAndroid Build Coastguard Worker * 173*c33452fbSAndroid Build Coastguard Worker * This operation is implemented in terms of zero or more calls to the stream's 174*c33452fbSAndroid Build Coastguard Worker * read_some function. 175*c33452fbSAndroid Build Coastguard Worker * 176*c33452fbSAndroid Build Coastguard Worker * @param s The stream from which the data is to be read. The type must support 177*c33452fbSAndroid Build Coastguard Worker * the SyncReadStream concept. 178*c33452fbSAndroid Build Coastguard Worker * 179*c33452fbSAndroid Build Coastguard Worker * @param buffers One or more buffers into which the data will be read. The sum 180*c33452fbSAndroid Build Coastguard Worker * of the buffer sizes indicates the maximum number of bytes to read from the 181*c33452fbSAndroid Build Coastguard Worker * stream. 182*c33452fbSAndroid Build Coastguard Worker * 183*c33452fbSAndroid Build Coastguard Worker * @param completion_condition The function object to be called to determine 184*c33452fbSAndroid Build Coastguard Worker * whether the read operation is complete. The signature of the function object 185*c33452fbSAndroid Build Coastguard Worker * must be: 186*c33452fbSAndroid Build Coastguard Worker * @code std::size_t completion_condition( 187*c33452fbSAndroid Build Coastguard Worker * // Result of latest read_some operation. 188*c33452fbSAndroid Build Coastguard Worker * const asio::error_code& error, 189*c33452fbSAndroid Build Coastguard Worker * 190*c33452fbSAndroid Build Coastguard Worker * // Number of bytes transferred so far. 191*c33452fbSAndroid Build Coastguard Worker * std::size_t bytes_transferred 192*c33452fbSAndroid Build Coastguard Worker * ); @endcode 193*c33452fbSAndroid Build Coastguard Worker * A return value of 0 indicates that the read operation is complete. A non-zero 194*c33452fbSAndroid Build Coastguard Worker * return value indicates the maximum number of bytes to be read on the next 195*c33452fbSAndroid Build Coastguard Worker * call to the stream's read_some function. 196*c33452fbSAndroid Build Coastguard Worker * 197*c33452fbSAndroid Build Coastguard Worker * @param ec Set to indicate what error occurred, if any. 198*c33452fbSAndroid Build Coastguard Worker * 199*c33452fbSAndroid Build Coastguard Worker * @returns The number of bytes read. If an error occurs, returns the total 200*c33452fbSAndroid Build Coastguard Worker * number of bytes successfully transferred prior to the error. 201*c33452fbSAndroid Build Coastguard Worker */ 202*c33452fbSAndroid Build Coastguard Worker template <typename SyncReadStream, typename MutableBufferSequence, 203*c33452fbSAndroid Build Coastguard Worker typename CompletionCondition> 204*c33452fbSAndroid Build Coastguard Worker std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, 205*c33452fbSAndroid Build Coastguard Worker CompletionCondition completion_condition, asio::error_code& ec); 206*c33452fbSAndroid Build Coastguard Worker 207*c33452fbSAndroid Build Coastguard Worker 208*c33452fbSAndroid Build Coastguard Worker /*@}*/ 209*c33452fbSAndroid Build Coastguard Worker /** 210*c33452fbSAndroid Build Coastguard Worker * @defgroup async_read asio::async_read 211*c33452fbSAndroid Build Coastguard Worker * 212*c33452fbSAndroid Build Coastguard Worker * @brief Start an asynchronous operation to read a certain amount of data from 213*c33452fbSAndroid Build Coastguard Worker * a stream. 214*c33452fbSAndroid Build Coastguard Worker */ 215*c33452fbSAndroid Build Coastguard Worker /*@{*/ 216*c33452fbSAndroid Build Coastguard Worker 217*c33452fbSAndroid Build Coastguard Worker /// Start an asynchronous operation to read a certain amount of data from a 218*c33452fbSAndroid Build Coastguard Worker /// stream. 219*c33452fbSAndroid Build Coastguard Worker /** 220*c33452fbSAndroid Build Coastguard Worker * This function is used to asynchronously read a certain number of bytes of 221*c33452fbSAndroid Build Coastguard Worker * data from a stream. The function call always returns immediately. The 222*c33452fbSAndroid Build Coastguard Worker * asynchronous operation will continue until one of the following conditions is 223*c33452fbSAndroid Build Coastguard Worker * true: 224*c33452fbSAndroid Build Coastguard Worker * 225*c33452fbSAndroid Build Coastguard Worker * @li The supplied buffers are full. That is, the bytes transferred is equal to 226*c33452fbSAndroid Build Coastguard Worker * the sum of the buffer sizes. 227*c33452fbSAndroid Build Coastguard Worker * 228*c33452fbSAndroid Build Coastguard Worker * @li An error occurred. 229*c33452fbSAndroid Build Coastguard Worker * 230*c33452fbSAndroid Build Coastguard Worker * This operation is implemented in terms of zero or more calls to the stream's 231*c33452fbSAndroid Build Coastguard Worker * async_read_some function, and is known as a <em>composed operation</em>. The 232*c33452fbSAndroid Build Coastguard Worker * program must ensure that the stream performs no other read operations (such 233*c33452fbSAndroid Build Coastguard Worker * as async_read, the stream's async_read_some function, or any other composed 234*c33452fbSAndroid Build Coastguard Worker * operations that perform reads) until this operation completes. 235*c33452fbSAndroid Build Coastguard Worker * 236*c33452fbSAndroid Build Coastguard Worker * @param s The stream from which the data is to be read. The type must support 237*c33452fbSAndroid Build Coastguard Worker * the AsyncReadStream concept. 238*c33452fbSAndroid Build Coastguard Worker * 239*c33452fbSAndroid Build Coastguard Worker * @param buffers One or more buffers into which the data will be read. The sum 240*c33452fbSAndroid Build Coastguard Worker * of the buffer sizes indicates the maximum number of bytes to read from the 241*c33452fbSAndroid Build Coastguard Worker * stream. Although the buffers object may be copied as necessary, ownership of 242*c33452fbSAndroid Build Coastguard Worker * the underlying memory blocks is retained by the caller, which must guarantee 243*c33452fbSAndroid Build Coastguard Worker * that they remain valid until the handler is called. 244*c33452fbSAndroid Build Coastguard Worker * 245*c33452fbSAndroid Build Coastguard Worker * @param handler The handler to be called when the read operation completes. 246*c33452fbSAndroid Build Coastguard Worker * Copies will be made of the handler as required. The function signature of the 247*c33452fbSAndroid Build Coastguard Worker * handler must be: 248*c33452fbSAndroid Build Coastguard Worker * @code void handler( 249*c33452fbSAndroid Build Coastguard Worker * const asio::error_code& error, // Result of operation. 250*c33452fbSAndroid Build Coastguard Worker * 251*c33452fbSAndroid Build Coastguard Worker * std::size_t bytes_transferred // Number of bytes copied into the 252*c33452fbSAndroid Build Coastguard Worker * // buffers. If an error occurred, 253*c33452fbSAndroid Build Coastguard Worker * // this will be the number of 254*c33452fbSAndroid Build Coastguard Worker * // bytes successfully transferred 255*c33452fbSAndroid Build Coastguard Worker * // prior to the error. 256*c33452fbSAndroid Build Coastguard Worker * ); @endcode 257*c33452fbSAndroid Build Coastguard Worker * Regardless of whether the asynchronous operation completes immediately or 258*c33452fbSAndroid Build Coastguard Worker * not, the handler will not be invoked from within this function. Invocation of 259*c33452fbSAndroid Build Coastguard Worker * the handler will be performed in a manner equivalent to using 260*c33452fbSAndroid Build Coastguard Worker * asio::io_service::post(). 261*c33452fbSAndroid Build Coastguard Worker * 262*c33452fbSAndroid Build Coastguard Worker * @par Example 263*c33452fbSAndroid Build Coastguard Worker * To read into a single data buffer use the @ref buffer function as follows: 264*c33452fbSAndroid Build Coastguard Worker * @code 265*c33452fbSAndroid Build Coastguard Worker * asio::async_read(s, asio::buffer(data, size), handler); 266*c33452fbSAndroid Build Coastguard Worker * @endcode 267*c33452fbSAndroid Build Coastguard Worker * See the @ref buffer documentation for information on reading into multiple 268*c33452fbSAndroid Build Coastguard Worker * buffers in one go, and how to use it with arrays, boost::array or 269*c33452fbSAndroid Build Coastguard Worker * std::vector. 270*c33452fbSAndroid Build Coastguard Worker * 271*c33452fbSAndroid Build Coastguard Worker * @note This overload is equivalent to calling: 272*c33452fbSAndroid Build Coastguard Worker * @code asio::async_read( 273*c33452fbSAndroid Build Coastguard Worker * s, buffers, 274*c33452fbSAndroid Build Coastguard Worker * asio::transfer_all(), 275*c33452fbSAndroid Build Coastguard Worker * handler); @endcode 276*c33452fbSAndroid Build Coastguard Worker */ 277*c33452fbSAndroid Build Coastguard Worker template <typename AsyncReadStream, typename MutableBufferSequence, 278*c33452fbSAndroid Build Coastguard Worker typename ReadHandler> 279*c33452fbSAndroid Build Coastguard Worker ASIO_INITFN_RESULT_TYPE(ReadHandler, 280*c33452fbSAndroid Build Coastguard Worker void (asio::error_code, std::size_t)) 281*c33452fbSAndroid Build Coastguard Worker async_read(AsyncReadStream& s, const MutableBufferSequence& buffers, 282*c33452fbSAndroid Build Coastguard Worker ASIO_MOVE_ARG(ReadHandler) handler); 283*c33452fbSAndroid Build Coastguard Worker 284*c33452fbSAndroid Build Coastguard Worker /// Start an asynchronous operation to read a certain amount of data from a 285*c33452fbSAndroid Build Coastguard Worker /// stream. 286*c33452fbSAndroid Build Coastguard Worker /** 287*c33452fbSAndroid Build Coastguard Worker * This function is used to asynchronously read a certain number of bytes of 288*c33452fbSAndroid Build Coastguard Worker * data from a stream. The function call always returns immediately. The 289*c33452fbSAndroid Build Coastguard Worker * asynchronous operation will continue until one of the following conditions is 290*c33452fbSAndroid Build Coastguard Worker * true: 291*c33452fbSAndroid Build Coastguard Worker * 292*c33452fbSAndroid Build Coastguard Worker * @li The supplied buffers are full. That is, the bytes transferred is equal to 293*c33452fbSAndroid Build Coastguard Worker * the sum of the buffer sizes. 294*c33452fbSAndroid Build Coastguard Worker * 295*c33452fbSAndroid Build Coastguard Worker * @li The completion_condition function object returns 0. 296*c33452fbSAndroid Build Coastguard Worker * 297*c33452fbSAndroid Build Coastguard Worker * @param s The stream from which the data is to be read. The type must support 298*c33452fbSAndroid Build Coastguard Worker * the AsyncReadStream concept. 299*c33452fbSAndroid Build Coastguard Worker * 300*c33452fbSAndroid Build Coastguard Worker * @param buffers One or more buffers into which the data will be read. The sum 301*c33452fbSAndroid Build Coastguard Worker * of the buffer sizes indicates the maximum number of bytes to read from the 302*c33452fbSAndroid Build Coastguard Worker * stream. Although the buffers object may be copied as necessary, ownership of 303*c33452fbSAndroid Build Coastguard Worker * the underlying memory blocks is retained by the caller, which must guarantee 304*c33452fbSAndroid Build Coastguard Worker * that they remain valid until the handler is called. 305*c33452fbSAndroid Build Coastguard Worker * 306*c33452fbSAndroid Build Coastguard Worker * @param completion_condition The function object to be called to determine 307*c33452fbSAndroid Build Coastguard Worker * whether the read operation is complete. The signature of the function object 308*c33452fbSAndroid Build Coastguard Worker * must be: 309*c33452fbSAndroid Build Coastguard Worker * @code std::size_t completion_condition( 310*c33452fbSAndroid Build Coastguard Worker * // Result of latest async_read_some operation. 311*c33452fbSAndroid Build Coastguard Worker * const asio::error_code& error, 312*c33452fbSAndroid Build Coastguard Worker * 313*c33452fbSAndroid Build Coastguard Worker * // Number of bytes transferred so far. 314*c33452fbSAndroid Build Coastguard Worker * std::size_t bytes_transferred 315*c33452fbSAndroid Build Coastguard Worker * ); @endcode 316*c33452fbSAndroid Build Coastguard Worker * A return value of 0 indicates that the read operation is complete. A non-zero 317*c33452fbSAndroid Build Coastguard Worker * return value indicates the maximum number of bytes to be read on the next 318*c33452fbSAndroid Build Coastguard Worker * call to the stream's async_read_some function. 319*c33452fbSAndroid Build Coastguard Worker * 320*c33452fbSAndroid Build Coastguard Worker * @param handler The handler to be called when the read operation completes. 321*c33452fbSAndroid Build Coastguard Worker * Copies will be made of the handler as required. The function signature of the 322*c33452fbSAndroid Build Coastguard Worker * handler must be: 323*c33452fbSAndroid Build Coastguard Worker * @code void handler( 324*c33452fbSAndroid Build Coastguard Worker * const asio::error_code& error, // Result of operation. 325*c33452fbSAndroid Build Coastguard Worker * 326*c33452fbSAndroid Build Coastguard Worker * std::size_t bytes_transferred // Number of bytes copied into the 327*c33452fbSAndroid Build Coastguard Worker * // buffers. If an error occurred, 328*c33452fbSAndroid Build Coastguard Worker * // this will be the number of 329*c33452fbSAndroid Build Coastguard Worker * // bytes successfully transferred 330*c33452fbSAndroid Build Coastguard Worker * // prior to the error. 331*c33452fbSAndroid Build Coastguard Worker * ); @endcode 332*c33452fbSAndroid Build Coastguard Worker * Regardless of whether the asynchronous operation completes immediately or 333*c33452fbSAndroid Build Coastguard Worker * not, the handler will not be invoked from within this function. Invocation of 334*c33452fbSAndroid Build Coastguard Worker * the handler will be performed in a manner equivalent to using 335*c33452fbSAndroid Build Coastguard Worker * asio::io_service::post(). 336*c33452fbSAndroid Build Coastguard Worker * 337*c33452fbSAndroid Build Coastguard Worker * @par Example 338*c33452fbSAndroid Build Coastguard Worker * To read into a single data buffer use the @ref buffer function as follows: 339*c33452fbSAndroid Build Coastguard Worker * @code asio::async_read(s, 340*c33452fbSAndroid Build Coastguard Worker * asio::buffer(data, size), 341*c33452fbSAndroid Build Coastguard Worker * asio::transfer_at_least(32), 342*c33452fbSAndroid Build Coastguard Worker * handler); @endcode 343*c33452fbSAndroid Build Coastguard Worker * See the @ref buffer documentation for information on reading into multiple 344*c33452fbSAndroid Build Coastguard Worker * buffers in one go, and how to use it with arrays, boost::array or 345*c33452fbSAndroid Build Coastguard Worker * std::vector. 346*c33452fbSAndroid Build Coastguard Worker */ 347*c33452fbSAndroid Build Coastguard Worker template <typename AsyncReadStream, typename MutableBufferSequence, 348*c33452fbSAndroid Build Coastguard Worker typename CompletionCondition, typename ReadHandler> 349*c33452fbSAndroid Build Coastguard Worker ASIO_INITFN_RESULT_TYPE(ReadHandler, 350*c33452fbSAndroid Build Coastguard Worker void (asio::error_code, std::size_t)) 351*c33452fbSAndroid Build Coastguard Worker async_read(AsyncReadStream& s, const MutableBufferSequence& buffers, 352*c33452fbSAndroid Build Coastguard Worker CompletionCondition completion_condition, 353*c33452fbSAndroid Build Coastguard Worker ASIO_MOVE_ARG(ReadHandler) handler); 354*c33452fbSAndroid Build Coastguard Worker 355*c33452fbSAndroid Build Coastguard Worker 356*c33452fbSAndroid Build Coastguard Worker /*@}*/ 357*c33452fbSAndroid Build Coastguard Worker 358*c33452fbSAndroid Build Coastguard Worker } // namespace asio 359*c33452fbSAndroid Build Coastguard Worker 360*c33452fbSAndroid Build Coastguard Worker #include "asio/detail/pop_options.hpp" 361*c33452fbSAndroid Build Coastguard Worker 362*c33452fbSAndroid Build Coastguard Worker #include "asio/impl/read.hpp" 363*c33452fbSAndroid Build Coastguard Worker 364*c33452fbSAndroid Build Coastguard Worker #endif // ASIO_READ_HPP 365