![]() |
![]() |
|
Index
Source Files
Annotated Class List
Alphabetical Class List
Class Hierarchy
Graphical Class Hierarchy
|
||
![]() |
![]() |
#include <SocketAcceptor.h>
Inheritance diagram for FIX::SocketAcceptor:


Public Member Functions | |
| SocketAcceptor (Application &, MessageStoreFactory &, const SessionSettings &) throw ( ConfigError ) | |
| SocketAcceptor (Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) throw ( ConfigError ) | |
| virtual | ~SocketAcceptor () |
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. | |
| void | onInitialize (const SessionSettings &) throw ( RuntimeError ) |
| Implemented to initialize acceptor. | |
| void | onStart () |
| Implemented to start listening for connections. | |
| bool | onPoll () |
| Implemented to connect and poll for events. | |
| void | onStop () |
| Implemented to stop a running acceptor. | |
| void | onConnect (SocketServer &, int, int) |
| void | onWrite (SocketServer &, int) |
| void | onData (SocketServer &, int) |
| void | onDisconnect (SocketServer &, int) |
| void | onError (SocketServer &) |
| void | onTimeout (SocketServer &) |
Private Attributes | |
| SocketServer * | m_pServer |
| PortToSessions | m_portToSessions |
| SocketConnections | m_connections |
Definition at line 36 of file SocketAcceptor.h.
|
|
Definition at line 51 of file SocketAcceptor.h. |
|
|
Reimplemented from FIX::Acceptor. Definition at line 50 of file SocketAcceptor.h. |
|
|
Definition at line 52 of file SocketAcceptor.h. |
|
||||||||||||||||
|
Definition at line 34 of file SocketAcceptor.cpp.
|
|
||||||||||||||||||||
|
Definition at line 40 of file SocketAcceptor.cpp.
|
|
|
Definition at line 47 of file SocketAcceptor.cpp.
00048 {
00049 SocketConnections::iterator iter;
00050 for ( iter = m_connections.begin(); iter != m_connections.end(); ++iter )
00051 delete iter->second;
00052 }
|
|
|
Implemented to configure acceptor.
Reimplemented from FIX::Acceptor. Definition at line 54 of file SocketAcceptor.cpp. References FIX::Dictionary::getBool(), FIX::Dictionary::getLong(), FIX::Dictionary::has(), QF_STACK_POP, QF_STACK_PUSH, FIX::SOCKET_ACCEPT_PORT, FIX::SOCKET_NODELAY, and FIX::SOCKET_REUSE_ADDRESS.
00056 { QF_STACK_PUSH(SocketAcceptor::onConfigure)
00057
00058 std::set<SessionID> sessions = s.getSessions();
00059 std::set<SessionID>::iterator i;
00060 for( i = sessions.begin(); i != sessions.end(); ++i )
00061 {
00062 const Dictionary& settings = s.get( *i );
00063 settings.getLong( SOCKET_ACCEPT_PORT );
00064 if( settings.has(SOCKET_REUSE_ADDRESS) )
00065 settings.getBool( SOCKET_REUSE_ADDRESS );
00066 if( settings.has(SOCKET_NODELAY) )
00067 settings.getBool( SOCKET_NODELAY );
00068 }
00069
00070 QF_STACK_POP
00071 }
|
|
||||||||||||||||
|
Implements FIX::SocketServer::Strategy. Definition at line 165 of file SocketAcceptor.cpp. References FIX::SocketServer::getMonitor(), FIX::Acceptor::log(), m_portToSessions, QF_STACK_POP, QF_STACK_PUSH, FIX::socket_isValid(), FIX::socket_peername(), and FIX::SocketServer::socketToPort().
00166 { QF_STACK_PUSH(SocketAcceptor::onConnect)
00167
00168 if ( !socket_isValid( s ) ) return;
00169 SocketConnections::iterator i = m_connections.find( s );
00170 if ( i != m_connections.end() ) return;
00171 int port = server.socketToPort( a );
00172 Sessions sessions = m_portToSessions[port];
00173 m_connections[ s ] = new SocketConnection( s, sessions, &server.getMonitor() );
00174
00175 std::stringstream stream;
00176 stream << "Accepted connection from " << socket_peername( s ) << " on port " << port;
00177 log( stream.str() );
00178
00179 QF_STACK_POP
00180 }
|
|
||||||||||||
|
Implements FIX::SocketServer::Strategy. Definition at line 194 of file SocketAcceptor.cpp. References QF_STACK_POP, QF_STACK_PUSH, and FIX::SocketConnection::read().
00195 { QF_STACK_PUSH(SocketAcceptor::onData)
00196
00197 SocketConnections::iterator i = m_connections.find( s );
00198 if ( i == m_connections.end() ) return ;
00199 SocketConnection* pSocketConnection = i->second;
00200 pSocketConnection->read( *this, server );
00201
00202 QF_STACK_POP
00203 }
|
|
||||||||||||
|
Implements FIX::SocketServer::Strategy. Definition at line 205 of file SocketAcceptor.cpp. References FIX::Session::disconnect(), FIX::SocketConnection::getSession(), QF_STACK_POP, and QF_STACK_PUSH.
00206 { QF_STACK_PUSH(SocketAcceptor::onDisconnect)
00207
00208 SocketConnections::iterator i = m_connections.find( s );
00209 if ( i == m_connections.end() ) return ;
00210 SocketConnection* pSocketConnection = i->second;
00211
00212 Session* pSession = pSocketConnection->getSession();
00213 if ( pSession ) pSession->disconnect();
00214
00215 delete pSocketConnection;
00216 m_connections.erase( s );
00217
00218 QF_STACK_POP
00219 }
|
|
|
Implements FIX::SocketServer::Strategy. Definition at line 221 of file SocketAcceptor.cpp.
00221 {}
|
|
|
Implemented to initialize acceptor.
Reimplemented from FIX::Acceptor. Definition at line 73 of file SocketAcceptor.cpp. References FIX::Dictionary::getLong(), FIX::Dictionary::has(), QF_STACK_POP, QF_STACK_PUSH, FIX::SOCKET_ACCEPT_PORT, FIX::SOCKET_NODELAY, and FIX::SOCKET_REUSE_ADDRESS.
00075 { QF_STACK_PUSH(SocketAcceptor::onInitialize)
00076
00077 short port = 0;
00078 bool reuseAddress = false;
00079 bool noDelay = false;
00080
00081 try
00082 {
00083 m_pServer = new SocketServer( 1 );
00084
00085 std::set<SessionID> sessions = s.getSessions();
00086 std::set<SessionID>::iterator i = sessions.begin();
00087 for( ; i != sessions.end(); ++i )
00088 {
00089 Dictionary settings = s.get( *i );
00090 port = (short)settings.getLong( SOCKET_ACCEPT_PORT );
00091
00092 if( settings.has( SOCKET_REUSE_ADDRESS ) )
00093 reuseAddress = s.get().getBool( SOCKET_REUSE_ADDRESS );
00094 if( settings.has( SOCKET_NODELAY ) )
00095 noDelay = s.get().getBool( SOCKET_NODELAY );
00096
00097 m_portToSessions[port].insert( *i );
00098 m_pServer->add( port, reuseAddress, noDelay );
00099 }
00100 }
00101 catch( std::exception& )
00102 {
00103 throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)port ) );
00104 }
00105
00106 QF_STACK_POP
00107 }
|
|
|
Implemented to connect and poll for events.
Implements FIX::Acceptor. Definition at line 135 of file SocketAcceptor.cpp. References FIX::SocketServer::block(), FIX::Acceptor::isLoggedOn(), FIX::Acceptor::isStopped(), m_pServer, QF_STACK_POP, and QF_STACK_PUSH.
00136 { QF_STACK_PUSH(SocketAcceptor::onPoll)
00137
00138 if( !m_pServer )
00139 return false;
00140
00141 time_t start = 0;
00142 time_t now = 0;
00143
00144 if( isStopped() )
00145 {
00146 if( start == 0 )
00147 ::time( &start );
00148 if( !isLoggedOn() )
00149 return false;
00150 if( ::time(&now) - 5 >= start )
00151 return false;
00152 }
00153
00154 m_pServer->block( *this, true );
00155 return true;
00156
00157 QF_STACK_POP
00158 }
|
|
|
Implemented to start listening for connections.
Implements FIX::Acceptor. Definition at line 109 of file SocketAcceptor.cpp. References FIX::SocketServer::block(), FIX::SocketServer::close(), FIX::Acceptor::isLoggedOn(), FIX::Acceptor::isStopped(), m_pServer, QF_STACK_POP, and QF_STACK_PUSH.
00110 { QF_STACK_PUSH(SocketAcceptor::onStart)
00111
00112 while ( !isStopped() && m_pServer && m_pServer->block( *this ) ) {}
00113
00114 if( !m_pServer )
00115 return;
00116
00117 time_t start = 0;
00118 time_t now = 0;
00119
00120 ::time( &start );
00121 while ( isLoggedOn() )
00122 {
00123 m_pServer->block( *this );
00124 if( ::time(&now) -5 >= start )
00125 break;
00126 }
00127
00128 m_pServer->close();
00129 delete m_pServer;
00130 m_pServer = 0;
00131
00132 QF_STACK_POP
00133 }
|
|
|
Implemented to stop a running acceptor.
Implements FIX::Acceptor. Definition at line 160 of file SocketAcceptor.cpp. References QF_STACK_POP, and QF_STACK_PUSH.
00161 { QF_STACK_PUSH(SocketAcceptor::onStop)
00162 QF_STACK_POP
00163 }
|
|
|
Reimplemented from FIX::SocketServer::Strategy. Definition at line 223 of file SocketAcceptor.cpp. References QF_STACK_POP, and QF_STACK_PUSH.
00224 { QF_STACK_PUSH(SocketAcceptor::onInitialize)
00225
00226 SocketConnections::iterator i;
00227 for ( i = m_connections.begin(); i != m_connections.end(); ++i )
00228 i->second->onTimeout();
00229
00230 QF_STACK_POP
00231 }
|
|
||||||||||||
|
Implements FIX::SocketServer::Strategy. Definition at line 182 of file SocketAcceptor.cpp. References FIX::SocketConnection::processQueue(), QF_STACK_POP, QF_STACK_PUSH, and FIX::SocketConnection::unsignal().
00183 { QF_STACK_PUSH(SocketAcceptor::onWrite)
00184
00185 SocketConnections::iterator i = m_connections.find( s );
00186 if ( i == m_connections.end() ) return ;
00187 SocketConnection* pSocketConnection = i->second;
00188 if( pSocketConnection->processQueue() )
00189 pSocketConnection->unsignal();
00190
00191 QF_STACK_POP
00192 }
|
|
|
|
|
|
Definition at line 70 of file SocketAcceptor.h. |
|
|
Definition at line 69 of file SocketAcceptor.h. Referenced by onConnect(). |
|
|
Definition at line 68 of file SocketAcceptor.h. |
1.3.6-20040222 written by Dimitri van Heesch,
© 1997-2001