qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::stream< _IO_ > Class Template Reference

Combined input/output stream template class. More...

#include <stream.h>

Inheritance diagram for qb::io::stream< _IO_ >:
Collaboration diagram for qb::io::stream< _IO_ >:

Public Types

using transport_io_type = _IO_
 Type of the underlying transport IO.
using output_buffer_type = qb::allocator::pipe<char>
 Type of the output buffer.
Public Types inherited from qb::io::istream< _IO_ >
using transport_io_type = _IO_
 Type of the underlying transport IO.
using input_buffer_type = qb::allocator::pipe<char>
 Type of the input buffer.

Public Member Functions

output_buffer_typeout () noexcept
 Get the output buffer.
std::size_t pendingWrite () const noexcept
 Get the number of bytes pending for writing.
template<typename Available = void>
int write (std::enable_if_t< has_method_write< _IO_, int, const char *, std::size_t >::value, Available > *=nullptr) noexcept
 Write data from the output buffer to the transport.
char * publish (char const *data, std::size_t size) noexcept
 Add data to the output buffer for later writing.
void close () noexcept
 Close the stream.
Public Member Functions inherited from qb::io::istream< _IO_ >
 ~istream () noexcept
 Destructor.
_IO_ & transport () noexcept
 Get the underlying transport object.
const _IO_ & transport () const noexcept
 Get the underlying transport object (const version)
input_buffer_typein () noexcept
 Get the input buffer.
std::size_t pendingRead () const noexcept
 Get the number of bytes available for reading.
template<typename Available = void>
int read (std::enable_if_t< has_method_read< _IO_, int, char *, std::size_t >::value, Available > *=nullptr) noexcept
 Read data from the transport into the input buffer.
void flush (std::size_t size) noexcept
 Remove data from the front of the input buffer.
void eof () noexcept
 Handle end-of-file condition.
void close () noexcept
 Close the stream.

Static Public Attributes

static constexpr const bool has_reset_on_pending_read = false
 Flag indicating whether the implementation resets pending reads.

Protected Attributes

output_buffer_type _out_buffer
 Buffer for outgoing data.
Protected Attributes inherited from qb::io::istream< _IO_ >
_IO_ _in
 The underlying IO object.
input_buffer_type _in_buffer
 Buffer for incoming data.

Detailed Description

template<typename _IO_>
class qb::io::stream< _IO_ >

Combined input/output stream template class.

This template class provides both input and output stream functionality for various transport implementations. It inherits from istream for input operations and adds output buffer management and writing methods.

This is the primary base class for most transport implementations in the library.

Template Parameters
_IO_The IO type that implements the actual transport operations

Member Function Documentation

◆ out()

template<typename _IO_>
output_buffer_type & qb::io::stream< _IO_ >::out ( )
inlinenodiscardnoexcept

Get the output buffer.

Returns
Reference to the output buffer

◆ pendingWrite()

template<typename _IO_>
std::size_t qb::io::stream< _IO_ >::pendingWrite ( ) const
inlinenodiscardnoexcept

Get the number of bytes pending for writing.

Returns
Number of bytes in the output buffer

◆ write()

template<typename _IO_>
template<typename Available = void>
int qb::io::stream< _IO_ >::write ( std::enable_if_t< has_method_write< _IO_, int, const char *, std::size_t >::value, Available > * = nullptr)
inlinenodiscardnoexcept

Write data from the output buffer to the transport.

Returns
Number of bytes written on success, error code on failure

This method is enabled only if the IO type has a compatible write method. It writes the entire buffer content and adjusts or resets the buffer based on the actual number of bytes written.

Note that this implementation uses the input IO object (_in) for writing, which is suitable for bidirectional transports like sockets.

◆ publish()

template<typename _IO_>
char * qb::io::stream< _IO_ >::publish ( char const * data,
std::size_t size )
inlinenoexcept

Add data to the output buffer for later writing.

Parameters
dataPointer to the data to add
sizeSize of the data to add
Returns
Pointer to the copied data in the output buffer

Copies the specified data to the output buffer for later transmission by the write method.

◆ close()

template<typename _IO_>
void qb::io::stream< _IO_ >::close ( )
inlinenoexcept

Close the stream.

Resets the output buffer and closes the underlying input stream.

Member Data Documentation

◆ has_reset_on_pending_read

template<typename _IO_>
const bool qb::io::stream< _IO_ >::has_reset_on_pending_read = false
staticconstexpr

Flag indicating whether the implementation resets pending reads.

This flag is used by derived classes to indicate if they need special handling for pending read operations. Default is false.