...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Stream wrapper to improve ssl::stream write performance.
Defined in header <boost/beast/experimental/core/flat_stream.hpp>
template< class NextLayer> class flat_stream
Name |
Description |
---|---|
The type of the executor associated with the object. |
|
The type of the lowest layer. |
|
The type of the next layer. |
Name |
Description |
---|---|
Start an asynchronous read. |
|
Start an asynchronous write. |
|
Constructor. |
|
Get the executor associated with the object. |
|
Get a reference to the lowest layer. |
|
Get a reference to the next layer. |
|
Read some data from the stream. |
|
Write some data to the stream. |
|
Destructor. |
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.
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:
boost::asio::read
, boost::asio::async_read
boost::asio::write
, boost::asio::async_write
boost::asio::read_until
, boost::asio::async_read_until
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};
Type |
Description |
---|---|
|
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 |
AsyncStream SyncStream