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

ThreadedSocketAcceptor.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_THREADEDSOCKETACCEPTOR_H
00023 #define FIX_THREADEDSOCKETACCEPTOR_H
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028 
00029 #include "Acceptor.h"
00030 #include "ThreadedSocketConnection.h"
00031 #include "Mutex.h"
00032 
00033 namespace FIX
00034 {
00036 class ThreadedSocketAcceptor : public Acceptor
00037 {
00038   friend class SocketConnection;
00039 public:
00040   ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
00041                           const SessionSettings& ) throw( ConfigError );
00042   ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
00043                           const SessionSettings&,
00044                           LogFactory& ) throw( ConfigError );
00045 
00046   virtual ~ThreadedSocketAcceptor();
00047 
00048 private:
00049   struct AcceptorThreadInfo
00050   {
00051     AcceptorThreadInfo( ThreadedSocketAcceptor* pAcceptor, int socket, int port )
00052     : m_pAcceptor( pAcceptor ), m_socket( socket ), m_port( port ) {}
00053 
00054     ThreadedSocketAcceptor* m_pAcceptor;
00055     int m_socket;
00056     int m_port;
00057   };
00058 
00059   struct ConnectionThreadInfo
00060   {
00061     ConnectionThreadInfo( ThreadedSocketAcceptor* pAcceptor, 
00062                           ThreadedSocketConnection* pConnection )
00063     : m_pAcceptor( pAcceptor ), m_pConnection( pConnection ) {}
00064 
00065     ThreadedSocketAcceptor* m_pAcceptor;
00066     ThreadedSocketConnection* m_pConnection;
00067   };
00068 
00069   bool readSettings( const SessionSettings& );
00070 
00071   typedef std::set < int >  Sockets;
00072   typedef std::set < SessionID > Sessions;
00073   typedef std::map < int, Sessions > PortToSessions;
00074   typedef std::map < int, int > SocketToPort;
00075   typedef std::map < int, thread_id > SocketToThread;
00076 
00077   void onConfigure( const SessionSettings& ) throw ( ConfigError );
00078   void onInitialize( const SessionSettings& ) throw ( RuntimeError );
00079 
00080   void onStart();
00081   bool onPoll( double timeout );
00082   void onStop();
00083 
00084   void addThread( int s, thread_id t );
00085   void removeThread( int s );
00086   static THREAD_PROC socketAcceptorThread( void* p );
00087   static THREAD_PROC socketConnectionThread( void* p );
00088 
00089   Sockets m_sockets;
00090   PortToSessions m_portToSessions;
00091   SocketToPort m_socketToPort;
00092   SocketToThread m_threads;
00093   Mutex m_mutex;
00094 };
00096 }
00097 
00098 #endif //FIX_THREADEDSOCKETACCEPTOR_H

Generated on Mon Apr 5 20:59:51 2010 for QuickFIX by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2001