dodo  0.0.1
A C++ library to create containerized Linux services
dodo::network::SocketReadBuffer Class Reference

SocketReadBuffer is a VirtualReadBuffer that reads from the BaseSocket in chunks internally. More...

#include <socketreadbuffer.hpp>

Inheritance diagram for dodo::network::SocketReadBuffer:
Collaboration diagram for dodo::network::SocketReadBuffer:

Public Member Functions

 SocketReadBuffer (BaseSocket *socket, size_t bufsize=8192)
 Construct a SocketReadBuffer. More...
 
virtual ~SocketReadBuffer ()
 Destruct the SocketReadBuffer, de-allocate the internal buffer. More...
 
virtual char get () const
 Get the current char from VirtualReadBuffer. More...
 
virtual common::SystemError next ()
 Move to the next char from the VirtualReadBuffer. More...
 
virtual common::SystemError underflow ()
 If the buffer_ is fully read. More...
 
- Public Member Functions inherited from dodo::network::VirtualReadBuffer
size_t getUnderflowCount () const
 Return the number of times underflow() was invoked. More...
 

Protected Attributes

ssize_t idx_
 The current index of get(char &c) in buffer_. More...
 
ssize_t received_
 The number of chars received in the last underflow(). More...
 
BaseSocketsocket_
 The associated network::BaseSocket*. More...
 
- Protected Attributes inherited from dodo::network::VirtualReadBuffer
char * buffer_
 The buffer. More...
 
ssize_t bufsize_
 The size of buffer_. More...
 
size_t underflows_
 The number underflow() invocations. More...
 

Detailed Description

SocketReadBuffer is a VirtualReadBuffer that reads from the BaseSocket in chunks internally.

Note that the BaseSocket should be in blocking mode.

Definition at line 99 of file socketreadbuffer.hpp.

Constructor & Destructor Documentation

◆ SocketReadBuffer()

dodo::network::SocketReadBuffer::SocketReadBuffer ( BaseSocket socket,
size_t  bufsize = 8192 
)
explicit

Construct a SocketReadBuffer.

If BaseSocket::getBlocking() is false, an exception is thrown.

Parameters
socketThe blocking BaseSocket to read from.
bufsizeThe buffer size to use

Definition at line 31 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_, dodo::network::VirtualReadBuffer::bufsize_, dodo::network::BaseSocket::getBlocking(), idx_, received_, socket_, and throw_Exception.

Here is the call graph for this function:

◆ ~SocketReadBuffer()

dodo::network::SocketReadBuffer::~SocketReadBuffer ( )
virtual

Destruct the SocketReadBuffer, de-allocate the internal buffer.

Any bytes buffered will be lost.

Definition at line 40 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_.

Member Function Documentation

◆ get()

char dodo::network::SocketReadBuffer::get ( ) const
virtual

Get the current char from VirtualReadBuffer.

Returns
The current character read.
See also
next()

Implements dodo::network::VirtualReadBuffer.

Definition at line 54 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_, and idx_.

◆ next()

common::SystemError dodo::network::SocketReadBuffer::next ( )
virtual

Move to the next char from the VirtualReadBuffer.

Note that call will return a SystemError::ecEAGAIN if there is no more data (received within the prevailing timeout).

Returns
SystemError::ecOK and c is valid, or an SystemError.

Implements dodo::network::VirtualReadBuffer.

Definition at line 58 of file socketreadbuffer.cpp.

References idx_, and underflow().

Here is the call graph for this function:

◆ underflow()

common::SystemError dodo::network::SocketReadBuffer::underflow ( )
virtual

If the buffer_ is fully read.

eset and read new data from the socket.

Returns
Systemerror::ecOK on succes.

Implements dodo::network::VirtualReadBuffer.

Definition at line 44 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_, dodo::network::VirtualReadBuffer::bufsize_, dodo::common::SystemError::ecOK, idx_, dodo::network::BaseSocket::receive(), received_, socket_, and dodo::network::VirtualReadBuffer::underflows_.

Referenced by next().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ idx_

ssize_t dodo::network::SocketReadBuffer::idx_
protected

The current index of get(char &c) in buffer_.

Definition at line 135 of file socketreadbuffer.hpp.

Referenced by get(), next(), SocketReadBuffer(), and underflow().

◆ received_

ssize_t dodo::network::SocketReadBuffer::received_
protected

The number of chars received in the last underflow().

Definition at line 140 of file socketreadbuffer.hpp.

Referenced by SocketReadBuffer(), and underflow().

◆ socket_

BaseSocket* dodo::network::SocketReadBuffer::socket_
protected

The associated network::BaseSocket*.

Definition at line 130 of file socketreadbuffer.hpp.

Referenced by SocketReadBuffer(), and underflow().


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