dodo
0.0.1
A C++ library to create containerized Linux services
|
SocketReadBuffer is a VirtualReadBuffer that reads from the BaseSocket in chunks internally. More...
#include <socketreadbuffer.hpp>
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... | |
![]() | |
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... | |
BaseSocket * | socket_ |
The associated network::BaseSocket*. More... | |
![]() | |
char * | buffer_ |
The buffer. More... | |
ssize_t | bufsize_ |
The size of buffer_. More... | |
size_t | underflows_ |
The number underflow() invocations. More... | |
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.
|
explicit |
Construct a SocketReadBuffer.
If BaseSocket::getBlocking() is false, an exception is thrown.
socket | The blocking BaseSocket to read from. |
bufsize | The 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.
|
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_.
|
virtual |
Get the current char from VirtualReadBuffer.
Implements dodo::network::VirtualReadBuffer.
Definition at line 54 of file socketreadbuffer.cpp.
References dodo::network::VirtualReadBuffer::buffer_, and idx_.
|
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).
Implements dodo::network::VirtualReadBuffer.
Definition at line 58 of file socketreadbuffer.cpp.
References idx_, and underflow().
|
virtual |
If the buffer_ is fully read.
eset and read new data from the socket.
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().
|
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().
|
protected |
The number of chars received in the last underflow().
Definition at line 140 of file socketreadbuffer.hpp.
Referenced by SocketReadBuffer(), and underflow().
|
protected |
The associated network::BaseSocket*.
Definition at line 130 of file socketreadbuffer.hpp.
Referenced by SocketReadBuffer(), and underflow().