QuickFIX: /home/omiller/Development/autobuild/quickfix/src/C++/SocketServer.h Source File

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

# 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 "Exceptions.h"
    00031 #include <map>
    00032 #include <set>
    00033 #include <queue>
    00034
    00035 namespace FIX
    00036 {
    00038 struct SocketInfo
    00039 {
    00040   SocketInfo()
    00041   : m_socket( -1 ), m_port( 0 ), m_noDelay( false ),
    00042     m_sendBufSize( 0 ), m_rcvBufSize( 0 ) {}
    00043
    00044   SocketInfo( int socket, short port, bool noDelay, int sendBufSize, int rcvBufSize )
    00045   : m_socket( socket ), m_port( port ), m_noDelay( noDelay ),
    00046     m_sendBufSize( sendBufSize ), m_rcvBufSize( rcvBufSize ) {}
    00047
    00048   int m_socket;
    00049   short m_port;
    00050   bool m_noDelay;
    00051   int m_sendBufSize;
    00052   int m_rcvBufSize;
    00053 };
    00054
    00056 class SocketServer
    00057 {
    00058 public:
    00059   class Strategy;
    00060
    00061   SocketServer( int timeout = 0 );
    00062
    00063   int add( int port, bool reuse = false, bool noDelay = false,
    00064            int sendBufSize = 0, int rcvBufSize = 0 ) throw( SocketException& );
    00065   int accept( int socket );
    00066   void close();
    00067   bool block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
    00068
    00069   int numConnections() { return m_monitor.numSockets() - 1; }
    00070   SocketMonitor& getMonitor() { return m_monitor; }
    00071
    00072   int socketToPort( int socket );
    00073   int portToSocket( int port );
    00074
    00075 private:
    00076   typedef std::map<int, SocketInfo>
    00077     SocketToInfo;
    00078   typedef std::map<int, SocketInfo>
    00079     PortToInfo;
    00080
    00081   SocketToInfo m_socketToInfo;
    00082   PortToInfo m_portToInfo;
    00083   SocketMonitor m_monitor;
    00084
    00085 public:
    00086   class Strategy
    00087   {
    00088   public:
    00089     virtual ~Strategy() {}
    00090     virtual void onConnect( SocketServer&, int acceptSocket, int socket ) = 0;
    00091     virtual void onWrite( SocketServer&, int socket ) = 0;
    00092     virtual bool onData( SocketServer&, int socket ) = 0;
    00093     virtual void onDisconnect( SocketServer&, int socket ) = 0;
    00094     virtual void onError( SocketServer& ) = 0;
    00095     virtual void onTimeout( SocketServer& ) {};
    00096   };
    00097 };
    00098 }
    00099
    00100 #endif //FIX_SOCKETSERVER_H