Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
FIX::SocketAcceptor Class Reference

Socket implementation of Acceptor. More...

#include <SocketAcceptor.h>

Inheritance diagram for FIX::SocketAcceptor:
Inheritance graph
[legend]
Collaboration diagram for FIX::SocketAcceptor:
Collaboration graph
[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 ()
 
LoggetLog ()
 
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...
 
SessiongetSession (const std::string &msg, Responder &)
 
const std::set< SessionID > & getSessions () const
 
SessiongetSession (const SessionID &sessionID) const
 
const Dictionary *const getSessionSettings (const SessionID &sessionID) const
 
bool has (const SessionID &id)
 
bool isStopped ()
 
ApplicationgetApplication ()
 
MessageStoreFactorygetMessageStoreFactory ()
 

Private Types

typedef std::set< SessionIDSessions
 
typedef std::map< int, SessionsPortToSessions
 
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

SocketServerm_pServer
 
PortToSessions m_portToSessions
 
SocketConnections m_connections
 

Friends

class SocketConnection
 

Additional Inherited Members

- Protected Attributes inherited from FIX::Acceptor
SessionSettings m_settings
 

Detailed Description

Socket implementation of Acceptor.

Definition at line 53 of file SocketAcceptor.h.

Member Typedef Documentation

◆ PortToSessions

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

Definition at line 85 of file SocketAcceptor.h.

◆ Sessions

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

Definition at line 84 of file SocketAcceptor.h.

◆ SocketConnections

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

Definition at line 86 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 51 of file SocketAcceptor.cpp.

◆ SocketAcceptor() [2/2]

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

Definition at line 57 of file SocketAcceptor.cpp.

58 {
59  std::set<SessionID> sessions = s.getSessions();
60  std::set<SessionID>::iterator i;
61  for( i = sessions.begin(); i != sessions.end(); ++i )
62  {
63  const Dictionary& settings = s.get( *i );
64  settings.getInt( SOCKET_ACCEPT_PORT );

References FIX::SessionSettings::get(), FIX::Dictionary::getInt(), FIX::SessionSettings::getSessions(), FIX::Dictionary::has(), FIX::SOCKET_ACCEPT_PORT, and FIX::SOCKET_REUSE_ADDRESS.

◆ ~SocketAcceptor()

FIX::SocketAcceptor::~SocketAcceptor ( )
virtual

Definition at line 66 of file SocketAcceptor.cpp.

Member Function Documentation

◆ onConfigure()

void FIX::SocketAcceptor::onConfigure ( const SessionSettings )
throw (ConfigError
)
privatevirtual

Implemented to configure acceptor.

Reimplemented from FIX::Acceptor.

Definition at line 73 of file SocketAcceptor.cpp.

74 {
75  short port = 0;
76 
77  try
78  {
79  m_pServer = new SocketServer( 1 );
80 
81  std::set<SessionID> sessions = s.getSessions();
82  std::set<SessionID>::iterator i = sessions.begin();
83  for( ; i != sessions.end(); ++i )
84  {
85  const Dictionary& settings = s.get( *i );
86  port = (short)settings.getInt( SOCKET_ACCEPT_PORT );
87 

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

◆ onConnect()

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

Implements FIX::SocketServer::Strategy.

Definition at line 183 of file SocketAcceptor.cpp.

183 {
184  SocketConnections::iterator i = m_connections.find( s );
185  if ( i == m_connections.end() ) return ;
186  SocketConnection* pSocketConnection = i->second;
187  if( pSocketConnection->processQueue() )
188  pSocketConnection->unsignal();
189 }
190 
191 bool SocketAcceptor::onData( SocketServer& server, int s )
192 {
193  SocketConnections::iterator i = m_connections.find( s );
194  if ( i == m_connections.end() ) return false;
195  SocketConnection* pSocketConnection = i->second;
196  return pSocketConnection->read( *this, server );
197 }

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

◆ onData()

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

Implements FIX::SocketServer::Strategy.

Definition at line 208 of file SocketAcceptor.cpp.

213 {
214 }

◆ onDisconnect()

void FIX::SocketAcceptor::onDisconnect ( SocketServer ,
int  s 
)
privatevirtual

Implements FIX::SocketServer::Strategy.

Definition at line 216 of file SocketAcceptor.cpp.

217 {
218  SocketConnections::iterator i;
219  for ( i = m_connections.begin(); i != m_connections.end(); ++i )
220  i->second->onTimeout();
221 }
222 }

References m_connections.

◆ onError()

void FIX::SocketAcceptor::onError ( SocketServer )
privatevirtual

Implements FIX::SocketServer::Strategy.

Definition at line 229 of file SocketAcceptor.cpp.

◆ onInitialize()

void FIX::SocketAcceptor::onInitialize ( const SessionSettings )
throw (RuntimeError
)
privatevirtual

Implemented to initialize acceptor.

Reimplemented from FIX::Acceptor.

Definition at line 89 of file SocketAcceptor.cpp.

89  : true;
90 
91  const bool noDelay = settings.has( SOCKET_NODELAY ) ?
92  settings.getBool( SOCKET_NODELAY ) : false;
93 
94  const int sendBufSize = settings.has( SOCKET_SEND_BUFFER_SIZE ) ?
95  settings.getInt( SOCKET_SEND_BUFFER_SIZE ) : 0;
96 
97  const int rcvBufSize = settings.has( SOCKET_RECEIVE_BUFFER_SIZE ) ?
98  settings.getInt( SOCKET_RECEIVE_BUFFER_SIZE ) : 0;
99 
100  m_portToSessions[port].insert( *i );
101  m_pServer->add( port, reuseAddress, noDelay, sendBufSize, rcvBufSize );
102  }
103  }
104  catch( SocketException& e )
105  {
106  throw RuntimeError( "Unable to create, bind, or listen to port "
107  + IntConvertor::convert( (unsigned short)port ) + " (" + e.what() + ")" );
108  }
109 }
110 
112 {
113  while ( !isStopped() && m_pServer && m_pServer->block( *this ) ) {}
114 
115  if( !m_pServer )
116  return;
117 
118  time_t start = 0;
119  time_t now = 0;
120 
121  ::time( &start );
122  while ( isLoggedOn() )
123  {
124  m_pServer->block( *this );
125  if( ::time(&now) -5 >= start )
126  break;

◆ onPoll()

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

Implemented to connect and poll for events.

Implements FIX::Acceptor.

Definition at line 151 of file SocketAcceptor.cpp.

152  {
153  start = 0;
154  return false;
155  }
156  }
157 
158  m_pServer->block( *this, true, timeout );
159  return true;
160 }
161 
163 {
164 }
165 
166 void SocketAcceptor::onConnect( SocketServer& server, int a, int s )
167 {
168  if ( !socket_isValid( s ) ) return;
169  SocketConnections::iterator i = m_connections.find( s );
170  if ( i != m_connections.end() ) return;
171  int port = server.socketToPort( a );
172  Sessions sessions = m_portToSessions[port];
173  m_connections[ s ] = new SocketConnection( s, sessions, &server.getMonitor() );
174 
175  std::stringstream stream;
176  stream << "Accepted connection from " << socket_peername( s ) << " on port " << port;
177 

References FIX::Acceptor::start().

◆ onStart()

void FIX::SocketAcceptor::onStart ( )
privatevirtual

Implemented to start listening for connections.

Implements FIX::Acceptor.

Definition at line 128 of file SocketAcceptor.cpp.

135 {
136  if( !m_pServer )
137  return false;
138 
139  time_t start = 0;
140  time_t now = 0;
141 
142  if( isStopped() )
143  {
144  if( start == 0 )
145  ::time( &start );
146  if( !isLoggedOn() )
147  {
148  start = 0;
149  return false;

◆ onStop()

void FIX::SocketAcceptor::onStop ( )
privatevirtual

Implemented to stop a running acceptor.

Implements FIX::Acceptor.

Definition at line 179 of file SocketAcceptor.cpp.

◆ onTimeout()

void FIX::SocketAcceptor::onTimeout ( SocketServer )
privatevirtual

Reimplemented from FIX::SocketServer::Strategy.

Definition at line 233 of file SocketAcceptor.cpp.

◆ onWrite()

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

Implements FIX::SocketServer::Strategy.

Definition at line 199 of file SocketAcceptor.cpp.

200 {
201  SocketConnections::iterator i = m_connections.find( s );
202  if ( i == m_connections.end() ) return ;
203  SocketConnection* pSocketConnection = i->second;
204 
205  Session* pSession = pSocketConnection->getSession();
206  if ( pSession ) pSession->disconnect();

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

◆ readSettings()

bool FIX::SocketAcceptor::readSettings ( const SessionSettings )
private

Friends And Related Function Documentation

◆ SocketConnection

friend class SocketConnection
friend

Definition at line 72 of file SocketAcceptor.h.

Member Data Documentation

◆ m_connections

SocketConnections FIX::SocketAcceptor::m_connections
private

Definition at line 104 of file SocketAcceptor.h.

Referenced by onConnect(), onDisconnect(), and onWrite().

◆ m_portToSessions

PortToSessions FIX::SocketAcceptor::m_portToSessions
private

Definition at line 103 of file SocketAcceptor.h.

◆ m_pServer

SocketServer* FIX::SocketAcceptor::m_pServer
private

Definition at line 102 of file SocketAcceptor.h.


The documentation for this class was generated from the following files:
FIX::SOCKET_RECEIVE_BUFFER_SIZE
const char SOCKET_RECEIVE_BUFFER_SIZE[]
Definition: SessionSettings.h:87
FIX::SOCKET_NODELAY
const char SOCKET_NODELAY[]
Definition: SessionSettings.h:85
FIX::SocketAcceptor::SocketConnection
friend class SocketConnection
Definition: SocketAcceptor.h:72
FIX::SocketAcceptor::onConnect
void onConnect(SocketServer &, int, int)
Definition: SocketAcceptor.cpp:183
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:165
FIX::Acceptor::start
void start()
Start acceptor.
Definition: Acceptor.cpp:175
FIX::SOCKET_SEND_BUFFER_SIZE
const char SOCKET_SEND_BUFFER_SIZE[]
Definition: SessionSettings.h:86
FIX::socket_isValid
bool socket_isValid(int socket)
Definition: Utility.cpp:294
FIX::SOCKET_ACCEPT_PORT
const char SOCKET_ACCEPT_PORT[]
Definition: SessionSettings.h:79
FIX::SocketAcceptor::onStop
void onStop()
Implemented to stop a running acceptor.
Definition: SocketAcceptor.cpp:179
FIX::SocketAcceptor::m_pServer
SocketServer * m_pServer
Definition: SocketAcceptor.h:102
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:170
FIX::Acceptor::isLoggedOn
bool isLoggedOn()
Check to see if any sessions are currently logged on.
Definition: Acceptor.cpp:247
FIX::SocketAcceptor::m_connections
SocketConnections m_connections
Definition: SocketAcceptor.h:104
FIX::SocketAcceptor::Sessions
std::set< SessionID > Sessions
Definition: SocketAcceptor.h:84
FIX::SocketAcceptor::m_portToSessions
PortToSessions m_portToSessions
Definition: SocketAcceptor.h:103
FIX::SocketAcceptor::onData
bool onData(SocketServer &, int)
Definition: SocketAcceptor.cpp:208
FIX::Acceptor::isStopped
bool isStopped()
Definition: Acceptor.h:104
FIX::SocketAcceptor::onStart
void onStart()
Implemented to start listening for connections.
Definition: SocketAcceptor.cpp:128
FIX::SocketServer::add
int add(int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0)
Definition: SocketServer.cpp:114
FIX::socket_peername
const char * socket_peername(int socket)
Definition: Utility.cpp:370

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