...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A two-way socket useful for unit testing.
Defined in header <boost/beast/_experimental/test/stream.hpp>
template< class Executor> class basic_stream
Name |
Description |
---|---|
The type of the executor associated with the object. |
|
Rebinds the socket type to another executor. |
Name |
Description |
---|---|
Appends a string to the pending input data. |
|
Start an asynchronous read. |
|
Start an asynchronous write. |
|
basic_stream [constructor] |
Move Constructor. |
Direct input buffer access. |
|
Clear the pending input area. |
|
Close the stream. |
|
Close the other end of the stream. |
|
Establish a connection. |
|
Return the executor associated with the object. |
|
Return the number of reads. |
|
Return the number of bytes read. |
|
Return the number of writes. |
|
Return the number of bytes written. |
|
Move Assignment. |
|
Set the maximum number of bytes returned by read_some. |
|
Read some data from the stream. |
|
Returns a string view representing the pending input data. |
|
Set the maximum number of bytes returned by write_some. |
|
Write some data to the stream. |
|
~basic_stream [destructor] |
Destructor. |
An instance of this class simulates a traditional socket, while also providing features useful for unit testing. Each endpoint maintains an independent buffer called the input area. Writes from one endpoint append data to the peer's pending input area. When an endpoint performs a read and data is present in the input area, the data is delivered to the blocking or asynchronous operation. Otherwise the operation is blocked or deferred until data is made available, or until the endpoints become disconnected.
These streams may be used anywhere an algorithm accepts a reference to a
synchronous or asynchronous read or write stream. It is possible to use a
test stream in a call to net::read_until
,
or in a call to boost::beast::http::async_write
for example.
As with Boost.Asio I/O objects, a stream
constructs with a reference
to the net::io_context
to use for handling asynchronous
I/O. For asynchronous operations, the stream follows the same rules as a
traditional asio socket with respect to how completion handlers for asynchronous
operations are performed.
To facilitate testing, these streams support some additional features:
beast::basic_flat_buffer
, may be directly
accessed by the caller to inspect the contents before or after the remote
endpoint writes data. This allows a unit test to verify that the received
data matches.
stream::read_some
or stream::async_read_some
. This allows
predefined test vectors to be set up for testing read algorithms.
Distinctobjects:Safe.
Sharedobjects:Unsafe. The application must also ensure that all asynchronous operations are performed within the same implicit or explicit strand.