Beast Logo

PrevUpHomeNext

dynabuf_readstream

A Stream with attached DynamicBuffer to buffer reads.

template<
    class Stream,
    class DynamicBuffer>
class dynabuf_readstream
Types

Name

Description

dynabuf_type

The type of the internal buffer.

lowest_layer_type

The type of the lowest layer.

next_layer_type

The type of the next layer.

Member Functions

Name

Description

async_read_some

Start an asynchronous read.

async_write_some

Start an asynchronous write.

buffer

Access the internal buffer.

capacity

Set the maximum buffer size.

dynabuf_readstream

Move constructor.

Construct the wrapping stream.

get_io_service

Get the io_service associated with the object.

lowest_layer

Get a reference to the lowest layer.

Get a const reference to the lowest layer.

next_layer

Get a reference to the next layer.

Get a const reference to the next layer.

operator=

Move assignment.

read_some

Read some data from the stream.

write_some

Write some data to the stream.

This wraps a Stream implementation so that calls to write are passed through to the underlying stream, while calls to read will first consume the input sequence stored in a DynamicBuffer which is part of the object.

The use-case for this class is different than that of the boost::asio::buffered_readstream. It is designed to facilitate the use of boost::asio::read_until, and to allow buffers acquired during detection of handshakes to be made transparently available to callers. A hypothetical implementation of the buffered version of boost::asio::ssl::stream::async_handshake could make use of this wrapper.

Uses:

Example:

// Process the next HTTP header on the stream,
// leaving excess bytes behind for the next call.
//
template<class DynamicBuffer>
void process_http_message(
    dynabuf_readstream<DynamicBuffer>& stream)
{
    // Read up to and including the end of the HTTP
    // header, leaving the sequence in the stream's
    // buffer. read_until may read past the end of the
    // headers; the return value will include only the
    // part up to the end of the delimiter.
    //
    std::size_t bytes_transferred =
        boost::asio::read_until(
            stream.next_layer(), stream.buffer(), "\r\n\r\n");

    // Use prepare_buffers() to limit the input
    // sequence to only the data up to and including
    // the trailing "\r\n\r\n".
    //
    auto header_buffers = prepare_buffers(
        bytes_transferred, stream.buffer().data());

    ...

    // Discard the portion of the input corresponding
    // to the HTTP headers.
    //
    stream.buffer().consume(bytes_transferred);

    // Everything we read from the stream
    // is part of the content-body.
}

Stream

The type of stream to wrap.

DynamicBuffer

The type of stream buffer to use.

Requirements

Header: beast/core/dynabuf_readstream.hpp

Convenience header: beast/core.hpp


PrevUpHomeNext