ThreadedSocketAcceptor.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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