Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

flat_stream

Stream wrapper to improve ssl::stream write performance.

Synopsis

Defined in header <boost/beast/experimental/core/flat_stream.hpp>

template<
    class NextLayer>
class flat_stream
Types

Name

Description

executor_type

The type of the executor associated with the object.

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.

flat_stream

Constructor.

get_executor

Get the executor associated with the object.

lowest_layer

Get a reference to the lowest layer.

next_layer

Get a reference to the next layer.

operator=

read_some

Read some data from the stream.

write_some

Write some data to the stream.

~flat_stream

Destructor.

Description

This wrapper flattens writes for buffer sequences having length greater than 1 and total size below a predefined amount, using a dynamic memory allocation. It is primarily designed to overcome a performance limitation of the current version of boost::asio::ssl::stream, which does not use OpenSSL's scatter/gather interface for its low-level read some and write some operations.

Example

To use the flat_stream template with SSL streams, declare a variable of the correct type. Parameters passed to the constructor will be forwarded to the next layer's constructor:

flat_stream<ssl::stream<ip::tcp::socket>> fs{ioc, ctx};

Alternatively you can write

ssl::stream<ip::tcp::socket> ss{ioc, ctx};
flat_stream<ssl::stream<ip::tcp::socket>&> fs{ss};

The resulting stream may be passed to any stream algorithms which operate on synchronous or asynchronous read or write streams, examples include:

The stream may also be used as a template parameter in other stream wrappers, such as for websocket:

websocket::stream<flat_stream<ssl::stream<ip::tcp::socket>>> ws{ioc, ctx};
Template Parameters

Type

Description

NextLayer

The type representing the next layer, to which data will be read and written during operations. For synchronous operations, the type must support the SyncStream concept. For asynchronous operations, the type must support the AsyncStream concept. This type will usually be some variation of boost::asio::ssl::stream.

Concepts

AsyncStream SyncStream

See Also

PrevUpHomeNext