ゴミ箱
Classes | Public Types | Public Member Functions | List of all members
boost::beast::buffered_read_stream< Stream, DynamicBuffer > Class Template Reference

#include <buffered_read_stream.hpp>

Public Types

using buffer_type = DynamicBuffer
 The type of the internal buffer. More...
 
using next_layer_type = typename std::remove_reference< Stream >::type
 The type of the next layer. More...
 
using lowest_layer_type = typename get_lowest_layer< next_layer_type >::type
 The type of the lowest layer. More...
 

Public Member Functions

 buffered_read_stream (buffered_read_stream &&)=default
 
buffered_read_streamoperator= (buffered_read_stream &&)=default
 
template<class... Args>
 buffered_read_stream (Args &&...args)
 
next_layer_typenext_layer ()
 Get a reference to the next layer. More...
 
next_layer_type const & next_layer () const
 Get a const reference to the next layer. More...
 
lowest_layer_typelowest_layer ()
 Get a reference to the lowest layer. More...
 
lowest_layer_type const & lowest_layer () const
 Get a const reference to the lowest layer. More...
 
boost::asio::io_service & get_io_service ()
 Get the io_service associated with the object. More...
 
DynamicBuffer & buffer ()
 
DynamicBuffer const & buffer () const
 Access the internal buffer. More...
 
void capacity (std::size_t size)
 
template<class MutableBufferSequence >
std::size_t read_some (MutableBufferSequence const &buffers)
 
template<class MutableBufferSequence >
std::size_t read_some (MutableBufferSequence const &buffers, error_code &ec)
 
template<class MutableBufferSequence , class ReadHandler >
async_return_type< ReadHandler, void(error_code)> async_read_some (MutableBufferSequence const &buffers, ReadHandler &&handler)
 
template<class ConstBufferSequence >
std::size_t write_some (ConstBufferSequence const &buffers)
 
template<class ConstBufferSequence >
std::size_t write_some (ConstBufferSequence const &buffers, error_code &ec)
 
template<class ConstBufferSequence , class WriteHandler >
async_return_type< WriteHandler, void(error_code)> async_write_some (ConstBufferSequence const &buffers, WriteHandler &&handler)
 
template<class ConstBufferSequence , class WriteHandler >
auto async_write_some (ConstBufferSequence const &buffers, WriteHandler &&handler) -> async_return_type< WriteHandler, void(error_code)>
 
template<class MutableBufferSequence , class ReadHandler >
auto async_read_some (MutableBufferSequence const &buffers, ReadHandler &&handler) -> async_return_type< ReadHandler, void(error_code)>
 

Detailed Description

template<class Stream, class DynamicBuffer>
class boost::beast::buffered_read_stream< Stream, DynamicBuffer >

A Stream with attached DynamicBuffer to buffer reads.

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(
buffered_read_stream<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 buffer_prefix() to limit the input
// sequence to only the data up to and including
// the trailing "\r\n\r\n".
//
auto header_buffers = buffer_prefix(
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.
}
Template Parameters
StreamThe type of stream to wrap.
DynamicBufferThe type of stream buffer to use.

Member Typedef Documentation

template<class Stream , class DynamicBuffer >
using boost::beast::buffered_read_stream< Stream, DynamicBuffer >::buffer_type = DynamicBuffer

The type of the internal buffer.

template<class Stream , class DynamicBuffer >
using boost::beast::buffered_read_stream< Stream, DynamicBuffer >::lowest_layer_type = typename get_lowest_layer<next_layer_type>::type

The type of the lowest layer.

template<class Stream , class DynamicBuffer >
using boost::beast::buffered_read_stream< Stream, DynamicBuffer >::next_layer_type = typename std::remove_reference<Stream>::type

The type of the next layer.

Constructor & Destructor Documentation

template<class Stream , class DynamicBuffer >
boost::beast::buffered_read_stream< Stream, DynamicBuffer >::buffered_read_stream ( buffered_read_stream< Stream, DynamicBuffer > &&  )
default

Move constructor.

Note
The behavior of move assignment on or from streams with active or pending operations is undefined.
template<class Stream , class DynamicBuffer >
template<class... Args>
boost::beast::buffered_read_stream< Stream, DynamicBuffer >::buffered_read_stream ( Args &&...  args)
explicit

Construct the wrapping stream.

Parameters
argsParameters forwarded to the Stream constructor.

Member Function Documentation

template<class Stream , class DynamicBuffer >
template<class MutableBufferSequence , class ReadHandler >
auto boost::beast::buffered_read_stream< Stream, DynamicBuffer >::async_read_some ( MutableBufferSequence const &  buffers,
ReadHandler &&  handler 
) -> async_return_type<ReadHandler, void(error_code)>
template<class Stream , class DynamicBuffer >
template<class MutableBufferSequence , class ReadHandler >
async_return_type<ReadHandler, void(error_code)> boost::beast::buffered_read_stream< Stream, DynamicBuffer >::async_read_some ( MutableBufferSequence const &  buffers,
ReadHandler &&  handler 
)

Start an asynchronous read.

This function is used to asynchronously read data from the stream. The function call always returns immediately.

Parameters
buffersOne or more buffers into which the data will be read. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
handlerThe handler to be called when the operation completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be:
void handler(
error_code const& error, // result of operation
std::size_t bytes_transferred // number of bytes transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using boost::asio::io_service::post.
template<class Stream , class DynamicBuffer >
template<class ConstBufferSequence , class WriteHandler >
auto boost::beast::buffered_read_stream< Stream, DynamicBuffer >::async_write_some ( ConstBufferSequence const &  buffers,
WriteHandler &&  handler 
) -> async_return_type<WriteHandler, void(error_code)>
template<class Stream , class DynamicBuffer >
template<class ConstBufferSequence , class WriteHandler >
async_return_type<WriteHandler, void(error_code)> boost::beast::buffered_read_stream< Stream, DynamicBuffer >::async_write_some ( ConstBufferSequence const &  buffers,
WriteHandler &&  handler 
)

Start an asynchronous write.

This function is used to asynchronously write data from the stream. The function call always returns immediately.

Parameters
buffersOne or more data buffers to be written to the stream. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
handlerThe handler to be called when the operation completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be:
void handler(
error_code const& error, // result of operation
std::size_t bytes_transferred // number of bytes transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using boost::asio::io_service::post.
template<class Stream , class DynamicBuffer >
DynamicBuffer& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::buffer ( )
inline

Access the internal buffer.

The internal buffer is returned. It is possible for the caller to break invariants with this function. For example, by causing the internal buffer size to increase beyond the caller defined maximum.

template<class Stream , class DynamicBuffer >
DynamicBuffer const& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::buffer ( ) const
inline

Access the internal buffer.

template<class Stream , class DynamicBuffer >
void boost::beast::buffered_read_stream< Stream, DynamicBuffer >::capacity ( std::size_t  size)
inline

Set the maximum buffer size.

This changes the maximum size of the internal buffer used to hold read data. No bytes are discarded by this call. If the buffer size is set to zero, no more data will be buffered.

Thread safety: The caller is responsible for making sure the call is made from the same implicit or explicit strand.

Parameters
sizeThe number of bytes in the read buffer.
Note
This is a soft limit. If the new maximum size is smaller than the amount of data in the buffer, no bytes are discarded.
template<class Stream , class DynamicBuffer >
boost::asio::io_service& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::get_io_service ( )
inline

Get the io_service associated with the object.

template<class Stream , class DynamicBuffer >
lowest_layer_type& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::lowest_layer ( )
inline

Get a reference to the lowest layer.

template<class Stream , class DynamicBuffer >
lowest_layer_type const& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::lowest_layer ( ) const
inline

Get a const reference to the lowest layer.

template<class Stream , class DynamicBuffer >
next_layer_type& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::next_layer ( )
inline

Get a reference to the next layer.

template<class Stream , class DynamicBuffer >
next_layer_type const& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::next_layer ( ) const
inline

Get a const reference to the next layer.

template<class Stream , class DynamicBuffer >
buffered_read_stream& boost::beast::buffered_read_stream< Stream, DynamicBuffer >::operator= ( buffered_read_stream< Stream, DynamicBuffer > &&  )
default

Move assignment.

Note
The behavior of move assignment on or from streams with active or pending operations is undefined.
template<class Stream , class DynamicBuffer >
template<class MutableBufferSequence >
std::size_t boost::beast::buffered_read_stream< Stream, DynamicBuffer >::read_some ( MutableBufferSequence const &  buffers)

Read some data from the stream.

This function is used to read data from the stream. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters
buffersOne or more buffers into which the data will be read.
Returns
The number of bytes read.
Exceptions
system_errorThrown on failure.
template<class Stream , class DynamicBuffer >
template<class MutableBufferSequence >
std::size_t boost::beast::buffered_read_stream< Stream, DynamicBuffer >::read_some ( MutableBufferSequence const &  buffers,
error_code ec 
)

Read some data from the stream.

This function is used to read data from the stream. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters
buffersOne or more buffers into which the data will be read.
ecSet to the error, if any occurred.
Returns
The number of bytes read, or 0 on error.
template<class Stream , class DynamicBuffer >
template<class ConstBufferSequence >
std::size_t boost::beast::buffered_read_stream< Stream, DynamicBuffer >::write_some ( ConstBufferSequence const &  buffers)
inline

Write some data to the stream.

This function is used to write data to the stream. The function call will block until one or more bytes of the data has been written successfully, or until an error occurs.

Parameters
buffersOne or more data buffers to be written to the stream.
Returns
The number of bytes written.
Exceptions
system_errorThrown on failure.
template<class Stream , class DynamicBuffer >
template<class ConstBufferSequence >
std::size_t boost::beast::buffered_read_stream< Stream, DynamicBuffer >::write_some ( ConstBufferSequence const &  buffers,
error_code ec 
)
inline

Write some data to the stream.

This function is used to write data to the stream. The function call will block until one or more bytes of the data has been written successfully, or until an error occurs.

Parameters
buffersOne or more data buffers to be written to the stream.
ecSet to the error, if any occurred.
Returns
The number of bytes written.

The documentation for this class was generated from the following files: