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 write performance.

Synopsis

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

template<
    class NextLayer>
class flat_stream
Types

Name

Description

executor_type

The type of the executor associated with the object.

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]



Constructor.

get_executor

Get the executor associated with the object.

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]

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 net::ssl::stream, which does not use OpenSSL's scatter/gather interface for its low-level read some and write some operations. It is normally not necessary to use this class directly if you are already using ssl_stream. The following examples shows how to use this class with the ssl stream that comes with networking:

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<net::ssl::stream<ip::tcp::socket>> fs{ioc, ctx};

Alternatively you can write

ssl::stream<ip::tcp::socket> ss{ioc, ctx};
flat_stream<net::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<net::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 net::ssl::stream.

See Also

PrevUpHomeNext