Common buffer protocol class.
More...
#include <protocols.h>
|
enum | mode_t { RDONLY,
WRONLY,
RDWR
} |
|
|
const char * | endl (void) const |
|
bool | eof (void) |
| Check if at end of input. More...
|
|
int | err (void) const |
|
bool | flush (void) |
| Flush buffered memory to physical I/O. More...
|
|
size_t | get (void *address, size_t count) |
| Get memory from the buffer. More...
|
|
bool | is_input (void) const |
| See if input active. More...
|
|
bool | is_open (void) const |
| See if buffer open. More...
|
|
bool | is_output (void) const |
| See if output active. More...
|
|
bool | is_pending (void) |
| See if pending input. More...
|
|
| operator bool () const |
| See if buffer open. More...
|
|
bool | operator! () const |
| See if buffer closed. More...
|
|
size_t | printf (const char *format,...) |
| Print formatted string to the buffer. More...
|
|
void | purge (void) |
| Purge any pending input or output buffer data.
|
|
size_t | put (const void *address, size_t count) |
| Put memory into the buffer. More...
|
|
template<typename T > |
size_t | read (T &data) |
|
template<typename T > |
size_t | read (T *data, unsigned count) |
|
void | reset (void) |
| Reset input buffer state. More...
|
|
void | seteof (void) |
| Set eof flag.
|
|
template<typename T > |
size_t | write (const T &data) |
|
template<typename T > |
size_t | write (const T *data, unsigned count) |
|
int | getchar (void) |
| Get the next character. More...
|
|
size_t | getline (char *string, size_t size) |
| Get text as a line of input from the buffer. More...
|
|
size_t | getline (String &buffer) |
| Get a string as a line of input from the buffer. More...
|
|
size_t | input (InputProtocol &format) |
|
size_t | load (StringPager *list) |
| Load input to a string list. More...
|
|
size_t | print (const PrintProtocol &format) |
|
int | putchar (int code) |
| Put the next character. More...
|
|
size_t | putchars (const char *string, size_t count=0) |
|
size_t | putline (const char *string) |
| Put a string as a line of output to the buffer. More...
|
|
size_t | save (const StringPager *list) |
| Save output from a string list. More...
|
|
|
virtual bool | _blocking (void) |
| Return true if blocking.
|
|
virtual void | _clear (void)=0 |
| Method to clear low level i/o error.
|
|
virtual int | _err (void) const =0 |
| Method to get low level i/o error. More...
|
|
virtual bool | _flush (void) |
| Flush buffer to physical i/o.
|
|
virtual int | _getch (void) |
| Get the next character. More...
|
|
virtual bool | _pending (void) |
| Check if data is pending.
|
|
virtual size_t | _pull (char *address, size_t size)=0 |
| Method to pull buffer from physical i/o (read). More...
|
|
virtual size_t | _push (const char *address, size_t size)=0 |
| Method to push buffer into physical i/o (write). More...
|
|
virtual int | _putch (int ch) |
| Put the next character. More...
|
|
void | allocate (size_t size, mode_t access=RDWR) |
| Allocate I/O buffer(s) of specified size. More...
|
|
| BufferProtocol () |
| Construct an empty (unallocated) buffer.
|
|
| BufferProtocol (size_t size, mode_t access=RDWR) |
| Construct a buffer of pre-allocated size and access type. More...
|
|
virtual void | fault (void) const |
| Allocation error handler.
|
|
char * | gather (size_t size) |
| Gather returns a pointer to contiguous input of specified size. More...
|
|
size_t | input_pending (void) const |
| Get current input position. More...
|
|
size_t | output_waiting (void) const |
| Get current output position. More...
|
|
void | release (void) |
| Release (free) buffer memory.
|
|
char * | request (size_t size) |
| Request workspace in output buffer. More...
|
|
virtual | ~BufferProtocol () |
| Destroy object by releasing buffer memory.
|
|
void | putback (int code) |
| Write to back buffer. More...
|
|
void | seteol (const char *string) |
| Set end of line marker. More...
|
|
|
const char * | format |
|
int | back |
|
const char * | eol |
|
Common buffer protocol class.
This is used to create objects which will stream character data as needed. This class can support bidirectional streaming as may be needed for serial devices, sockets, and pipes. The buffering mechanisms are hidden from derived classes, and two virtuals are used to communicate with the physical transport.
- Author
- David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org
Definition at line 292 of file protocols.h.
ucommon::BufferProtocol::BufferProtocol |
( |
size_t |
size, |
|
|
mode_t |
access = RDWR |
|
) |
| |
|
protected |
Construct a buffer of pre-allocated size and access type.
- Parameters
-
size | of buffer to allocate. |
access | mode of buffer. |
virtual int ucommon::BufferProtocol::_err |
( |
void |
| ) |
const |
|
protectedpure virtual |
Method to get low level i/o error.
- Returns
- error from low level i/o methods.
Implemented in ucommon::TCPBuffer.
virtual int ucommon::BufferProtocol::_getch |
( |
void |
| ) |
|
|
protectedvirtual |
virtual size_t ucommon::BufferProtocol::_pull |
( |
char * |
address, |
|
|
size_t |
size |
|
) |
| |
|
protectedpure virtual |
Method to pull buffer from physical i/o (read).
The address is passed to this virtual since it is hidden as private.
- Parameters
-
address | of buffer to pull data into. |
size | of buffer area being pulled.. |
- Returns
- number of read written, 0 on error or end of data.
Implemented in ucommon::SSLBuffer, and ucommon::TCPBuffer.
virtual size_t ucommon::BufferProtocol::_push |
( |
const char * |
address, |
|
|
size_t |
size |
|
) |
| |
|
protectedpure virtual |
Method to push buffer into physical i/o (write).
The address is passed to this virtual since it is hidden as private.
- Parameters
-
address | of data to push. |
size | of data to push. |
- Returns
- number of bytes written, 0 on error.
Implemented in ucommon::SSLBuffer, and ucommon::TCPBuffer.
virtual int ucommon::BufferProtocol::_putch |
( |
int |
code | ) |
|
|
protectedvirtual |
void ucommon::BufferProtocol::allocate |
( |
size_t |
size, |
|
|
mode_t |
access = RDWR |
|
) |
| |
|
protected |
Allocate I/O buffer(s) of specified size.
If a buffer is currently allocated, it is released.
- Parameters
-
size | of buffer to allocate. |
access | mode of buffer. |
bool ucommon::BufferProtocol::eof |
( |
void |
| ) |
|
Check if at end of input.
- Returns
- true if end of data, false if input still buffered.
bool ucommon::BufferProtocol::flush |
( |
void |
| ) |
|
|
inline |
Flush buffered memory to physical I/O.
- Returns
- true on success, false if not active or fails.
Definition at line 454 of file protocols.h.
char* ucommon::BufferProtocol::gather |
( |
size_t |
size | ) |
|
|
protected |
Gather returns a pointer to contiguous input of specified size.
This may require moving the input data in memory.
- Parameters
-
- Returns
- data pointer to gathered data or NULL if not available.
size_t ucommon::BufferProtocol::get |
( |
void * |
address, |
|
|
size_t |
count |
|
) |
| |
Get memory from the buffer.
- Parameters
-
address | of characters save from buffer. |
count | of characters to get from buffer. |
- Returns
- number of characters actually copied.
size_t ucommon::BufferProtocol::input_pending |
( |
void |
| ) |
const |
|
inlineprotected |
Get current input position.
Sometimes used to help compute and report a "tell" offset.
- Returns
- offset of input buffer.
Definition at line 411 of file protocols.h.
bool ucommon::BufferProtocol::is_input |
( |
void |
| ) |
const |
|
inline |
See if input active.
- Returns
- true if input active.
Definition at line 498 of file protocols.h.
bool ucommon::BufferProtocol::is_open |
( |
void |
| ) |
const |
|
inline |
See if buffer open.
- Returns
- true if buffer active.
Definition at line 491 of file protocols.h.
bool ucommon::BufferProtocol::is_output |
( |
void |
| ) |
const |
|
inline |
See if output active.
- Returns
- true if output active.
Definition at line 505 of file protocols.h.
bool ucommon::BufferProtocol::is_pending |
( |
void |
| ) |
|
|
inline |
See if pending input.
- Returns
- true if input pending.
Definition at line 512 of file protocols.h.
ucommon::BufferProtocol::operator bool |
( |
| ) |
const |
|
inline |
See if buffer open.
- Returns
- true if buffer active.
Definition at line 477 of file protocols.h.
bool ucommon::BufferProtocol::operator! |
( |
| ) |
const |
|
inline |
See if buffer closed.
- Returns
- true if buffer inactive.
Definition at line 484 of file protocols.h.
size_t ucommon::BufferProtocol::output_waiting |
( |
void |
| ) |
const |
|
inlineprotected |
Get current output position.
Sometimes used to help compute a "trunc" operation.
Definition at line 418 of file protocols.h.
size_t ucommon::BufferProtocol::printf |
( |
const char * |
format, |
|
|
|
... |
|
) |
| |
Print formatted string to the buffer.
The maximum output size is the buffer size, and the operation flushes the buffer.
- Parameters
-
- Returns
- number of bytes written.
size_t ucommon::BufferProtocol::put |
( |
const void * |
address, |
|
|
size_t |
count |
|
) |
| |
Put memory into the buffer.
If count is 0 then put as NULL terminated string.
- Parameters
-
address | of characters to put into buffer. |
count | of characters to put into buffer. |
- Returns
- number of characters actually written.
char* ucommon::BufferProtocol::request |
( |
size_t |
size | ) |
|
|
protected |
Request workspace in output buffer.
This returns a pointer to memory from the output buffer and advances the output position. This is sometimes used for a form of zero copy write.
- Parameters
-
- Returns
- data pointer or NULL if not available.
void ucommon::BufferProtocol::reset |
( |
void |
| ) |
|
Reset input buffer state.
Drops any pending input.
The documentation for this class was generated from the following file: