ThreadedSocketAcceptor.h
Go to the documentation of this file.
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_THREADEDSOCKETACCEPTOR_H
#define FIX_THREADEDSOCKETACCEPTOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Acceptor.h"
#include "ThreadedSocketConnection.h"
#include "Mutex.h"
namespace FIX
{
class ThreadedSocketAcceptor : public Acceptor
{
friend class SocketConnection;
public:
ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
const SessionSettings&,
LogFactory& ) throw( ConfigError );
virtual ~ThreadedSocketAcceptor();
private:
struct AcceptorThreadInfo
{
AcceptorThreadInfo( ThreadedSocketAcceptor* pAcceptor, int socket, int port )
: m_pAcceptor( pAcceptor ), m_socket( socket ), m_port( port ) {}
ThreadedSocketAcceptor* m_pAcceptor;
int m_socket;
int m_port;
};
struct ConnectionThreadInfo
{
ConnectionThreadInfo( ThreadedSocketAcceptor* pAcceptor,
ThreadedSocketConnection* pConnection )
: m_pAcceptor( pAcceptor ), m_pConnection( pConnection ) {}
ThreadedSocketAcceptor* m_pAcceptor;
ThreadedSocketConnection* m_pConnection;
};
bool readSettings( const SessionSettings& );
typedef std::set < int > Sockets;
typedef std::set < SessionID > Sessions;
typedef std::map < int, Sessions > PortToSessions;
typedef std::map < int, int > SocketToPort;
typedef std::map < int, thread_id > SocketToThread;
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll( double timeout );
void onStop();
void addThread( int s, thread_id t );
void removeThread( int s );
static THREAD_PROC socketAcceptorThread( void* p );
static THREAD_PROC socketConnectionThread( void* p );
Sockets m_sockets;
PortToSessions m_portToSessions;
SocketToPort m_socketToPort;
SocketToThread m_threads;
Mutex m_mutex;
};
}
#endif //FIX_THREADEDSOCKETACCEPTOR_H
Acceptor.h
Mutex.h
ThreadedSocketConnection.h
THREAD_PROC
#define THREAD_PROC
Definition: Utility.h:184
FIX::Acceptor
Base for classes which act as an acceptor for incoming connections.
Definition: Acceptor.h:50
FIX::Application
This interface must be implemented to define what your FIX application does.
Definition: Application.h:44
FIX::LogFactory
This interface must be implemented to create a Log.
Definition: Log.h:43
FIX::MessageStoreFactory
This interface must be implemented to create a MessageStore.
Definition: MessageStore.h:42
FIX::Mutex
Portable implementation of a mutex.
Definition: Mutex.h:31
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition: SessionSettings.h:221
FIX::SocketConnection
Encapsulates a socket file descriptor (single-threaded).
Definition: SocketConnection.h:47
FIX::ThreadedSocketAcceptor
Threaded Socket implementation of Acceptor.
Definition: ThreadedSocketAcceptor.h:37
FIX::ThreadedSocketAcceptor::m_mutex
Mutex m_mutex
Definition: ThreadedSocketAcceptor.h:93
FIX::ThreadedSocketAcceptor::onPoll
bool onPoll(double timeout)
Implemented to connect and poll for events.
Definition: ThreadedSocketAcceptor.cpp:135
FIX::ThreadedSocketAcceptor::PortToSessions
std::map< int, Sessions > PortToSessions
Definition: ThreadedSocketAcceptor.h:73
FIX::ThreadedSocketAcceptor::socketConnectionThread
static THREAD_PROC socketConnectionThread(void *p)
Definition: ThreadedSocketAcceptor.cpp:246
FIX::ThreadedSocketAcceptor::m_threads
SocketToThread m_threads
Definition: ThreadedSocketAcceptor.h:92
FIX::ThreadedSocketAcceptor::SocketToPort
std::map< int, int > SocketToPort
Definition: ThreadedSocketAcceptor.h:74
FIX::ThreadedSocketAcceptor::removeThread
void removeThread(int s)
Definition: ThreadedSocketAcceptor.cpp:175
FIX::ThreadedSocketAcceptor::socketAcceptorThread
static THREAD_PROC socketAcceptorThread(void *p)
Definition: ThreadedSocketAcceptor.cpp:186
FIX::ThreadedSocketAcceptor::m_sockets
Sockets m_sockets
Definition: ThreadedSocketAcceptor.h:89
FIX::ThreadedSocketAcceptor::ThreadedSocketAcceptor
ThreadedSocketAcceptor(Application &, MessageStoreFactory &, const SessionSettings &)
Definition: ThreadedSocketAcceptor.cpp:32
FIX::ThreadedSocketAcceptor::readSettings
bool readSettings(const SessionSettings &)
FIX::ThreadedSocketAcceptor::addThread
void addThread(int s, thread_id t)
Definition: ThreadedSocketAcceptor.cpp:168
FIX::ThreadedSocketAcceptor::m_portToSessions
PortToSessions m_portToSessions
Definition: ThreadedSocketAcceptor.h:90
FIX::ThreadedSocketAcceptor::onStop
void onStop()
Implemented to stop a running acceptor.
Definition: ThreadedSocketAcceptor.cpp:140
FIX::ThreadedSocketAcceptor::onStart
void onStart()
Implemented to start listening for connections.
Definition: ThreadedSocketAcceptor.cpp:121
FIX::ThreadedSocketAcceptor::SocketToThread
std::map< int, thread_id > SocketToThread
Definition: ThreadedSocketAcceptor.h:75
FIX::ThreadedSocketAcceptor::onConfigure
void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition: ThreadedSocketAcceptor.cpp:54
FIX::ThreadedSocketAcceptor::m_socketToPort
SocketToPort m_socketToPort
Definition: ThreadedSocketAcceptor.h:91
FIX::ThreadedSocketAcceptor::~ThreadedSocketAcceptor
virtual ~ThreadedSocketAcceptor()
Definition: ThreadedSocketAcceptor.cpp:49
FIX::ThreadedSocketAcceptor::onInitialize
void onInitialize(const SessionSettings &)
Implemented to initialize acceptor.
Definition: ThreadedSocketAcceptor.cpp:70
FIX::ThreadedSocketAcceptor::Sockets
std::set< int > Sockets
Definition: ThreadedSocketAcceptor.h:71
FIX::ThreadedSocketAcceptor::Sessions
std::set< SessionID > Sessions
Definition: ThreadedSocketAcceptor.h:72
FIX::ThreadedSocketConnection
Encapsulates a socket file descriptor (multi-threaded).
Definition: ThreadedSocketConnection.h:45
FIX
Definition: Acceptor.cpp:35
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:190
FIX::ConfigError
Application is not configured correctly
Definition: Exceptions.h:88
FIX::RuntimeError
Application encountered serious error during runtime
Definition: Exceptions.h:95
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo
Definition: ThreadedSocketAcceptor.h:50
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::AcceptorThreadInfo
AcceptorThreadInfo(ThreadedSocketAcceptor *pAcceptor, int socket, int port)
Definition: ThreadedSocketAcceptor.h:51
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::m_socket
int m_socket
Definition: ThreadedSocketAcceptor.h:55
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::m_pAcceptor
ThreadedSocketAcceptor * m_pAcceptor
Definition: ThreadedSocketAcceptor.h:54
FIX::ThreadedSocketAcceptor::AcceptorThreadInfo::m_port
int m_port
Definition: ThreadedSocketAcceptor.h:56
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo
Definition: ThreadedSocketAcceptor.h:60
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo::m_pAcceptor
ThreadedSocketAcceptor * m_pAcceptor
Definition: ThreadedSocketAcceptor.h:65
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo::ConnectionThreadInfo
ConnectionThreadInfo(ThreadedSocketAcceptor *pAcceptor, ThreadedSocketConnection *pConnection)
Definition: ThreadedSocketAcceptor.h:61
FIX::ThreadedSocketAcceptor::ConnectionThreadInfo::m_pConnection
ThreadedSocketConnection * m_pConnection
Definition: ThreadedSocketAcceptor.h:66