boost::http_io::async_read_some

Read part of the message body from the stream.

Synopsis

Declared in <boost/http_io/read.hpp>

template<
    class AsyncReadStream,
    boost::asio::completion_token_for<void(system::error_code, std::size_t)> CompletionToken = boost::asio::default_completion_token<AsyncReadStream::executor_type>::type>
auto
async_read_some(
    AsyncReadStream& s,
    http_proto::parser& pr,
    CompletionToken&& token);

Description

This function is used to asynchronously read part of a message body from a stream into an instance of parser. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The parser reads the header section of the message.

  • The parser reads the entire message.

  • Additional body data becomes available.

  • An error occurs.

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other reads until this operation completes.

void handler(
    error_code const& error,        // result of operation
    std::size_t bytes_transferred   // the number of bytes consumed by the parser
);

Regardless of whether the asynchronous operation completes immediately or not, the completion handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::async_immediate.

Per‐Operation Cancellation

This asynchronous operation supports cancellation for the following asio::cancellation_type values:

  • `asio::cancellation_type::terminal`

  • `asio::cancellation_type::partial`

  • `asio::cancellation_type::total`

if they are also supported by the AsyncReadStream type's async_read_some operation.

Parameters

Name

Description

stream

The stream from which the data is to be read. The type must meet the AsyncReadStream requirements.

parser

The parser to use. The object must remain valid at least until the handler is called; ownership is not transferred.

token

The completion token that will be used to produce a completion handler, which will be called when the read completes. The function signature of the completion handler must be:

Created with MrDocs