dodo  0.0.1
A C++ library to create containerized Linux services
dodo::network::VirtualReadBuffer Class Referenceabstract

Interface to read individual bytes whilst the implementation can read from an actual source (such as a network buffer) in larger chunks, reducing the number of required system calls. More...

#include <socketreadbuffer.hpp>

Inheritance diagram for dodo::network::VirtualReadBuffer:
Collaboration diagram for dodo::network::VirtualReadBuffer:

Public Member Functions

virtual char get () const =0
 Get the current char from VirtualReadBuffer. More...
 
size_t getUnderflowCount () const
 Return the number of times underflow() was invoked. More...
 
virtual common::SystemError next ()=0
 Move to the next char from the VirtualReadBuffer. More...
 
virtual common::SystemError underflow ()=0
 If the buffer_ underflows, the buffer_ must be reset refilledwith new data from the source. More...
 

Protected Attributes

char * buffer_
 The buffer. More...
 
ssize_t bufsize_
 The size of buffer_. More...
 
size_t underflows_
 The number underflow() invocations. More...
 

Detailed Description

Interface to read individual bytes whilst the implementation can read from an actual source (such as a network buffer) in larger chunks, reducing the number of required system calls.

This is covenient when implementing protocols that need be char (byte) scanned to parse.

Note that this interface requires a source that blocks on read. A call to next() will advance the current byte, but this in turn will call underflow, which in turn might do a read if it reached the end of available bytes.

See also
SocketReadBuffer and FileReadBuffer - both concrete implementations.

Definition at line 44 of file socketreadbuffer.hpp.

Member Function Documentation

◆ get()

◆ getUnderflowCount()

size_t dodo::network::VirtualReadBuffer::getUnderflowCount ( ) const
inline

Return the number of times underflow() was invoked.

Returns
The number of times underflow() was invoked.

Definition at line 73 of file socketreadbuffer.hpp.

References underflows_.

◆ next()

◆ underflow()

virtual common::SystemError dodo::network::VirtualReadBuffer::underflow ( )
pure virtual

If the buffer_ underflows, the buffer_ must be reset refilledwith new data from the source.

Returns
Systemerror::ecOK on succes.

Implemented in dodo::network::StringReadBuffer, dodo::network::FileReadBuffer, and dodo::network::SocketReadBuffer.

Field Documentation

◆ buffer_

◆ bufsize_

ssize_t dodo::network::VirtualReadBuffer::bufsize_
protected

◆ underflows_

size_t dodo::network::VirtualReadBuffer::underflows_
protected

The documentation for this class was generated from the following file: