ThreadedSocketAcceptor.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef FIX_THREADEDSOCKETACCEPTOR_H
23 #define FIX_THREADEDSOCKETACCEPTOR_H
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable : 4503 4355 4786 4290 )
27 #endif
28 
29 #include "Acceptor.h"
31 #include "Mutex.h"
32 
33 namespace FIX
34 {
36 class ThreadedSocketAcceptor : public Acceptor
37 {
38  friend class SocketConnection;
39 public:
40  ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
41  const SessionSettings& ) throw( ConfigError );
42  ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
43  const SessionSettings&,
44  LogFactory& ) throw( ConfigError );
45 
46  virtual ~ThreadedSocketAcceptor();
47 
48 private:
49  struct AcceptorThreadInfo
50  {
51  AcceptorThreadInfo( ThreadedSocketAcceptor* pAcceptor, int socket, int port )
52  : m_pAcceptor( pAcceptor ), m_socket( socket ), m_port( port ) {}
53 
55  int m_socket;
56  int m_port;
57  };
58 
59  struct ConnectionThreadInfo
60  {
62  ThreadedSocketConnection* pConnection )
63  : m_pAcceptor( pAcceptor ), m_pConnection( pConnection ) {}
64 
66  ThreadedSocketConnection* m_pConnection;
67  };
68 
69  bool readSettings( const SessionSettings& );
70 
71  typedef std::set < int > Sockets;
72  typedef std::set < SessionID > Sessions;
73  typedef std::map < int, Sessions > PortToSessions;
74  typedef std::map < int, int > SocketToPort;
75  typedef std::map < int, thread_id > SocketToThread;
76 
77  void onConfigure( const SessionSettings& ) throw ( ConfigError );
78  void onInitialize( const SessionSettings& ) throw ( RuntimeError );
79 
80  void onStart();
81  bool onPoll( double timeout );
82  void onStop();
83 
84  void addThread( int s, thread_id t );
85  void removeThread( int s );
86  static THREAD_PROC socketAcceptorThread( void* p );
87  static THREAD_PROC socketConnectionThread( void* p );
88 
94 };
96 }
97 
98 #endif //FIX_THREADEDSOCKETACCEPTOR_H
FIX::ThreadedSocketAcceptor::onStart
void onStart()
Implemented to start listening for connections.
Definition: ThreadedSocketAcceptor.cpp:138
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:190
FIX::ThreadedSocketAcceptor::SocketToPort
std::map< int, int > SocketToPort
Definition: ThreadedSocketAcceptor.h:108
FIX::ThreadedSocketAcceptor::PortToSessions
std::map< int, Sessions > PortToSessions
Definition: ThreadedSocketAcceptor.h:107
Acceptor.h
FIX::ThreadedSocketAcceptor::readSettings
bool readSettings(const SessionSettings &)
FIX::ThreadedSocketAcceptor::m_sockets
Sockets m_sockets
Definition: ThreadedSocketAcceptor.h:123
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo::m_pConnection
ThreadedSocketConnection * m_pConnection
Definition: ThreadedSocketAcceptor.h:100
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::m_port
int m_port
Definition: ThreadedSocketAcceptor.h:90
FIX::ThreadedSocketAcceptor::onStop
void onStop()
Implemented to stop a running acceptor.
Definition: ThreadedSocketAcceptor.cpp:157
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::m_socket
int m_socket
Definition: ThreadedSocketAcceptor.h:89
FIX::ThreadedSocketAcceptor::SocketConnection
friend class SocketConnection
Definition: ThreadedSocketAcceptor.h:72
FIX::ThreadedSocketAcceptor::removeThread
void removeThread(int s)
Definition: ThreadedSocketAcceptor.cpp:192
FIX::ThreadedSocketAcceptor::m_socketToPort
SocketToPort m_socketToPort
Definition: ThreadedSocketAcceptor.h:125
FIX::ThreadedSocketAcceptor::onConfigure
void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition: ThreadedSocketAcceptor.cpp:71
FIX::Mutex
Portable implementation of a mutex.
Definition: Mutex.h:47
FIX::ThreadedSocketAcceptor::m_threads
SocketToThread m_threads
Definition: ThreadedSocketAcceptor.h:126
FIX::ThreadedSocketAcceptor::SocketToThread
std::map< int, thread_id > SocketToThread
Definition: ThreadedSocketAcceptor.h:109
FIX::ConfigError
Application is not configured correctly
Definition: Exceptions.h:104
FIX::RuntimeError
Application encountered serious error during runtime
Definition: Exceptions.h:111
FIX::ThreadedSocketAcceptor
Threaded Socket implementation of Acceptor.
Definition: ThreadedSocketAcceptor.h:53
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition: SessionSettings.h:237
Mutex.h
FIX::ThreadedSocketAcceptor::Sockets
std::set< int > Sockets
Definition: ThreadedSocketAcceptor.h:105
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::AcceptorThreadInfo
AcceptorThreadInfo(ThreadedSocketAcceptor *pAcceptor, int socket, int port)
Definition: ThreadedSocketAcceptor.h:85
THREAD_PROC
#define THREAD_PROC
Definition: Utility.h:184
FIX::ThreadedSocketAcceptor::~ThreadedSocketAcceptor
virtual ~ThreadedSocketAcceptor()
Definition: ThreadedSocketAcceptor.cpp:66
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo::m_pAcceptor
ThreadedSocketAcceptor * m_pAcceptor
Definition: ThreadedSocketAcceptor.h:99
FIX::ThreadedSocketAcceptor::socketAcceptorThread
static THREAD_PROC socketAcceptorThread(void *p)
Definition: ThreadedSocketAcceptor.cpp:203
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo::ConnectionThreadInfo
ConnectionThreadInfo(ThreadedSocketAcceptor *pAcceptor, ThreadedSocketConnection *pConnection)
Definition: ThreadedSocketAcceptor.h:95
FIX::ThreadedSocketAcceptor::Sessions
std::set< SessionID > Sessions
Definition: ThreadedSocketAcceptor.h:106
FIX::ThreadedSocketConnection
Encapsulates a socket file descriptor (multi-threaded).
Definition: ThreadedSocketConnection.h:61
FIX::ThreadedSocketAcceptor::socketConnectionThread
static THREAD_PROC socketConnectionThread(void *p)
Definition: ThreadedSocketAcceptor.cpp:263
FIX::ThreadedSocketAcceptor::addThread
void addThread(int s, thread_id t)
Definition: ThreadedSocketAcceptor.cpp:185
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::m_pAcceptor
ThreadedSocketAcceptor * m_pAcceptor
Definition: ThreadedSocketAcceptor.h:88
FIX::ThreadedSocketAcceptor::m_portToSessions
PortToSessions m_portToSessions
Definition: ThreadedSocketAcceptor.h:124
FIX::ThreadedSocketAcceptor::onPoll
bool onPoll(double timeout)
Implemented to connect and poll for events.
Definition: ThreadedSocketAcceptor.cpp:152
FIX
Definition: Acceptor.cpp:34
FIX::ThreadedSocketAcceptor::ThreadedSocketAcceptor
ThreadedSocketAcceptor(Application &, MessageStoreFactory &, const SessionSettings &)
Definition: ThreadedSocketAcceptor.cpp:49
ThreadedSocketConnection.h
FIX::ThreadedSocketAcceptor::m_mutex
Mutex m_mutex
Definition: ThreadedSocketAcceptor.h:127
FIX::ThreadedSocketAcceptor::onInitialize
void onInitialize(const SessionSettings &)
Implemented to initialize acceptor.
Definition: ThreadedSocketAcceptor.cpp:87

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001