#include <string.h>
#include <errno.h>
#include "assa/MemDump.h"
#include "assa/xdrIOBuffer.h"
#include "assa/XDRHack.h"
Go to the source code of this file.
Namespaces | |
namespace | ASSA |
Functions | |
Socket & | operator>> (Socket &s_, xdrIOBuffer &b_) |
|
Definition at line 25 of file xdrIOBuffer.cpp. References ASSA::ASSAERR, DL, ASSA::xdrIOBuffer::dump(), EL, ASSA::xdrIOBuffer::error, ASSA::xdrIOBuffer::get_state(), ASSA::Socket::getBytesAvail(), ASSA::xdrIOBuffer::m_buf, ASSA::xdrIOBuffer::m_ptr, ASSA::xdrIOBuffer::m_state, ASSA::xdrIOBuffer::m_sz, ASSA::Socket::read(), ASSA::xdrIOBuffer::size(), trace_with_mask, ASSA::xdrIOBuffer::waiting, ASSA::XDRBUFTRACE, and ASSA::xdrIOBuffer::xmitted. 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((ASSAERR,"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 { 00044 #if defined(WIN32) 00045 if (WSAGetLastError () != WSAEWOULDBLOCK) { 00046 WSASetLastError (0); 00047 EL((ASSAERR,"Socket::read() error!\n")); 00048 b_.m_state = xdrIOBuffer::error; 00049 } 00050 #else 00051 if (errno != EWOULDBLOCK) { 00052 EL((ASSAERR,"Socket::read() error!\n")); 00053 b_.m_state = xdrIOBuffer::error; 00054 } 00055 #endif 00056 else { 00057 EL((ASSAERR,"Socket::read() error! \n")); 00058 } 00059 return s_; 00060 } 00061 b_.m_ptr += ret; 00062 00063 DL((XDRBUFTRACE,"Received %d bytes\n", ret)); 00064 b_.dump (); 00065 00066 if (b_.m_sz == b_.size ()) { // at the end 00067 DL((XDRBUFTRACE,"Complete message is in the buffer!\n")); 00068 b_.m_state = xdrIOBuffer::xmitted; 00069 b_.m_ptr = b_.m_buf; // rewind m_ptr for parsing stage 00070 b_.dump (); 00071 } 00072 return s_; 00073 }
|