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

/home/orenmnero/autobuild/quickfix/src/C++/SocketServer.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_SOCKETSERVER_H
00023 #define FIX_SOCKETSERVER_H
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028 
00029 #include "SocketMonitor.h"
00030 #include <map>
00031 #include <set>
00032 #include <queue>
00033 
00034 namespace FIX
00035 {
00037 struct SocketInfo
00038 {
00039   SocketInfo()
00040   : m_socket( -1 ), m_port( 0 ), m_noDelay( false ) {}
00041   SocketInfo( int socket, short port, bool noDelay )
00042   : m_socket( socket ), m_port( port ), m_noDelay( noDelay ) {}
00043 
00044   int m_socket;
00045   short m_port;
00046   bool m_noDelay;
00047 };
00048 
00050 class SocketServer
00051 {
00052 public:
00053   class Strategy;
00054 
00055   SocketServer( int timeout = 0 );
00056 
00057   int add( int port, bool reuse = false, bool noDelay = false );
00058   int accept( int socket );
00059   void close();
00060   bool block( Strategy& strategy, bool poll = 0 );
00061 
00062   int numConnections() { return m_monitor.numSockets() - 1; }
00063   SocketMonitor& getMonitor() { return m_monitor; }
00064 
00065   int socketToPort( int socket );
00066   int portToSocket( int port );
00067 
00068 private:
00069   typedef std::map<int, SocketInfo>
00070     SocketToInfo;
00071   typedef std::map<int, SocketInfo>
00072     PortToInfo;
00073 
00074   SocketToInfo m_socketToInfo;  
00075   PortToInfo m_portToInfo;
00076   SocketMonitor m_monitor;
00077 
00078 public:
00079   class Strategy
00080   {
00081   public:
00082     virtual ~Strategy() {}
00083     virtual void onConnect( SocketServer&, int acceptSocket, int socket ) = 0;
00084     virtual void onWrite( SocketServer&, int socket ) = 0;
00085     virtual void onData( SocketServer&, int socket ) = 0;
00086     virtual void onDisconnect( SocketServer&, int socket ) = 0;
00087     virtual void onError( SocketServer& ) = 0;
00088     virtual void onTimeout( SocketServer& ) {};
00089   };
00090 };
00091 }
00092 
00093 #endif //FIX_SOCKETSERVER_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