#include <protocols.h>
Public Types | |
enum | type_t { BUF_RD, BUF_WR, BUF_RDWR } |
Public Member Functions | |
int | _getch (void) |
Get a character from the buffer. | |
int | _putch (int ch) |
Put a character into the buffer. | |
bool | eof (void) |
Check if at end of input. | |
int | err (void) |
bool | flush (void) |
Flush buffered memory to physical I/O. | |
size_t | get (char *address, size_t count) |
Get memory from the buffer. | |
size_t | getline (string &buffer) |
Get a string as a line of input from the buffer. | |
size_t | getline (char *string, size_t size) |
Get text as a line of input from the buffer. | |
bool | is_input (void) |
See if input active. | |
bool | is_open (void) |
See if buffer open. | |
bool | is_output (void) |
See if output active. | |
bool | is_pending (void) |
See if pending input. | |
operator bool () | |
See if buffer open. | |
bool | operator! () |
See if buffer closed. | |
size_t | printf (const char *format,...) |
Print formatted string to the buffer. | |
void | purge (void) |
Purge any pending input or output buffer data. | |
size_t | put (const char *address, size_t count=0) |
Put memory into the buffer. | |
size_t | putline (const char *string) |
Put a string as a line of output to the buffer. | |
void | reset (void) |
Reset input buffer state. | |
void | seteof (void) |
Set eof flag. | |
Protected Member Functions | |
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. | |
virtual bool | _flush (void) |
Flush buffer to physical i/o. | |
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). | |
virtual size_t | _push (const char *address, size_t size)=0 |
Method to push buffer into physical i/o (write). | |
void | allocate (size_t size, type_t access=BUF_RDWR) |
Allocate I/O buffer(s) of specified size. | |
BufferProtocol (size_t size, type_t access=BUF_RDWR) | |
Construct a buffer of pre-allocated size and access type. | |
BufferProtocol () | |
Construct an empty (unallocated) buffer. | |
char * | gather (size_t size) |
Gather returns a pointer to contiguous input of specified size. | |
void | release (void) |
Release (free) buffer memory. | |
char * | request (size_t size) |
Request workspace in output buffer. | |
void | seteol (const char *string) |
Set end of line marker. | |
size_t | unread (void) |
Get current input position. | |
size_t | unsaved (void) |
Get current output position. | |
~BufferProtocol () | |
Destroy object by releasing buffer memory. | |
Protected Attributes | |
const char * | format |
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.
Definition at line 165 of file protocols.h.
ucc::BufferProtocol::BufferProtocol | ( | size_t | size, | |
type_t | access = BUF_RDWR | |||
) | [protected] |
Construct a buffer of pre-allocated size and access type.
size | of buffer to allocate. | |
access | mode of buffer. |
virtual int ucc::BufferProtocol::_err | ( | void | ) | const [protected, pure virtual] |
Method to get low level i/o error.
int ucc::BufferProtocol::_getch | ( | void | ) | [virtual] |
Get a character from the buffer.
If no data is available, return EOF.
Implements ucc::CharacterProtocol.
virtual size_t ucc::BufferProtocol::_pull | ( | char * | address, | |
size_t | size | |||
) | [protected, pure virtual] |
Method to pull buffer from physical i/o (read).
The address is passed to this virtual since it is hidden as private.
address | of buffer to pull data into. | |
size | of buffer area being pulled.. |
Implemented in ucc::fbuf, ucc::TCPBuffer, ucc::SSLBuffer, and ucc::shell::iobuf.
virtual size_t ucc::BufferProtocol::_push | ( | const char * | address, | |
size_t | size | |||
) | [protected, pure virtual] |
Method to push buffer into physical i/o (write).
The address is passed to this virtual since it is hidden as private.
address | of data to push. | |
size | of data to push. |
int ucc::BufferProtocol::_putch | ( | int | ch | ) | [virtual] |
Put a character into the buffer.
Implements ucc::CharacterProtocol.
void ucc::BufferProtocol::allocate | ( | size_t | size, | |
type_t | access = BUF_RDWR | |||
) | [protected] |
Allocate I/O buffer(s) of specified size.
If a buffer is currently allocated, it is released.
size | of buffer to allocate. | |
access | mode of buffer. |
bool ucc::BufferProtocol::eof | ( | void | ) |
Check if at end of input.
bool ucc::BufferProtocol::flush | ( | void | ) | [inline] |
Flush buffered memory to physical I/O.
Definition at line 340 of file protocols.h.
char* ucc::BufferProtocol::gather | ( | size_t | size | ) | [protected] |
size_t ucc::BufferProtocol::get | ( | char * | address, | |
size_t | count | |||
) |
Get memory from the buffer.
This method will become "get()" in abi 4 and may become a protected method.
address | of characters save from buffer. | |
count | of characters to get from buffer. |
size_t ucc::BufferProtocol::getline | ( | string & | buffer | ) |
Get a string as a line of input from the buffer.
The eol character(s) are used to mark the end of a line. Because the end of line character is stripped, the length of the string may be less than the actual count read. If at the end of the file buffer and unable to read more data an error occured then 0 is returned.
buffer | to save input into. |
size_t ucc::BufferProtocol::getline | ( | char * | string, | |
size_t | size | |||
) |
Get text as a line of input from the buffer.
The eol character(s) are used to mark the end of a line. Because the end of line character is stripped, the length of the string may be less than the actual count read. If at the end of the file buffer and unable to read more data an error occured then 0 is returned.
bool ucc::BufferProtocol::is_input | ( | void | ) | [inline] |
bool ucc::BufferProtocol::is_open | ( | void | ) | [inline] |
bool ucc::BufferProtocol::is_output | ( | void | ) | [inline] |
bool ucc::BufferProtocol::is_pending | ( | void | ) | [inline] |
ucc::BufferProtocol::operator bool | ( | ) | [inline] |
bool ucc::BufferProtocol::operator! | ( | ) | [inline] |
size_t ucc::BufferProtocol::printf | ( | const char * | format, | |
... | ||||
) |
size_t ucc::BufferProtocol::put | ( | const char * | address, | |
size_t | count = 0 | |||
) |
Put memory into the buffer.
If count is 0 then put as NULL terminated string. This method will become "put()" in abi 4 and may become a protected method.
address | of characters to put into buffer. | |
count | of characters to put into buffer. |
size_t ucc::BufferProtocol::putline | ( | const char * | string | ) |
char* ucc::BufferProtocol::request | ( | size_t | size | ) | [protected] |
void ucc::BufferProtocol::reset | ( | void | ) |
Reset input buffer state.
Drops any pending input.
void ucc::BufferProtocol::seteol | ( | const char * | string | ) | [inline, protected] |
Set end of line marker.
Normally this is set to cr & lf, which actually supports both lf alone and cr/lf termination of lines. However, putline() will always add the full cr/lf if this mode is used. This option only effects getline() and putline().
string | for eol for getline and putline. |
Definition at line 204 of file protocols.h.
size_t ucc::BufferProtocol::unread | ( | void | ) | [inline, protected] |
Get current input position.
Sometimes used to help compute and report a "tell" offset.
Definition at line 286 of file protocols.h.
size_t ucc::BufferProtocol::unsaved | ( | void | ) | [inline, protected] |
Get current output position.
Sometimes used to help compute a "trunc" operation.
Definition at line 293 of file protocols.h.