#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 nonblocking and store into internal buffer. |
Definition at line 55 of file xdrIOBuffer.h.
|
Definition at line 60 of file xdrIOBuffer.h.
|
|
Constructor.
Definition at line 70 of file xdrIOBuffer.cpp. References DL, dump(), m_buf, m_ptr, m_sz, trace_with_mask, ASSA::XDRBUF, and ASSA::XDRBUFTRACE. 00071 : m_sz (sz_), 00072 m_state (waiting) 00073 { 00074 trace_with_mask("xdrIOBuffer::xdrIOBuffer", XDRBUFTRACE); 00075 00076 m_buf = new char[sz_]; 00077 m_ptr = m_buf; 00078 memset (m_buf, 0, m_sz); 00079 DL((XDRBUF,"Allocated xdrIOBuffer [%d]\n",m_sz)); 00080 dump (); 00081 }
|
|
Destructor.
Definition at line 84 of file xdrIOBuffer.cpp. References DL, m_buf, trace_with_mask, and ASSA::XDRBUFTRACE. 00085 { 00086 trace_with_mask("xdrIOBuffer::~xdrIOBuffer", XDRBUFTRACE); 00087 00088 DL((XDRBUFTRACE,"xdrIOBuffer->this = 0x%x\n", long(this))); 00089 delete [] m_buf; 00090 }
|
|
Copy constructor.
Definition at line 151 of file xdrIOBuffer.h. References copy(), trace_with_mask, and ASSA::XDRBUFTRACE. 00152 { 00153 trace_with_mask("xdrIOBuffer::xdrIOBuffer(xdrIOBuffer&)", XDRBUFTRACE); 00154 00155 copy (rhs_); 00156 }
|
|
Return buffer (maximum expected/allowable) size.
Definition at line 178 of file xdrIOBuffer.h. References m_sz. 00179 { 00180 return (m_sz); 00181 }
|
|
Copy object from argument.
Definition at line 104 of file xdrIOBuffer.cpp. References m_buf, m_ptr, m_state, m_sz, size(), trace_with_mask, and ASSA::XDRBUFTRACE. Referenced by operator=(), and xdrIOBuffer(). 00105 { 00106 trace_with_mask("xdrIOBuffer::copy", XDRBUFTRACE); 00107 00108 m_sz = rhs_.m_sz; 00109 m_buf = new char[m_sz]; 00110 memcpy (m_buf, rhs_.m_buf, m_sz); 00111 m_ptr = m_buf + (rhs_.size ()); 00112 m_state = rhs_.m_state; 00113 }
|
|
Dump object's internal state to the log file.
Definition at line 216 of file xdrIOBuffer.cpp. 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 ASSA::operator>>(), and xdrIOBuffer(). 00217 { 00218 trace_with_mask("xdrIOBuffer::dump", XDRBUFTRACE); 00219 00220 DL((XDRBUFTRACE,"xdrIOBuffer->this = 0x%x\n", long(this) )); 00221 DL((XDRBUFTRACE,"\n\n" \ 00222 "\tm_buf ........: 0x%x \n" \ 00223 "\tm_sz .........: %d \n" \ 00224 "\tm_ptr ........: 0x%x \n" \ 00225 "\tbytes left ...: %d \n" \ 00226 "\tm_state ......: %s \n\n", 00227 long (m_buf), m_sz, long (m_ptr),(m_sz - size ()), 00228 get_state ().c_str ())); 00229 00230 if (m_ptr != m_buf) { 00231 MemDump image (m_buf, size ()); 00232 DL((XDRBUFTRACE,"Bytes in buffer so far:\n\n%s\n\n", 00233 image.getMemDump () )); 00234 } 00235 else if (m_ptr == m_buf && m_state == xmitted) { 00236 MemDump image (m_buf, (m_sz)); 00237 DL((XDRBUFTRACE,"Complete buffer:\n\n%s\n\n", 00238 image.getMemDump () )); 00239 } 00240 else { 00241 DL((XDRBUFTRACE,"Empty buffer\n" )); 00242 } 00243 }
|
|
Give verbal interpretation of object's state.
Definition at line 201 of file xdrIOBuffer.cpp. References error, m_state, parsed, waiting, and xmitted. Referenced by dump(), operator>>(), and ASSA::operator>>(). 00202 { 00203 string msg; 00204 switch (m_state) 00205 { 00206 case xdrIOBuffer::waiting: msg = "waiting"; break; 00207 case xdrIOBuffer::xmitted: msg = "xmitted"; break; 00208 case xdrIOBuffer::parsed: msg = "parsed"; break; 00209 case xdrIOBuffer::error: msg = "error"; break; 00210 } 00211 return msg; 00212 }
|
|
Convertion to void* (for testing where bool is required).
Definition at line 160 of file xdrIOBuffer.h. References m_state, parsed, trace_with_mask, waiting, and ASSA::XDRBUFTRACE. 00161 { 00162 trace_with_mask("xdrIOBuffer::opt void*()", XDRBUFTRACE); 00163 00164 return (m_state == waiting || m_state == parsed) 00165 ? (void *)0 // bad state 00166 : (void *)(-1); // good state 00167 }
|
|
Assign operator.
Definition at line 93 of file xdrIOBuffer.cpp. References copy(), m_buf, trace_with_mask, and ASSA::XDRBUFTRACE. 00094 { 00095 trace_with_mask("xdrIOBuffer::operator=()", XDRBUFTRACE); 00096 00097 delete [] m_buf; 00098 copy (rhs_); 00099 return *this; 00100 }
|
|
Read and XDR-decode a float from the buffer.
Definition at line 166 of file xdrIOBuffer.cpp. References EL, ASSA::ERROR, get_state(), m_ptr, m_state, m_sz, parsed, size(), trace_with_mask, ASSA::XDRBUFTRACE, and xmitted. 00167 { 00168 trace_with_mask("xdrIOBuffer::operator>>(float)", XDRBUFTRACE); 00169 00170 if (m_state != xmitted) { 00171 EL((ERROR,"Wrong state: %s\n", get_state ().c_str () )); 00172 return *this; 00173 } 00174 float val; 00175 int unit_sz = sizeof (float); 00176 memcpy ((char*) &val, m_ptr, unit_sz); 00177 m_ptr += unit_sz; 00178 00179 XDR xdrs; 00180 xdrmem_create (&xdrs, (caddr_t) &val, unit_sz, XDR_DECODE); 00181 xdr_float (&xdrs, &n_); 00182 xdr_destroy (&xdrs); 00183 00184 if (size () == m_sz) 00185 m_state = parsed; 00186 return *this; 00187 }
|
|
Read and XDR-decode an integer from the buffer.
Definition at line 117 of file xdrIOBuffer.cpp. References EL, ASSA::ERROR, get_state(), m_ptr, m_state, m_sz, parsed, size(), trace_with_mask, ASSA::XDRBUFTRACE, and xmitted. 00118 { 00119 trace_with_mask("xdrIOBuffer::operator>>(int)", XDRBUFTRACE); 00120 00121 if (m_state != xmitted) { 00122 EL((ERROR,"Wrong state: %s\n", get_state ().c_str () )); 00123 return *this; 00124 } 00125 int val; 00126 int unit_sz = sizeof (int); 00127 memcpy ((char*) &val, m_ptr, unit_sz); 00128 m_ptr += unit_sz; 00129 00130 n_ = (int) ntohl (val); 00131 00132 if (size () == m_sz) 00133 m_state = parsed; 00134 return *this; 00135 }
|
|
Read and XDR-decode STL string from the buffer. XDR format for STL string is described in Socket::operator<< comments. Definition at line 139 of file xdrIOBuffer.cpp. References EL, ASSA::ERROR, get_state(), m_ptr, m_state, m_sz, parsed, size(), trace_with_mask, ASSA::Socket::xdr_length(), ASSA::XDRBUFTRACE, and xmitted. 00140 { 00141 trace_with_mask("xdrIOBuffer::operator>>(string)", XDRBUFTRACE); 00142 00143 if (m_state != xmitted) { 00144 EL((ERROR,"Wrong state: %s\n", get_state ().c_str () )); 00145 return *this; 00146 } 00149 s_ = ""; 00150 u_long len = (u_long) *m_ptr; 00151 char* cptr = m_ptr + 4; 00152 00153 while (len--) { 00154 s_ += *cptr++; 00155 } 00156 m_ptr += Socket::xdr_length (s_); 00157 00158 if (size () == m_sz) { 00159 m_state = parsed; 00160 } 00161 return *this; 00162 }
|
|
Clear up the internal buffer and reset state to waiting.
Definition at line 190 of file xdrIOBuffer.cpp. References m_buf, m_ptr, m_state, m_sz, trace_with_mask, waiting, and ASSA::XDRBUFTRACE. 00191 { 00192 trace_with_mask("xdrIOBuffer::reset", XDRBUFTRACE); 00193 00194 m_ptr = m_buf; 00195 memset (m_buf, 0, m_sz); 00196 m_state = waiting; 00197 }
|
|
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 171 of file xdrIOBuffer.h. Referenced by copy(), dump(), operator>>(), and ASSA::operator>>().
|
|
Return pointer to the first byte of xdrIOBuffer.
Definition at line 185 of file xdrIOBuffer.h. References m_buf. 00186 { 00187 return ((const char*) m_buf); 00188 }
|
|
Read raw data from nonblocking and store into internal buffer.
Definition at line 25 of file xdrIOBuffer.cpp. 00026 { 00027 trace_with_mask("Socket >> xdrIOBuffer", XDRBUFTRACE); 00028 00029 DL((XDRBUFTRACE,"Buffer Initially:\n")); 00030 b_.dump (); 00031 00032 if (b_.m_state != xdrIOBuffer::waiting) { 00033 EL((ERROR,"Wrong state: %s\n", b_.get_state ().c_str ())); 00034 return s_; 00035 } 00036 int expected = b_.m_sz - b_.size (); 00037 00038 DL((XDRBUFTRACE,"Bytes expected: %d\n",expected)); 00039 DL((XDRBUFTRACE,"Bytes in Socket buffer(s): %d\n", s_.getBytesAvail ())); 00040 int ret; 00041 00042 if ((ret = s_.read (b_.m_ptr, expected)) <= 0) { 00043 if (errno != EWOULDBLOCK) { 00044 EL((ERROR,"Socket::read() error!\n")); 00045 b_.m_state = xdrIOBuffer::error; 00046 } 00047 else { 00048 EL((ERROR,"Socket::read() error! \n")); 00049 } 00050 return s_; 00051 } 00052 b_.m_ptr += ret; 00053 00054 DL((XDRBUFTRACE,"Received %d bytes\n", ret)); 00055 b_.dump (); 00056 00057 if (b_.m_sz == b_.size ()) { // at the end 00058 DL((XDRBUFTRACE,"Complete message is in the buffer!\n")); 00059 b_.m_state = xdrIOBuffer::xmitted; 00060 b_.m_ptr = b_.m_buf; // rewind m_ptr for parsing stage 00061 b_.dump (); 00062 } 00063 return s_; 00064 }
|
|
Buffer.
Definition at line 137 of file xdrIOBuffer.h. Referenced by copy(), dump(), operator=(), ASSA::operator>>(), reset(), size(), str(), xdrIOBuffer(), and ~xdrIOBuffer(). |
|
Pointer for next I/O operation into the buffer.
Definition at line 143 of file xdrIOBuffer.h. Referenced by copy(), dump(), operator>>(), ASSA::operator>>(), reset(), size(), and xdrIOBuffer(). |
|
Object state.
Definition at line 146 of file xdrIOBuffer.h. Referenced by copy(), dump(), get_state(), operator void *(), operator>>(), ASSA::operator>>(), and reset(). |
|
Buffer size and maximum expected size.
Definition at line 140 of file xdrIOBuffer.h. Referenced by buffer_size(), copy(), dump(), operator>>(), ASSA::operator>>(), reset(), and xdrIOBuffer(). |