ThreadedSocketInitiator.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_THREADEDSOCKETINITIATOR_H
#define FIX_THREADEDSOCKETINITIATOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Initiator.h"
#include "ThreadedSocketConnection.h"
#include <map>
namespace FIX
{
class ThreadedSocketInitiator : public Initiator
{
public:
ThreadedSocketInitiator( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
ThreadedSocketInitiator( Application&, MessageStoreFactory&,
const SessionSettings&,
LogFactory& ) throw( ConfigError );
virtual ~ThreadedSocketInitiator();
private:
typedef std::map < int, thread_id > SocketToThread;
typedef std::map < SessionID, int > SessionToHostNum;
typedef std::pair < ThreadedSocketInitiator*, ThreadedSocketConnection* > ThreadPair;
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll( double timeout );
void onStop();
void doConnect( const SessionID& s, const Dictionary& d );
void addThread( int s, thread_id t );
void removeThread( int s );
void lock() { Locker l(m_mutex); }
static THREAD_PROC socketThread( void* p );
void getHost( const SessionID&, const Dictionary&, std::string&, short& );
SessionSettings m_settings;
SessionToHostNum m_sessionToHostNum;
time_t m_lastConnect;
int m_reconnectInterval;
bool m_noDelay;
int m_sendBufSize;
int m_rcvBufSize;
SocketToThread m_threads;
Mutex m_mutex;
};
}
#endif //FIX_THREADEDSOCKETINITIATOR_H
FIX::ThreadedSocketInitiator::getHost
void getHost(const SessionID &, const Dictionary &, std::string &, short &)
Definition: ThreadedSocketInitiator.cpp:238
FIX::ThreadedSocketInitiator::m_settings
SessionSettings m_settings
Definition: ThreadedSocketInitiator.h:71
FIX::ThreadedSocketInitiator::m_lastConnect
time_t m_lastConnect
Definition: ThreadedSocketInitiator.h:73
FIX::ThreadedSocketConnection
Encapsulates a socket file descriptor (multi-threaded).
Definition: ThreadedSocketConnection.h:44
FIX::ThreadedSocketInitiator::ThreadPair
std::pair< ThreadedSocketInitiator *, ThreadedSocketConnection *> ThreadPair
Definition: ThreadedSocketInitiator.h:53
FIX::ThreadedSocketInitiator::m_noDelay
bool m_noDelay
Definition: ThreadedSocketInitiator.h:75
FIX::ThreadedSocketInitiator::removeThread
void removeThread(int s)
Definition: ThreadedSocketInitiator.cpp:188
FIX::ThreadedSocketInitiator::SocketToThread
std::map< int, thread_id > SocketToThread
Definition: ThreadedSocketInitiator.h:51
FIX::ThreadedSocketInitiator::onStop
void onStop()
Implemented to stop a running initiator.
Definition: ThreadedSocketInitiator.cpp:103
FIX::ThreadedSocketInitiator::m_rcvBufSize
int m_rcvBufSize
Definition: ThreadedSocketInitiator.h:77
FIX::ThreadedSocketInitiator::onPoll
bool onPoll(double timeout)
Implemented to connect and poll for events.
Definition: ThreadedSocketInitiator.cpp:98
FIX::ThreadedSocketInitiator::ThreadedSocketInitiator
ThreadedSocketInitiator(Application &, MessageStoreFactory &, const SessionSettings &)
Definition: ThreadedSocketInitiator.cpp:32
FIX::ThreadedSocketInitiator::socketThread
static THREAD_PROC socketThread(void *p)
Definition: ThreadedSocketInitiator.cpp:200
FIX::ThreadedSocketInitiator::lock
void lock()
Definition: ThreadedSocketInitiator.h:66
FIX
Definition: Acceptor.cpp:34
FIX::RuntimeError
Application encountered serious error during runtime
Definition: Exceptions.h:94
FIX::Locker
Locks/Unlocks a mutex using RAII.
Definition: Mutex.h:95
FIX::ThreadedSocketInitiator::m_reconnectInterval
int m_reconnectInterval
Definition: ThreadedSocketInitiator.h:74
FIX::ThreadedSocketInitiator::onConfigure
void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition: ThreadedSocketInitiator.cpp:60
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition: SessionSettings.h:130
FIX::ThreadedSocketInitiator::onInitialize
void onInitialize(const SessionSettings &)
Implemented to initialize initiator.
Definition: ThreadedSocketInitiator.cpp:75
FIX::ThreadedSocketInitiator::addThread
void addThread(int s, thread_id t)
Definition: ThreadedSocketInitiator.cpp:181
Initiator.h
FIX::Mutex
Portable implementation of a mutex.
Definition: Mutex.h:30
FIX::ThreadedSocketInitiator::m_sessionToHostNum
SessionToHostNum m_sessionToHostNum
Definition: ThreadedSocketInitiator.h:72
FIX::ThreadedSocketInitiator::m_threads
SocketToThread m_threads
Definition: ThreadedSocketInitiator.h:78
FIX::ThreadedSocketInitiator::onStart
void onStart()
Implemented to start connecting to targets.
Definition: ThreadedSocketInitiator.cpp:80
FIX::ThreadedSocketInitiator::SessionToHostNum
std::map< SessionID, int > SessionToHostNum
Definition: ThreadedSocketInitiator.h:52
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:164
FIX::Dictionary
For storage and retrieval of key/value pairs.
Definition: Dictionary.h:36
ThreadedSocketConnection.h
FIX::ThreadedSocketInitiator::m_sendBufSize
int m_sendBufSize
Definition: ThreadedSocketInitiator.h:76
FIX::ThreadedSocketInitiator::doConnect
void doConnect(const SessionID &s, const Dictionary &d)
Implemented to connect a session to its target.
Definition: ThreadedSocketInitiator.cpp:133
FIX::SessionID
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:30
THREAD_PROC
#define THREAD_PROC
Definition: Utility.h:158
FIX::ThreadedSocketInitiator::m_mutex
Mutex m_mutex
Definition: ThreadedSocketInitiator.h:79