Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

LoopbackSocket.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: LoopbackSocket.cc,v 1.4 2004/05/19 15:56:55 mmarsh Exp $
00008 //
00009 // $Log: LoopbackSocket.cc,v $
00010 // Revision 1.4  2004/05/19 15:56:55  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.3  2004/01/23 14:55:50  mmarsh
00014 // Added flush() method specific to loopback sockets.
00015 //
00016 // Revision 1.2  2003/11/04 22:31:50  mmarsh
00017 // *** empty log message ***
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 size_t
00054 LoopbackSocket::writeTo( const void* input, size_t maxSize ) const
00055 {
00056    unsigned char* ucinput = (unsigned char*)input;
00057    for ( size_t i = 0 ; i < maxSize ; ++i )
00058    {
00059       m_buffer.push_back( ucinput[i] );
00060    }
00061    return maxSize;
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 }

Generated on Wed Jun 2 16:32:55 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18