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


Public Member Functions | |
| SocketInitiator (Application &, MessageStoreFactory &, const SessionSettings &) throw ( ConfigError ) | |
| SocketInitiator (Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) throw ( ConfigError ) | |
| virtual | ~SocketInitiator () |
Private Types | |
| typedef std::map< int, SocketConnection * > | SocketConnections |
| typedef std::map< SessionID, int > | SessionToHostNum |
Private Member Functions | |
| void | onConfigure (const SessionSettings &) throw ( ConfigError ) |
| Implemented to configure acceptor. | |
| void | onInitialize (const SessionSettings &) throw ( RuntimeError ) |
| Implemented to initialize initiator. | |
| void | onStart () |
| Implemented to start connecting to targets. | |
| bool | onPoll () |
| Implemented to connect and poll for events. | |
| void | onStop () |
| Implemented to stop a running initiator. | |
| bool | doConnect (const SessionID &, const Dictionary &d) |
| Implemented to connect a session to its target. | |
| void | onConnect (SocketConnector &, int) |
| void | onWrite (SocketConnector &, int) |
| void | onData (SocketConnector &, int) |
| void | onDisconnect (SocketConnector &, int) |
| void | onError (SocketConnector &) |
| void | onTimeout (SocketConnector &) |
| void | getHost (const SessionID &, const Dictionary &, std::string &, short &) |
Private Attributes | |
| SessionSettings | m_settings |
| SessionToHostNum | m_sessionToHostNum |
| SocketConnector | m_connector |
| SocketConnections | m_pendingConnections |
| SocketConnections | m_connections |
| time_t | m_lastConnect |
| int | m_reconnectInterval |
| bool | m_noDelay |
| bool | m_stop |
Definition at line 36 of file SocketInitiator.h.
|
|
Definition at line 48 of file SocketInitiator.h. |
|
|
Definition at line 47 of file SocketInitiator.h. |
|
||||||||||||||||
|
Definition at line 33 of file SocketInitiator.cpp.
00037 : Initiator( application, factory, settings ), 00038 m_connector( 1 ), m_lastConnect( 0 ), 00039 m_reconnectInterval( 30 ), m_noDelay( false ) {} |
|
||||||||||||||||||||
|
Definition at line 41 of file SocketInitiator.cpp.
00046 : Initiator( application, factory, settings, logFactory ), 00047 m_connector( 1 ), m_lastConnect( 0 ), 00048 m_reconnectInterval( 30 ), m_noDelay( false ) {} |
|
|
Definition at line 50 of file SocketInitiator.cpp. References m_pendingConnections.
00051 {
00052 SocketConnections::iterator i;
00053 for (i = m_connections.begin();
00054 i != m_connections.end(); ++i)
00055 delete i->second;
00056
00057 for (i = m_pendingConnections.begin();
00058 i != m_pendingConnections.end(); ++i)
00059 delete i->second;
00060
00061 }
|
|
||||||||||||
|
Implemented to connect a session to its target.
Implements FIX::Initiator. Definition at line 129 of file SocketInitiator.cpp. References FIX::SocketConnector::connect(), getHost(), FIX::Session::getLog(), FIX::SocketConnector::getMonitor(), FIX::Session::isSessionTime(), m_noDelay, m_pendingConnections, FIX::Log::onEvent(), QF_STACK_POP, QF_STACK_PUSH, and FIX::Initiator::setPending().
00130 { QF_STACK_PUSH(SocketInitiator::doConnect)
00131
00132 try
00133 {
00134 std::string address;
00135 short port = 0;
00136 Session* session = Session::lookupSession( s );
00137 if( !session->isSessionTime() ) return false;
00138
00139 Log* log = session->getLog();
00140
00141 getHost( s, d, address, port );
00142
00143 log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) );
00144 int result = m_connector.connect( address, port, m_noDelay );
00145 setPending( s );
00146
00147 m_pendingConnections[ result ]
00148 = new SocketConnection( *this, s, result, &m_connector.getMonitor() );
00149
00150 return true;
00151 }
00152 catch ( std::exception& ) { return false; }
00153
00154 QF_STACK_POP
00155 }
|
|
||||||||||||||||||||
|
Definition at line 245 of file SocketInitiator.cpp. References FIX::Dictionary::getLong(), FIX::Dictionary::getString(), m_sessionToHostNum, QF_STACK_POP, QF_STACK_PUSH, FIX::SOCKET_CONNECT_HOST, and FIX::SOCKET_CONNECT_PORT. Referenced by doConnect().
00247 { QF_STACK_PUSH(SocketInitiator::getHost)
00248
00249 int num = 0;
00250 SessionToHostNum::iterator i = m_sessionToHostNum.find( s );
00251 if ( i != m_sessionToHostNum.end() ) num = i->second;
00252
00253 try
00254 {
00255 std::stringstream hostStream;
00256 hostStream << SOCKET_CONNECT_HOST << num;
00257 address = d.getString( hostStream.str() );
00258
00259 std::stringstream portStream;
00260 portStream << SOCKET_CONNECT_PORT << num;
00261 port = ( short ) d.getLong( portStream.str() );
00262 }
00263 catch ( ConfigError& )
00264 {
00265 num = 0;
00266 address = d.getString( SOCKET_CONNECT_HOST );
00267 port = ( short ) d.getLong( SOCKET_CONNECT_PORT );
00268 }
00269 m_sessionToHostNum[ s ] = ++num;
00270
00271 QF_STACK_POP
00272 }
|
|
|
Implemented to configure acceptor.
Reimplemented from FIX::Initiator. Definition at line 63 of file SocketInitiator.cpp. References QF_STACK_POP, QF_STACK_PUSH, FIX::RECONNECT_INTERVAL, and FIX::SOCKET_NODELAY.
00065 { QF_STACK_PUSH(SocketInitiator::onConfigure)
00066
00067 try { m_reconnectInterval = s.get().getLong( RECONNECT_INTERVAL ); }
00068 catch ( std::exception& ) {}
00069 if( s.get().has( SOCKET_NODELAY ) )
00070 m_noDelay = s.get().getBool( SOCKET_NODELAY );
00071
00072 QF_STACK_POP
00073 }
|
|
||||||||||||
|
Implements FIX::SocketConnector::Strategy. Definition at line 157 of file SocketInitiator.cpp. References m_pendingConnections, QF_STACK_POP, QF_STACK_PUSH, and FIX::Initiator::setConnected().
00158 { QF_STACK_PUSH(SocketInitiator::onConnect)
00159
00160 SocketConnections::iterator i = m_pendingConnections.find( s );
00161 if( i == m_pendingConnections.end() ) return;
00162 SocketConnection* pSocketConnection = i->second;
00163
00164 m_connections[s] = pSocketConnection;
00165 m_pendingConnections.erase( i );
00166 setConnected( pSocketConnection->getSession()->getSessionID() );
00167
00168 QF_STACK_POP
00169 }
|
|
||||||||||||
|
Implements FIX::SocketConnector::Strategy. Definition at line 183 of file SocketInitiator.cpp. References QF_STACK_POP, QF_STACK_PUSH, and FIX::SocketConnection::read().
00184 { QF_STACK_PUSH(SocketInitiator::onData)
00185
00186 SocketConnections::iterator i = m_connections.find( s );
00187 if ( i == m_connections.end() ) return ;
00188 SocketConnection* pSocketConnection = i->second;
00189 pSocketConnection->read( connector );
00190
00191 QF_STACK_POP
00192 }
|
|
||||||||||||
|
Implements FIX::SocketConnector::Strategy. Definition at line 194 of file SocketInitiator.cpp. References FIX::Session::disconnect(), FIX::SocketConnection::getSession(), FIX::Session::getSessionID(), m_pendingConnections, QF_STACK_POP, QF_STACK_PUSH, and FIX::Initiator::setDisconnected().
00195 { QF_STACK_PUSH(SocketInitiator::onDisconnect)
00196
00197 SocketConnections::iterator i = m_connections.find( s );
00198 SocketConnections::iterator j = m_pendingConnections.find( s );
00199
00200 if ( i == m_connections.end() && j == m_pendingConnections.end() )
00201 return;
00202
00203 SocketConnection* pSocketConnection = i->second;
00204 setDisconnected( pSocketConnection->getSession()->getSessionID() );
00205
00206 Session* pSession = pSocketConnection->getSession();
00207 if ( pSession )
00208 {
00209 pSession->disconnect();
00210 setDisconnected( pSession->getSessionID() );
00211 }
00212
00213 delete pSocketConnection;
00214 m_connections.erase( s );
00215 m_pendingConnections.erase( s );
00216
00217 QF_STACK_POP
00218 }
|
|
|
Implements FIX::SocketConnector::Strategy. Definition at line 220 of file SocketInitiator.cpp. References onTimeout(), QF_STACK_POP, and QF_STACK_PUSH.
00221 { QF_STACK_PUSH(SocketInitiator::onError)
00222 onTimeout( connector );
00223 QF_STACK_POP
00224 }
|
|
|
Implemented to initialize initiator.
Reimplemented from FIX::Initiator. Definition at line 75 of file SocketInitiator.cpp. References QF_STACK_POP, and QF_STACK_PUSH.
00077 { QF_STACK_PUSH(SocketInitiator::onInitialize)
00078 QF_STACK_POP
00079 }
|
|
|
Implemented to connect and poll for events.
Implements FIX::Initiator. Definition at line 102 of file SocketInitiator.cpp. References FIX::SocketConnector::block(), FIX::Initiator::isLoggedOn(), FIX::Initiator::isStopped(), QF_STACK_POP, and QF_STACK_PUSH.
00103 { QF_STACK_PUSH(SocketInitiator::onPoll)
00104
00105 time_t start = 0;
00106 time_t now = 0;
00107
00108 if( isStopped() )
00109 {
00110 if( start == 0 )
00111 ::time( &start );
00112 if( !isLoggedOn() )
00113 return false;
00114 if( ::time(&now) - 5 >= start )
00115 return false;
00116 }
00117
00118 m_connector.block( *this, true );
00119 return true;
00120
00121 QF_STACK_POP
00122 }
|
|
|
Implemented to start connecting to targets.
Implements FIX::Initiator. Definition at line 81 of file SocketInitiator.cpp. References FIX::SocketConnector::block(), FIX::Initiator::connect(), FIX::Initiator::isLoggedOn(), FIX::Initiator::isStopped(), QF_STACK_POP, and QF_STACK_PUSH.
00082 { QF_STACK_PUSH(SocketInitiator::onStart)
00083
00084 connect();
00085 while ( !isStopped() )
00086 m_connector.block( *this );
00087
00088 time_t start = 0;
00089 time_t now = 0;
00090
00091 ::time( &start );
00092 while ( isLoggedOn() )
00093 {
00094 m_connector.block( *this );
00095 if( ::time(&now) -5 >= start )
00096 break;
00097 }
00098
00099 QF_STACK_POP
00100 }
|
|
|
Implemented to stop a running initiator.
Implements FIX::Initiator. Definition at line 124 of file SocketInitiator.cpp. References QF_STACK_POP, and QF_STACK_PUSH.
00125 { QF_STACK_PUSH(SocketInitiator::onStop)
00126 QF_STACK_POP
00127 }
|
|
|
Reimplemented from FIX::SocketConnector::Strategy. Definition at line 226 of file SocketInitiator.cpp. References FIX::Initiator::connect(), m_lastConnect, m_reconnectInterval, QF_STACK_POP, and QF_STACK_PUSH. Referenced by onError().
00227 { QF_STACK_PUSH(SocketInitiator::onTimeout)
00228
00229 time_t now;
00230 ::time( &now );
00231
00232 if ( (now - m_lastConnect) >= m_reconnectInterval )
00233 {
00234 connect();
00235 m_lastConnect = now;
00236 }
00237
00238 SocketConnections::iterator i;
00239 for ( i = m_connections.begin(); i != m_connections.end(); ++i )
00240 i->second->onTimeout();
00241
00242 QF_STACK_POP
00243 }
|
|
||||||||||||
|
Implements FIX::SocketConnector::Strategy. Definition at line 171 of file SocketInitiator.cpp. References FIX::SocketConnection::processQueue(), QF_STACK_POP, QF_STACK_PUSH, and FIX::SocketConnection::unsignal().
00172 { QF_STACK_PUSH(SocketInitiator::onWrite)
00173
00174 SocketConnections::iterator i = m_connections.find( s );
00175 if ( i == m_connections.end() ) return ;
00176 SocketConnection* pSocketConnection = i->second;
00177 if( pSocketConnection->processQueue() )
00178 pSocketConnection->unsignal();
00179
00180 QF_STACK_POP
00181 }
|
|
|
Definition at line 71 of file SocketInitiator.h. |
|
|
Definition at line 69 of file SocketInitiator.h. |
|
|
Definition at line 72 of file SocketInitiator.h. Referenced by onTimeout(). |
|
|
Definition at line 74 of file SocketInitiator.h. Referenced by doConnect(). |
|
|
Definition at line 70 of file SocketInitiator.h. Referenced by doConnect(), onConnect(), onDisconnect(), and ~SocketInitiator(). |
|
|
Definition at line 73 of file SocketInitiator.h. Referenced by onTimeout(). |
|
|
Definition at line 68 of file SocketInitiator.h. Referenced by getHost(). |
|
|
Reimplemented from FIX::Initiator. Definition at line 67 of file SocketInitiator.h. |
|
|
Reimplemented from FIX::Initiator. Definition at line 75 of file SocketInitiator.h. |
1.3.6-20040222 written by Dimitri van Heesch,
© 1997-2001