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

PrevUpHomeNext

test::basic_stream

A two-way socket useful for unit testing.

Synopsis

Defined in header <boost/beast/_experimental/test/stream.hpp>

template<
    class Executor>
class basic_stream
Types

Name

Description

buffer_type

executor_type

The type of the executor associated with the object.

rebind_executor

Rebinds the socket type to another executor.

Member Functions

Name

Description

append

Appends a string to the pending input data.

async_read_some

Start an asynchronous read.

async_write_some

Start an asynchronous write.

basic_stream [constructor]

Move Constructor.

Construct a stream.

buffer

Direct input buffer access.

clear

Clear the pending input area.

close

Close the stream.

close_remote

Close the other end of the stream.

connect

Establish a connection.

get_executor

Return the executor associated with the object.

nread

Return the number of reads.

nread_bytes

Return the number of bytes read.

nwrite

Return the number of writes.

nwrite_bytes

Return the number of bytes written.

operator=

Move Assignment.

operator==

read_size

Set the maximum number of bytes returned by read_some.

read_some

Read some data from the stream.

str

Returns a string view representing the pending input data.

write_size

Set the maximum number of bytes returned by write_some.

write_some

Write some data to the stream.

~basic_stream [destructor]

Destructor.

Description

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:

Thread Safety

Distinctobjects:Safe.

Sharedobjects:Unsafe. The application must also ensure that all asynchronous operations are performed within the same implicit or explicit strand.


PrevUpHomeNext