FIX::SocketAcceptor Class Reference

Socket implementation of Acceptor. More...

`#include <SocketAcceptor.h>`

Inheritance diagram for FIX::SocketAcceptor:
[legend]
Collaboration diagram for FIX::SocketAcceptor:
[legend]

## Public Member Functions

| SocketAcceptor (Application &, MessageStoreFactory &, const SessionSettings &) throw ( ConfigError )
| SocketAcceptor (Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) throw ( ConfigError )
virtual | ~SocketAcceptor ()
Public Member Functions inherited from FIX::Acceptor
| Acceptor (Application &, MessageStoreFactory &, const SessionSettings &) throw ( ConfigError )
| Acceptor (Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) throw ( ConfigError )
virtual | ~Acceptor ()
Log * | getLog ()
void | start () throw ( ConfigError, RuntimeError )
| Start acceptor. More...
void | block () throw ( ConfigError, RuntimeError )
| Block on the acceptor. More...
bool | poll (double timeout=0.0) throw ( ConfigError, RuntimeError )
| Poll the acceptor. More...
void | stop (bool force=false)
| Stop acceptor. More...
bool | isLoggedOn ()
| Check to see if any sessions are currently logged on. More...
Session * | getSession (const std::string &msg, Responder &)
const std::set< SessionID > & | getSessions () const
Session * | getSession (const SessionID &sessionID) const
const Dictionary *const | getSessionSettings (const SessionID &sessionID) const
bool | has (const SessionID &id)
bool | isStopped ()
Application & | getApplication ()
MessageStoreFactory & | getMessageStoreFactory ()

## Private Types

typedef std::set< SessionID > | Sessions
typedef std::map< int, Sessions > | PortToSessions
typedef std::map< int, SocketConnection *> | SocketConnections

## Private Member Functions

bool | readSettings (const SessionSettings &)
void | onConfigure (const SessionSettings &) throw ( ConfigError )
| Implemented to configure acceptor. More...
void | onInitialize (const SessionSettings &) throw ( RuntimeError )
| Implemented to initialize acceptor. More...
void | onStart ()
| Implemented to start listening for connections. More...
bool | onPoll (double timeout)
| Implemented to connect and poll for events. More...
void | onStop ()
| Implemented to stop a running acceptor. More...
void | onConnect (SocketServer &, int, int)
void | onWrite (SocketServer &, int)
bool | onData (SocketServer &, int)
void | onDisconnect (SocketServer &, int)
void | onError (SocketServer &)
void | onTimeout (SocketServer &)
Private Member Functions inherited from FIX::SocketServer::Strategy
virtual | ~Strategy ()

## Private Attributes

SocketServer * | m_pServer
PortToSessions | m_portToSessions
SocketConnections | m_connections

## Friends

class | SocketConnection

## Detailed Description

Socket implementation of Acceptor.

Definition at line 36 of file SocketAcceptor.h.

## Member Typedef Documentation

## PortToSessions

typedef std::map< int, Sessions > FIX::SocketAcceptor::PortToSessions

private

Definition at line 51 of file SocketAcceptor.h.

## Sessions

typedef std::set< SessionID > FIX::SocketAcceptor::Sessions

private

Definition at line 50 of file SocketAcceptor.h.

## SocketConnections

typedef std::map< int, SocketConnection* > FIX::SocketAcceptor::SocketConnections

private

Definition at line 52 of file SocketAcceptor.h.

## Constructor & Destructor Documentation

## SocketAcceptor() [1/2]

FIX::SocketAcceptor::SocketAcceptor | ( | Application & | application,
|  | MessageStoreFactory & | factory,
|  | const SessionSettings & | settings
| ) |  |
throw | ( | ConfigError
| ) |  |

Definition at line 34 of file SocketAcceptor.cpp.

: Acceptor( application, factory, settings ),
m_pServer( 0 ) {}
FIX::SocketAcceptor::m_pServer
SocketServer * m_pServer
Definition: SocketAcceptor.h:68
FIX::Acceptor::Acceptor
Acceptor(Application &, MessageStoreFactory &, const SessionSettings &)
Definition: Acceptor.cpp:36

## SocketAcceptor() [2/2]

FIX::SocketAcceptor::SocketAcceptor | ( | Application & | application,
|  | MessageStoreFactory & | factory,
|  | const SessionSettings & | settings,
|  | LogFactory & | logFactory
| ) |  |
throw | ( | ConfigError
| ) |  |

Definition at line 40 of file SocketAcceptor.cpp.

: Acceptor( application, factory, settings, logFactory ),
m_pServer( 0 )
{
}
FIX::SocketAcceptor::m_pServer
SocketServer * m_pServer
Definition: SocketAcceptor.h:68
FIX::Acceptor::Acceptor
Acceptor(Application &, MessageStoreFactory &, const SessionSettings &)
Definition: Acceptor.cpp:36

## ~SocketAcceptor()

FIX::SocketAcceptor::~SocketAcceptor | ( |  | ) |

virtual

Definition at line 49 of file SocketAcceptor.cpp.

References m_connections.

{
SocketConnections::iterator iter;
for ( iter = m_connections.begin(); iter != m_connections.end(); ++iter )
delete iter->second;
}
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:70

## Member Function Documentation

## onConfigure()

void FIX::SocketAcceptor::onConfigure | ( | const SessionSettings & |  | ) |
throw | ( | ConfigError
| ) |  |

private virtual

Implemented to configure acceptor.

Reimplemented from FIX::Acceptor.

Definition at line 56 of file SocketAcceptor.cpp.

References FIX::Dictionary::getBool(), FIX::Dictionary::getInt(), FIX::Dictionary::has(), FIX::SOCKET_ACCEPT_PORT, FIX::SOCKET_NODELAY, and FIX::SOCKET_REUSE_ADDRESS.

{
std::set<SessionID> sessions = s.getSessions();
std::set<SessionID>::iterator i;
for( i = sessions.begin(); i != sessions.end(); ++i )
{
const Dictionary& settings = s.get( *i );
settings.getInt( SOCKET_ACCEPT_PORT );
if( settings.has(SOCKET_REUSE_ADDRESS) )
settings.getBool( SOCKET_REUSE_ADDRESS );
if( settings.has(SOCKET_NODELAY) )
settings.getBool( SOCKET_NODELAY );
}
}
FIX::SOCKET_NODELAY
const char SOCKET_NODELAY[]
Definition: SessionSettings.h:66
FIX::SOCKET_ACCEPT_PORT
const char SOCKET_ACCEPT_PORT[]
Definition: SessionSettings.h:62
FIX::SOCKET_REUSE_ADDRESS
const char SOCKET_REUSE_ADDRESS[]
Definition: SessionSettings.h:63

## onConnect()

void FIX::SocketAcceptor::onConnect | ( | SocketServer & | server,
|  | int | a,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 166 of file SocketAcceptor.cpp.

References FIX::Acceptor::getLog(), FIX::SocketServer::getMonitor(), m_connections, m_portToSessions, FIX::Log::onEvent(), FIX::socket_isValid(), FIX::socket_peername(), SocketConnection, and FIX::SocketServer::socketToPort().

{
if ( !socket_isValid( s ) ) return;
SocketConnections::iterator i = m_connections.find( s );
if ( i != m_connections.end() ) return;
int port = server.socketToPort( a );
Sessions sessions = m_portToSessions[port];
m_connections[ s ] = new SocketConnection( s, sessions, &server.getMonitor() );
std::stringstream stream;
stream << "Accepted connection from " << socket_peername( s ) << " on port " << port;
if( getLog() )
getLog()->onEvent( stream.str() );
}
FIX::socket_isValid
bool socket_isValid(int socket)
Definition: Utility.cpp:255
FIX::SocketAcceptor::SocketConnection
friend class SocketConnection
Definition: SocketAcceptor.h:38
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:70
FIX::Log::onEvent
virtual void onEvent(const std::string &)=0
FIX::Acceptor::getLog
Log * getLog()
Definition: Acceptor.h:59
FIX::SocketAcceptor::m_portToSessions
PortToSessions m_portToSessions
Definition: SocketAcceptor.h:69
FIX::SocketAcceptor::Sessions
std::set< SessionID > Sessions
Definition: SocketAcceptor.h:50
FIX::socket_peername
const char * socket_peername(int socket)
Definition: Utility.cpp:331

## onData()

bool FIX::SocketAcceptor::onData | ( | SocketServer & | server,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 191 of file SocketAcceptor.cpp.

References m_connections, and FIX::SocketConnection::read().

{
SocketConnections::iterator i = m_connections.find( s );
if ( i == m_connections.end() ) return false;
SocketConnection* pSocketConnection = i->second;
return pSocketConnection->read( *this, server );
}
FIX::SocketAcceptor::SocketConnection
friend class SocketConnection
Definition: SocketAcceptor.h:38
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:70

## onDisconnect()

void FIX::SocketAcceptor::onDisconnect | ( | SocketServer & | ,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 199 of file SocketAcceptor.cpp.

References FIX::Session::disconnect(), FIX::SocketConnection::getSession(), and m_connections.

{
SocketConnections::iterator i = m_connections.find( s );
if ( i == m_connections.end() ) return ;
SocketConnection* pSocketConnection = i->second;
Session* pSession = pSocketConnection->getSession();
if ( pSession ) pSession->disconnect();
delete pSocketConnection;
m_connections.erase( s );
}
FIX::SocketAcceptor::SocketConnection
friend class SocketConnection
Definition: SocketAcceptor.h:38
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:70

## onError()

void FIX::SocketAcceptor::onError | ( | SocketServer & |  | ) |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 212 of file SocketAcceptor.cpp.

{
}

## onInitialize()

void FIX::SocketAcceptor::onInitialize | ( | const SessionSettings & |  | ) |
throw | ( | RuntimeError
| ) |  |

private virtual

Implemented to initialize acceptor.

Reimplemented from FIX::Acceptor.

Definition at line 72 of file SocketAcceptor.cpp.

References FIX::IntConvertor::convert(), FIX::Dictionary::getBool(), FIX::Dictionary::getInt(), FIX::Dictionary::has(), FIX::SOCKET_ACCEPT_PORT, FIX::SOCKET_NODELAY, FIX::SOCKET_RECEIVE_BUFFER_SIZE, FIX::SOCKET_REUSE_ADDRESS, and FIX::SOCKET_SEND_BUFFER_SIZE.

{
short port = 0;
try
{
m_pServer = new SocketServer( 1 );
std::set<SessionID> sessions = s.getSessions();
std::set<SessionID>::iterator i = sessions.begin();
for( ; i != sessions.end(); ++i )
{
const Dictionary& settings = s.get( *i );
port = (short)settings.getInt( SOCKET_ACCEPT_PORT );
const bool reuseAddress = settings.has( SOCKET_REUSE_ADDRESS ) ?
settings.getBool( SOCKET_REUSE_ADDRESS ) : true;
const bool noDelay = settings.has( SOCKET_NODELAY ) ?
settings.getBool( SOCKET_NODELAY ) : false;
const int sendBufSize = settings.has( SOCKET_SEND_BUFFER_SIZE ) ?
settings.getInt( SOCKET_SEND_BUFFER_SIZE ) : 0;
const int rcvBufSize = settings.has( SOCKET_RECEIVE_BUFFER_SIZE ) ?
settings.getInt( SOCKET_RECEIVE_BUFFER_SIZE ) : 0;
m_portToSessions[port].insert( *i );
m_pServer->add( port, reuseAddress, noDelay, sendBufSize, rcvBufSize );
}
}
catch( SocketException& e )
{
throw RuntimeError( "Unable to create, bind, or listen to port "
+ IntConvertor::convert( (unsigned short)port ) + " (" + e.what() + ")" );
}
}
FIX::SOCKET_NODELAY
const char SOCKET_NODELAY[]
Definition: SessionSettings.h:66
FIX::SOCKET_ACCEPT_PORT
const char SOCKET_ACCEPT_PORT[]
Definition: SessionSettings.h:62
FIX::SOCKET_SEND_BUFFER_SIZE
const char SOCKET_SEND_BUFFER_SIZE[]
Definition: SessionSettings.h:67
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:154
FIX::SOCKET_RECEIVE_BUFFER_SIZE
const char SOCKET_RECEIVE_BUFFER_SIZE[]
Definition: SessionSettings.h:68
FIX::SocketServer::add
int add(int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0)
Definition: SocketServer.cpp:97
FIX::SocketAcceptor::m_portToSessions
PortToSessions m_portToSessions
Definition: SocketAcceptor.h:69
FIX::SocketAcceptor::m_pServer
SocketServer * m_pServer
Definition: SocketAcceptor.h:68
FIX::SOCKET_REUSE_ADDRESS
const char SOCKET_REUSE_ADDRESS[]
Definition: SessionSettings.h:63

## onPoll()

bool FIX::SocketAcceptor::onPoll | ( | double | second | ) |

private virtual

Implemented to connect and poll for events.

Implements FIX::Acceptor.

Definition at line 134 of file SocketAcceptor.cpp.

References FIX::SocketServer::block(), FIX::Acceptor::isLoggedOn(), FIX::Acceptor::isStopped(), m_pServer, and FIX::Acceptor::start().

{
if( !m_pServer )
return false;
time_t start = 0;
time_t now = 0;
if( isStopped() )
{
if( start == 0 )
::time( &start );
if( !isLoggedOn() )
{
start = 0;
return false;
}
if( ::time(&now) - 5 >= start )
{
start = 0;
return false;
}
}
m_pServer->block( *this, true, timeout );
return true;
}
FIX::Acceptor::isLoggedOn
bool isLoggedOn()
Check to see if any sessions are currently logged on.
Definition: Acceptor.cpp:230
FIX::Acceptor::isStopped
bool isStopped()
Definition: Acceptor.h:87
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:148
FIX::Acceptor::start
void start()
Start acceptor.
Definition: Acceptor.cpp:158
FIX::SocketAcceptor::m_pServer
SocketServer * m_pServer
Definition: SocketAcceptor.h:68

## onStart()

void FIX::SocketAcceptor::onStart | ( |  | ) |

private virtual

Implemented to start listening for connections.

Implements FIX::Acceptor.

Definition at line 111 of file SocketAcceptor.cpp.

References FIX::SocketServer::block(), FIX::SocketServer::close(), FIX::Acceptor::isLoggedOn(), FIX::Acceptor::isStopped(), m_pServer, and FIX::Acceptor::start().

{
while ( !isStopped() && m_pServer && m_pServer->block( *this ) ) {}
if( !m_pServer )
return;
time_t start = 0;
time_t now = 0;
::time( &start );
while ( isLoggedOn() )
{
m_pServer->block( *this );
if( ::time(&now) -5 >= start )
break;
}
m_pServer->close();
delete m_pServer;
m_pServer = 0;
}
FIX::Acceptor::isLoggedOn
bool isLoggedOn()
Check to see if any sessions are currently logged on.
Definition: Acceptor.cpp:230
FIX::Acceptor::isStopped
bool isStopped()
Definition: Acceptor.h:87
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:148
FIX::Acceptor::start
void start()
Start acceptor.
Definition: Acceptor.cpp:158
FIX::SocketAcceptor::m_pServer
SocketServer * m_pServer
Definition: SocketAcceptor.h:68
FIX::SocketServer::close
void close()
Definition: SocketServer.cpp:137

## onStop()

void FIX::SocketAcceptor::onStop | ( |  | ) |

private virtual

Implemented to stop a running acceptor.

Implements FIX::Acceptor.

Definition at line 162 of file SocketAcceptor.cpp.

{
}

## onTimeout()

void FIX::SocketAcceptor::onTimeout | ( | SocketServer & |  | ) |

private virtual

Reimplemented from FIX::SocketServer::Strategy.

Definition at line 216 of file SocketAcceptor.cpp.

References m_connections.

{
SocketConnections::iterator i;
for ( i = m_connections.begin(); i != m_connections.end(); ++i )
i->second->onTimeout();
}
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:70

## onWrite()

void FIX::SocketAcceptor::onWrite | ( | SocketServer & | server,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 182 of file SocketAcceptor.cpp.

References m_connections, FIX::SocketConnection::processQueue(), and FIX::SocketConnection::unsignal().

{
SocketConnections::iterator i = m_connections.find( s );
if ( i == m_connections.end() ) return ;
SocketConnection* pSocketConnection = i->second;
if( pSocketConnection->processQueue() )
pSocketConnection->unsignal();
}
FIX::SocketAcceptor::SocketConnection
friend class SocketConnection
Definition: SocketAcceptor.h:38
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:70

## readSettings()

bool FIX::SocketAcceptor::readSettings | ( | const SessionSettings & |  | ) |

private

## Friends And Related Function Documentation

## SocketConnection

friend class SocketConnection

friend

Definition at line 38 of file SocketAcceptor.h.

Referenced by onConnect().

## Member Data Documentation

## m_connections

SocketConnections FIX::SocketAcceptor::m_connections

private

Definition at line 70 of file SocketAcceptor.h.

Referenced by onConnect(), onData(), onDisconnect(), onTimeout(), onWrite(), and ~SocketAcceptor().

## m_portToSessions

PortToSessions FIX::SocketAcceptor::m_portToSessions

private

Definition at line 69 of file SocketAcceptor.h.

Referenced by onConnect().

## m_pServer

SocketServer* FIX::SocketAcceptor::m_pServer

private

Definition at line 68 of file SocketAcceptor.h.

Referenced by onPoll(), and onStart().

The documentation for this class was generated from the following files:

- SocketAcceptor.h
- SocketAcceptor.cpp