Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy   
 

/home/orenmnero/autobuild/quickfix/src/C++/SocketMonitor.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /****************************************************************************
00004 ** Copyright (c) quickfixengine.org  All rights reserved.
00005 **
00006 ** This file is part of the QuickFIX FIX Engine
00007 **
00008 ** This file may be distributed under the terms of the quickfixengine.org
00009 ** license as defined by quickfixengine.org and appearing in the file
00010 ** LICENSE included in the packaging of this file.
00011 **
00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00016 **
00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00018 ** not clear to you.
00019 **
00020 ****************************************************************************/
00021 
00022 #ifndef FIX_SOCKETMONITOR_H
00023 #define FIX_SOCKETMONITOR_H
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028 
00029 #ifdef _MSC_VER
00030 #include <Winsock2.h>
00031 typedef int socklen_t;
00032 #else
00033 #include <sys/types.h>
00034 #include <sys/socket.h>
00035 #include <sys/time.h>
00036 #include <netinet/in.h>
00037 #include <arpa/inet.h>
00038 #endif
00039 
00040 #include <set>
00041 #include <queue>
00042 #include <time.h>
00043 
00044 namespace FIX
00045 {
00047 class SocketMonitor
00048 {
00049 public:
00050   class Strategy;
00051 
00052   SocketMonitor( int timeout = 0 );
00053   virtual ~SocketMonitor();
00054 
00055   bool addConnect( int socket );
00056   bool addRead( int socket );
00057   bool addWrite( int socket );
00058   bool drop( int socket );
00059   void signal( int socket );
00060   void unsignal( int socket );
00061   void block( Strategy& strategy, bool poll = 0 );
00062 
00063   int numSockets() 
00064   { return m_readSockets.size() - 1; }
00065 
00066 private:
00067   typedef std::set < int > Sockets;
00068   typedef std::queue < int > Queue;
00069 
00070   void setsockopt();
00071   bool bind();
00072   bool listen();
00073   void buildSet( const Sockets&, fd_set& );
00074   inline timeval* getTimeval( bool poll );
00075   inline bool sleepIfEmpty( bool poll );
00076 
00077   void processReadSet( Strategy&, fd_set& );
00078   void processWriteSet( Strategy&, fd_set& );
00079 
00080   int m_timeout;
00081   timeval m_timeval;
00082 #ifndef SELECT_DECREMENTS_TIME
00083   clock_t m_ticks;
00084 #endif
00085 
00086   int m_signal;
00087   int m_interrupt;
00088   Sockets m_connectSockets;
00089   Sockets m_readSockets;
00090   Sockets m_writeSockets;
00091   Queue m_dropped;
00092 
00093 public:
00094   class Strategy
00095   {
00096   public:
00097     virtual ~Strategy()
00098     {}
00099     virtual void onConnect( SocketMonitor&, int socket ) = 0;
00100     virtual void onEvent( SocketMonitor&, int socket ) = 0;
00101     virtual void onWrite( SocketMonitor&, int socket ) = 0;
00102     virtual void onError( SocketMonitor&, int socket ) = 0;
00103     virtual void onError( SocketMonitor& ) = 0;
00104     virtual void onTimeout( SocketMonitor& )
00105   {}}
00106   ;
00107 };
00108 }
00109 
00110 #endif //FIX_SOCKETMONITOR_H

Generated on Mon Jul 24 19:36:30 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001