00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "LoopbackSocket.h"
00022 #include "Message.h"
00023
00024 using namespace CODEX_Quorum;
00025
00026 LoopbackSocket::LoopbackSocket()
00027 {
00028 }
00029
00030 LoopbackSocket::LoopbackSocket( const LoopbackSocket& aOther )
00031 {
00032 }
00033
00034 LoopbackSocket::~LoopbackSocket()
00035 {
00036 }
00037
00038 size_t
00039 LoopbackSocket::readFrom( void* output, size_t maxSize ) const
00040 {
00041 unsigned char* ucoutput = (unsigned char*)output;
00042 size_t buffSize = m_buffer.size();
00043 size_t readSize = ( buffSize < maxSize )? buffSize : maxSize;
00044 for ( size_t i = 0 ; i < readSize ; ++i )
00045 {
00046 ucoutput[i] = m_buffer.front();
00047 m_buffer.pop_front();
00048 }
00049 return readSize;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 bool
00066 LoopbackSocket::isset_fd( const fd_set* fd_bitmap, StateType s ) const
00067 {
00068 switch(s)
00069 {
00070 case kRead :
00071 return ( ! m_buffer.empty() );
00072 break;
00073 case kWrite :
00074 while ( ! m_msgQueue.empty() )
00075 {
00076 Message* first = m_msgQueue.front();
00077 for ( unsigned int i = 0 ; i < first->length() ; ++i )
00078 {
00079 m_buffer.push_back( first->buffer()[i] );
00080 }
00081 delete first;
00082 m_msgQueue.pop();
00083 }
00084 return true;
00085 break;
00086 case kError :
00087 return false;
00088 break;
00089 }
00090 return false;
00091 }
00092
00093 void
00094 LoopbackSocket::flush() const
00095 {
00096 while ( ! m_msgQueue.empty() )
00097 {
00098 Message* first = m_msgQueue.front();
00099 for ( unsigned int i = 0 ; i < first->length() ; ++i )
00100 {
00101 m_buffer.push_back( first->buffer()[i] );
00102 }
00103 delete first;
00104 m_msgQueue.pop();
00105 }
00106 }