Loading...
Searching...
No Matches
ASSA::xdrIOBuffer Class Reference

`#include <xdrIOBuffer.h>`

## Public Types

enum | state_t { waiting , xmitted , parsed , error }

## Public Member Functions

| xdrIOBuffer (u_int len_)
| Constructor.
| ~xdrIOBuffer ()
| Destructor.
| xdrIOBuffer (const xdrIOBuffer &rhs_)
| Copy constructor.
xdrIOBuffer & | operator= (const xdrIOBuffer &rhs_)
| Assign operator.
xdrIOBuffer & | operator>> (std::string &)
| Read and XDR-decode STL string from the buffer.
xdrIOBuffer & | operator>> (int &)
| Read and XDR-decode an integer from the buffer.
xdrIOBuffer & | operator>> (float &)
| Read and XDR-decode a float from the buffer.
| operator void * () const
| Convertion to void* (for testing where bool is required).
string | get_state () const
| Give verbal interpretation of object's state.
int | size () const
| Return number of bytes in xdrIOBuffer.
int | buffer_size () const
| Return buffer (maximum expected/allowable) size.
const char * | str () const
| Return pointer to the first byte of xdrIOBuffer.
void | reset ()
| Clear up the internal buffer and reset state to waiting.
void | dump () const
| Dump object's internal state to the log file.

## Protected Member Functions

void | copy (const xdrIOBuffer &)
| Copy object from argument.

## Private Attributes

char * | m_buf
| Buffer.
int | m_sz
| Buffer size and maximum expected size.
char * | m_ptr
| Pointer for next I/O operation into the buffer.
state_t | m_state
| Object state.

## Friends

Socket & | operator>> (Socket &src_, xdrIOBuffer &dest_)
| Read raw data from Socket nonblocking and store into internal buffer.

## Detailed Description

Definition at line 55 of file xdrIOBuffer.h.

## Member Enumeration Documentation

## state_t

enum ASSA::xdrIOBuffer::state_t

Enumerator
waiting |
xmitted |
parsed |
error |

Definition at line 60 of file xdrIOBuffer.h.

{
waiting,
xmitted,
parsed,
error
};
ASSA::xdrIOBuffer::waiting
@ waiting
Definition xdrIOBuffer.h:61
ASSA::xdrIOBuffer::xmitted
@ xmitted
Definition xdrIOBuffer.h:62
ASSA::xdrIOBuffer::parsed
@ parsed
Definition xdrIOBuffer.h:63
ASSA::xdrIOBuffer::error
@ error
Definition xdrIOBuffer.h:64

## Constructor & Destructor Documentation

## xdrIOBuffer() [1/2]

xdrIOBuffer::xdrIOBuffer | ( | u_int | len_ | ) |

Constructor.

Definition at line 78 of file xdrIOBuffer.cpp.

: m_sz (sz_),
m_state (waiting)
{
trace_with_mask("xdrIOBuffer::xdrIOBuffer", XDRBUFTRACE);
m_buf = new char[sz_];
m_ptr = m_buf;
memset (m_buf, 0, m_sz);
DL((XDRBUF,"Allocated xdrIOBuffer [%d]\n",m_sz));
dump ();
}
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
ASSA::xdrIOBuffer::m_sz
int m_sz
Buffer size and maximum expected size.
Definition xdrIOBuffer.h:140
ASSA::xdrIOBuffer::m_ptr
char * m_ptr
Pointer for next I/O operation into the buffer.
Definition xdrIOBuffer.h:143
ASSA::xdrIOBuffer::m_state
state_t m_state
Object state.
Definition xdrIOBuffer.h:146
ASSA::xdrIOBuffer::m_buf
char * m_buf
Buffer.
Definition xdrIOBuffer.h:137
ASSA::xdrIOBuffer::dump
void dump() const
Dump object's internal state to the log file.
Definition xdrIOBuffer.cpp:225
ASSA::XDRBUF
@ XDRBUF
Class xdrIOBuffer messages.
Definition LogMask.h:43
ASSA::XDRBUFTRACE
@ XDRBUFTRACE
Extended xdrIOBuffer messages.
Definition LogMask.h:44

References DL, dump(), m_buf, m_ptr, m_state, m_sz, trace_with_mask, waiting, ASSA::XDRBUF, and ASSA::XDRBUFTRACE.

Referenced by copy(), operator=(), operator>>, and xdrIOBuffer().

## ~xdrIOBuffer()

xdrIOBuffer::~xdrIOBuffer | ( |  | ) |

Destructor.

Definition at line 92 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::~xdrIOBuffer", XDRBUFTRACE);
DL((XDRBUFTRACE,"xdrIOBuffer->this = 0x%x\n", long(this)));
delete [] m_buf;
}

References DL, m_buf, trace_with_mask, and ASSA::XDRBUFTRACE.

## xdrIOBuffer() [2/2]

ASSA::xdrIOBuffer::xdrIOBuffer | ( | const xdrIOBuffer & | rhs_ | ) |

inline

Copy constructor.

Definition at line 150 of file xdrIOBuffer.h.

{
trace_with_mask("xdrIOBuffer::xdrIOBuffer(xdrIOBuffer&)", XDRBUFTRACE);
copy (rhs_);
}
ASSA::xdrIOBuffer::copy
void copy(const xdrIOBuffer &)
Copy object from argument.
Definition xdrIOBuffer.cpp:113

References copy(), trace_with_mask, ASSA::XDRBUFTRACE, and xdrIOBuffer().

## Member Function Documentation

## buffer_size()

int ASSA::xdrIOBuffer::buffer_size | ( |  | ) | const

inline

Return buffer (maximum expected/allowable) size.

Definition at line 177 of file xdrIOBuffer.h.

{
return (m_sz);
}

References m_sz.

## copy()

void xdrIOBuffer::copy | ( | const xdrIOBuffer & | rhs_ | ) |

protected

Copy object from argument.

Definition at line 112 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::copy", XDRBUFTRACE);
m_sz = rhs_.m_sz;
m_buf = new char[m_sz];
memcpy (m_buf, rhs_.m_buf, m_sz);
m_ptr = m_buf + (rhs_.size ());
m_state = rhs_.m_state;
}
ASSA::xdrIOBuffer::size
int size() const
Return number of bytes in xdrIOBuffer.
Definition xdrIOBuffer.h:171

References m_buf, m_ptr, m_state, m_sz, size(), trace_with_mask, ASSA::XDRBUFTRACE, and xdrIOBuffer().

Referenced by operator=(), and xdrIOBuffer().

## dump()

void xdrIOBuffer::dump | ( |  | ) | const

Dump object's internal state to the log file.

Definition at line 224 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::dump", XDRBUFTRACE);
DL((XDRBUFTRACE,"xdrIOBuffer->this = 0x%x\n", long(this) ));
DL((XDRBUFTRACE,"\n\n" \
"\tm_buf ........: 0x%x \n" \
"\tm_sz .........: %d \n" \
"\tm_ptr ........: 0x%x \n" \
"\tbytes left ...: %d \n" \
"\tm_state ......: %s \n\n",
long (m_buf), m_sz, long (m_ptr),(m_sz - size ()),
get_state ().c_str ()));
if (m_ptr != m_buf) {
MemDump image (m_buf, size ());
DL((XDRBUFTRACE,"Bytes in buffer so far:\n\n%s\n\n",
image.getMemDump () ));
}
else if (m_ptr == m_buf && m_state == xmitted) {
MemDump image (m_buf, (m_sz));
DL((XDRBUFTRACE,"Complete buffer:\n\n%s\n\n",
image.getMemDump () ));
}
else {
DL((XDRBUFTRACE,"Empty buffer\n" ));
}
}
ASSA::xdrIOBuffer::get_state
string get_state() const
Give verbal interpretation of object's state.
Definition xdrIOBuffer.cpp:210

References DL, get_state(), ASSA::MemDump::getMemDump(), m_buf, m_ptr, m_state, m_sz, size(), trace_with_mask, ASSA::XDRBUFTRACE, and xmitted.

Referenced by operator>>, and xdrIOBuffer().

## get_state()

string xdrIOBuffer::get_state | ( |  | ) | const

Give verbal interpretation of object's state.

Definition at line 209 of file xdrIOBuffer.cpp.

{
string msg;
switch (m_state)
{
case xdrIOBuffer::waiting: msg = "waiting"; break;
case xdrIOBuffer::xmitted: msg = "xmitted"; break;
case xdrIOBuffer::parsed: msg = "parsed"; break;
case xdrIOBuffer::error: msg = "error"; break;
}
return msg;
}

References error, m_state, parsed, waiting, and xmitted.

Referenced by dump(), operator>>(), operator>>(), operator>>, and operator>>().

## operator void *()

ASSA::xdrIOBuffer::operator void * | ( |  | ) | const

inline

Convertion to void* (for testing where bool is required).

Definition at line 159 of file xdrIOBuffer.h.

{
trace_with_mask("xdrIOBuffer::opt void*()", XDRBUFTRACE);
return (m_state == waiting || m_state == parsed)
? (void *)0 // bad state
: (void *)(-1); // good state
}

References m_state, parsed, trace_with_mask, waiting, and ASSA::XDRBUFTRACE.

## operator=()

xdrIOBuffer & xdrIOBuffer::operator= | ( | const xdrIOBuffer & | rhs_ | ) |

Assign operator.

Definition at line 102 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::operator=()", XDRBUFTRACE);
delete [] m_buf;
copy (rhs_);
return *this;
}

References copy(), m_buf, trace_with_mask, ASSA::XDRBUFTRACE, and xdrIOBuffer().

## operator>>() [1/3]

xdrIOBuffer & xdrIOBuffer::operator>> | ( | float & | n_ | ) |

Read and XDR-decode a float from the buffer.

Definition at line 174 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::operator>>(float)", XDRBUFTRACE);
if (m_state != xmitted) {
EL((ASSAERR,"Wrong state: %s\n", get_state ().c_str () ));
return *this;
}
float val;
int unit_sz = sizeof (float);
memcpy ((char*) &val, m_ptr, unit_sz);
m_ptr += unit_sz;
XDR xdrs;
xdrmem_create (&xdrs, (caddr_t) &val, unit_sz, XDR_DECODE);
xdr_float (&xdrs, &n_);
xdr_destroy (&xdrs);
if (size () == m_sz)
m_state = parsed;
return *this;
}
EL
#define EL(X)
A macro for writing error message to the Logger.
Definition Logger.h:285
ASSA::ASSAERR
@ ASSAERR
ASSA and system errors.
Definition LogMask.h:34

References ASSA::ASSAERR, EL, get_state(), m_ptr, m_state, m_sz, parsed, size(), trace_with_mask, ASSA::XDRBUFTRACE, and xmitted.

## operator>>() [2/3]

xdrIOBuffer & xdrIOBuffer::operator>> | ( | int & | n_ | ) |

Read and XDR-decode an integer from the buffer.

Definition at line 125 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::operator>>(int)", XDRBUFTRACE);
if (m_state != xmitted) {
EL((ASSAERR,"Wrong state: %s\n", get_state ().c_str () ));
return *this;
}
int val;
int unit_sz = sizeof (int);
memcpy ((char*) &val, m_ptr, unit_sz);
m_ptr += unit_sz;
n_ = (int) ntohl (val);
if (size () == m_sz)
m_state = parsed;
return *this;
}

References ASSA::ASSAERR, EL, get_state(), m_ptr, m_state, m_sz, parsed, size(), trace_with_mask, ASSA::XDRBUFTRACE, and xmitted.

## operator>>() [3/3]

xdrIOBuffer & xdrIOBuffer::operator>> | ( | std::string & | s_ | ) |

Read and XDR-decode STL string from the buffer.

XDR format for STL string is described in Socket::operator<< comments.

Definition at line 147 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::operator>>(string)", XDRBUFTRACE);
if (m_state != xmitted) {
EL((ASSAERR,"Wrong state: %s\n", get_state ().c_str () ));
return *this;
}
s_ = "";
u_long len = (u_long) *m_ptr;
char* cptr = m_ptr + 4;
while (len--) {
s_ += *cptr++;
}
m_ptr += Socket::xdr_length (s_);
if (size () == m_sz) {
m_state = parsed;
}
return *this;
}
u_long
unsigned long u_long
Definition Logger_Impl.h:41
ASSA::Socket::xdr_length
static size_t xdr_length(const std::string &s_)
Give the true length of the XDR-encoded STL string.
Definition Socket.h:343

References ASSA::ASSAERR, EL, get_state(), m_ptr, m_state, m_sz, parsed, size(), trace_with_mask, ASSA::Socket::xdr_length(), ASSA::XDRBUFTRACE, and xmitted.

## reset()

void xdrIOBuffer::reset | ( |  | ) |

Clear up the internal buffer and reset state to waiting.

Definition at line 199 of file xdrIOBuffer.cpp.

{
trace_with_mask("xdrIOBuffer::reset", XDRBUFTRACE);
m_ptr = m_buf;
memset (m_buf, 0, m_sz);
m_state = waiting;
}

References m_buf, m_ptr, m_state, m_sz, trace_with_mask, waiting, and ASSA::XDRBUFTRACE.

## size()

int ASSA::xdrIOBuffer::size | ( |  | ) | const

inline

Return number of bytes in xdrIOBuffer.

In waiting state it's bytes transmitted so far. In xmitted state, number of bytes left to decode.

Definition at line 170 of file xdrIOBuffer.h.

{
return (m_ptr - m_buf);
}

References m_buf, and m_ptr.

Referenced by copy(), dump(), operator>>(), operator>>(), operator>>, and operator>>().

## str()

const char * ASSA::xdrIOBuffer::str | ( |  | ) | const

inline

Return pointer to the first byte of xdrIOBuffer.

Definition at line 184 of file xdrIOBuffer.h.

{
return ((const char*) m_buf);
}

References m_buf.

## Friends And Related Symbol Documentation

## operator>>

Socket & operator>> | ( | Socket & | src_,
|  | xdrIOBuffer & | dest_ )

friend

Read raw data from Socket nonblocking and store into internal buffer.

Definition at line 25 of file xdrIOBuffer.cpp.

{
trace_with_mask("Socket >> xdrIOBuffer", XDRBUFTRACE);
DL((XDRBUFTRACE,"Buffer Initially:\n"));
b_.dump ();
if (b_.m_state != xdrIOBuffer::waiting) {
EL((ASSAERR,"Wrong state: %s\n", b_.get_state ().c_str ()));
return s_;
}
int expected = b_.m_sz - b_.size ();
DL((XDRBUFTRACE,"Bytes expected: %d\n",expected));
DL((XDRBUFTRACE,"Bytes in Socket buffer(s): %d\n", s_.getBytesAvail ()));
int ret;
if ((ret = s_.read (b_.m_ptr, expected)) <= 0)
{
#if defined(WIN32)
if (WSAGetLastError () != WSAEWOULDBLOCK) {
WSASetLastError (0);
EL((ASSAERR,"Socket::read() error!\n"));
b_.m_state = xdrIOBuffer::error;
}
#else
if (errno != EWOULDBLOCK) {
EL((ASSAERR,"Socket::read() error!\n"));
b_.m_state = xdrIOBuffer::error;
}
#endif
else {
EL((ASSAERR,"Socket::read() error! \n"));
}
return s_;
}
b_.m_ptr += ret;
DL((XDRBUFTRACE,"Received %d bytes\n", ret));
b_.dump ();
if (b_.m_sz == b_.size ()) { // at the end
DL((XDRBUFTRACE,"Complete message is in the buffer!\n"));
b_.m_state = xdrIOBuffer::xmitted;
b_.m_ptr = b_.m_buf; // rewind m_ptr for parsing stage
b_.dump ();
}
return s_;
}

References ASSA::ASSAERR, DL, dump(), EL, error, get_state(), ASSA::Socket::getBytesAvail(), m_buf, m_ptr, m_state, m_sz, ASSA::Socket::read(), size(), trace_with_mask, waiting, ASSA::XDRBUFTRACE, xdrIOBuffer(), and xmitted.

## Member Data Documentation

## m_buf

char* ASSA::xdrIOBuffer::m_buf

private

Buffer.

Definition at line 137 of file xdrIOBuffer.h.

Referenced by copy(), dump(), operator=(), operator>>, reset(), size(), str(), xdrIOBuffer(), and ~xdrIOBuffer().

## m_ptr

char* ASSA::xdrIOBuffer::m_ptr

private

Pointer for next I/O operation into the buffer.

Definition at line 143 of file xdrIOBuffer.h.

Referenced by copy(), dump(), operator>>(), operator>>(), operator>>, operator>>(), reset(), size(), and xdrIOBuffer().

## m_state

state_t ASSA::xdrIOBuffer::m_state

private

Object state.

Definition at line 146 of file xdrIOBuffer.h.

Referenced by copy(), dump(), get_state(), operator void *(), operator>>(), operator>>(), operator>>, operator>>(), reset(), and xdrIOBuffer().

## m_sz

int ASSA::xdrIOBuffer::m_sz

private

Buffer size and maximum expected size.

Definition at line 140 of file xdrIOBuffer.h.

Referenced by buffer_size(), copy(), dump(), operator>>(), operator>>(), operator>>, operator>>(), reset(), and xdrIOBuffer().

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

- xdrIOBuffer.h
- xdrIOBuffer.cpp