quickfix_ruby 1.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/quickfix/Acceptor.cpp +248 -0
- data/ext/quickfix/Acceptor.h +127 -0
- data/ext/quickfix/Allocator.h +9 -0
- data/ext/quickfix/Application.h +127 -0
- data/ext/quickfix/AtomicCount.h +109 -0
- data/ext/quickfix/DOMDocument.h +74 -0
- data/ext/quickfix/DataDictionary.cpp +618 -0
- data/ext/quickfix/DataDictionary.h +539 -0
- data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
- data/ext/quickfix/DataDictionaryProvider.h +70 -0
- data/ext/quickfix/DatabaseConnectionID.h +105 -0
- data/ext/quickfix/DatabaseConnectionPool.h +91 -0
- data/ext/quickfix/Dictionary.cpp +162 -0
- data/ext/quickfix/Dictionary.h +94 -0
- data/ext/quickfix/Event.h +95 -0
- data/ext/quickfix/Exceptions.h +299 -0
- data/ext/quickfix/Field.h +672 -0
- data/ext/quickfix/FieldConvertors.h +863 -0
- data/ext/quickfix/FieldMap.cpp +238 -0
- data/ext/quickfix/FieldMap.h +244 -0
- data/ext/quickfix/FieldNumbers.h +46 -0
- data/ext/quickfix/FieldTypes.cpp +64 -0
- data/ext/quickfix/FieldTypes.h +698 -0
- data/ext/quickfix/Fields.h +31 -0
- data/ext/quickfix/FileLog.cpp +200 -0
- data/ext/quickfix/FileLog.h +112 -0
- data/ext/quickfix/FileStore.cpp +332 -0
- data/ext/quickfix/FileStore.h +129 -0
- data/ext/quickfix/FixFieldNumbers.h +1537 -0
- data/ext/quickfix/FixFields.h +1538 -0
- data/ext/quickfix/FixValues.h +3281 -0
- data/ext/quickfix/FlexLexer.h +188 -0
- data/ext/quickfix/Group.cpp +64 -0
- data/ext/quickfix/Group.h +73 -0
- data/ext/quickfix/HtmlBuilder.h +186 -0
- data/ext/quickfix/HttpConnection.cpp +739 -0
- data/ext/quickfix/HttpConnection.h +78 -0
- data/ext/quickfix/HttpMessage.cpp +149 -0
- data/ext/quickfix/HttpMessage.h +133 -0
- data/ext/quickfix/HttpParser.cpp +49 -0
- data/ext/quickfix/HttpParser.h +54 -0
- data/ext/quickfix/HttpServer.cpp +169 -0
- data/ext/quickfix/HttpServer.h +78 -0
- data/ext/quickfix/Initiator.cpp +289 -0
- data/ext/quickfix/Initiator.h +149 -0
- data/ext/quickfix/Log.cpp +77 -0
- data/ext/quickfix/Log.h +179 -0
- data/ext/quickfix/Message.cpp +580 -0
- data/ext/quickfix/Message.h +370 -0
- data/ext/quickfix/MessageCracker.h +188 -0
- data/ext/quickfix/MessageSorters.cpp +105 -0
- data/ext/quickfix/MessageSorters.h +156 -0
- data/ext/quickfix/MessageStore.cpp +146 -0
- data/ext/quickfix/MessageStore.h +174 -0
- data/ext/quickfix/Mutex.h +131 -0
- data/ext/quickfix/MySQLConnection.h +194 -0
- data/ext/quickfix/MySQLLog.cpp +275 -0
- data/ext/quickfix/MySQLLog.h +145 -0
- data/ext/quickfix/MySQLStore.cpp +331 -0
- data/ext/quickfix/MySQLStore.h +142 -0
- data/ext/quickfix/NullStore.cpp +54 -0
- data/ext/quickfix/NullStore.h +99 -0
- data/ext/quickfix/OdbcConnection.h +266 -0
- data/ext/quickfix/OdbcLog.cpp +252 -0
- data/ext/quickfix/OdbcLog.h +117 -0
- data/ext/quickfix/OdbcStore.cpp +338 -0
- data/ext/quickfix/OdbcStore.h +113 -0
- data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
- data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
- data/ext/quickfix/Parser.cpp +103 -0
- data/ext/quickfix/Parser.h +57 -0
- data/ext/quickfix/PostgreSQLConnection.h +176 -0
- data/ext/quickfix/PostgreSQLLog.cpp +276 -0
- data/ext/quickfix/PostgreSQLLog.h +144 -0
- data/ext/quickfix/PostgreSQLStore.cpp +334 -0
- data/ext/quickfix/PostgreSQLStore.h +141 -0
- data/ext/quickfix/Queue.h +75 -0
- data/ext/quickfix/QuickfixRuby.cpp +252066 -0
- data/ext/quickfix/QuickfixRuby.h +34 -0
- data/ext/quickfix/Responder.h +43 -0
- data/ext/quickfix/Session.cpp +1487 -0
- data/ext/quickfix/Session.h +335 -0
- data/ext/quickfix/SessionFactory.cpp +274 -0
- data/ext/quickfix/SessionFactory.h +86 -0
- data/ext/quickfix/SessionID.h +170 -0
- data/ext/quickfix/SessionSettings.cpp +189 -0
- data/ext/quickfix/SessionSettings.h +171 -0
- data/ext/quickfix/SessionState.h +231 -0
- data/ext/quickfix/Settings.cpp +100 -0
- data/ext/quickfix/Settings.h +53 -0
- data/ext/quickfix/SharedArray.h +150 -0
- data/ext/quickfix/SocketAcceptor.cpp +222 -0
- data/ext/quickfix/SocketAcceptor.h +75 -0
- data/ext/quickfix/SocketConnection.cpp +238 -0
- data/ext/quickfix/SocketConnection.h +103 -0
- data/ext/quickfix/SocketConnector.cpp +116 -0
- data/ext/quickfix/SocketConnector.h +67 -0
- data/ext/quickfix/SocketInitiator.cpp +260 -0
- data/ext/quickfix/SocketInitiator.h +81 -0
- data/ext/quickfix/SocketMonitor.cpp +335 -0
- data/ext/quickfix/SocketMonitor.h +111 -0
- data/ext/quickfix/SocketServer.cpp +177 -0
- data/ext/quickfix/SocketServer.h +100 -0
- data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
- data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
- data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
- data/ext/quickfix/ThreadedSocketConnection.h +82 -0
- data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
- data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
- data/ext/quickfix/TimeRange.cpp +173 -0
- data/ext/quickfix/TimeRange.h +258 -0
- data/ext/quickfix/Utility.cpp +537 -0
- data/ext/quickfix/Utility.h +219 -0
- data/ext/quickfix/Values.h +62 -0
- data/ext/quickfix/config.h +0 -0
- data/ext/quickfix/config_windows.h +0 -0
- data/ext/quickfix/extconf.rb +12 -0
- data/ext/quickfix/index.h +37 -0
- data/ext/quickfix/pugiconfig.hpp +72 -0
- data/ext/quickfix/pugixml.cpp +10765 -0
- data/ext/quickfix/pugixml.hpp +1341 -0
- data/ext/quickfix/strptime.h +7 -0
- data/lib/quickfix40.rb +274 -0
- data/lib/quickfix41.rb +351 -0
- data/lib/quickfix42.rb +1184 -0
- data/lib/quickfix43.rb +3504 -0
- data/lib/quickfix44.rb +10721 -0
- data/lib/quickfix50.rb +13426 -0
- data/lib/quickfix50sp1.rb +15629 -0
- data/lib/quickfix50sp2.rb +17068 -0
- data/lib/quickfix_fields.rb +19853 -0
- data/lib/quickfix_ruby.rb +82 -0
- data/lib/quickfixt11.rb +70 -0
- data/spec/FIX40.xml +862 -0
- data/spec/FIX41.xml +1285 -0
- data/spec/FIX42.xml +2746 -0
- data/spec/FIX43.xml +4229 -0
- data/spec/FIX44.xml +6596 -0
- data/spec/FIX50.xml +8137 -0
- data/spec/FIX50SP1.xml +9496 -0
- data/spec/FIX50SP2.xml +10011 -0
- data/spec/FIXT11.xml +313 -0
- data/test/test_DataDictionaryTestCase.rb +268 -0
- data/test/test_DictionaryTestCase.rb +112 -0
- data/test/test_FieldBaseTestCase.rb +24 -0
- data/test/test_MessageTestCase.rb +368 -0
- data/test/test_SessionSettingsTestCase.rb +41 -0
- metadata +193 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
** Copyright (c) 2001-2014
|
|
3
|
+
**
|
|
4
|
+
** This file is part of the QuickFIX FIX Engine
|
|
5
|
+
**
|
|
6
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
|
7
|
+
** license as defined by quickfixengine.org and appearing in the file
|
|
8
|
+
** LICENSE included in the packaging of this file.
|
|
9
|
+
**
|
|
10
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
11
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
**
|
|
13
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
|
14
|
+
**
|
|
15
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
|
16
|
+
** not clear to you.
|
|
17
|
+
**
|
|
18
|
+
****************************************************************************/
|
|
19
|
+
|
|
20
|
+
#ifdef _MSC_VER
|
|
21
|
+
#include "stdafx.h"
|
|
22
|
+
#else
|
|
23
|
+
#include "config.h"
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#include "SocketConnector.h"
|
|
27
|
+
#include "Utility.h"
|
|
28
|
+
#ifndef _MSC_VER
|
|
29
|
+
#include <unistd.h>
|
|
30
|
+
#include <sys/ioctl.h>
|
|
31
|
+
#include <sys/types.h>
|
|
32
|
+
#include <sys/stat.h>
|
|
33
|
+
#endif
|
|
34
|
+
#include <iostream>
|
|
35
|
+
|
|
36
|
+
namespace FIX
|
|
37
|
+
{
|
|
38
|
+
/// Handles events from SocketMonitor for client connections.
|
|
39
|
+
class ConnectorWrapper : public SocketMonitor::Strategy
|
|
40
|
+
{
|
|
41
|
+
public:
|
|
42
|
+
ConnectorWrapper( SocketConnector& connector,
|
|
43
|
+
SocketConnector::Strategy& strategy )
|
|
44
|
+
: m_connector( connector ), m_strategy( strategy ) {}
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
void onConnect( SocketMonitor&, int socket )
|
|
48
|
+
{
|
|
49
|
+
m_strategy.onConnect( m_connector, socket );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void onWrite( SocketMonitor&, int socket )
|
|
53
|
+
{
|
|
54
|
+
m_strategy.onWrite( m_connector, socket );
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void onEvent( SocketMonitor&, int socket )
|
|
58
|
+
{
|
|
59
|
+
if( !m_strategy.onData( m_connector, socket ) )
|
|
60
|
+
m_strategy.onDisconnect( m_connector, socket );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void onError( SocketMonitor&, int socket )
|
|
64
|
+
{
|
|
65
|
+
m_strategy.onDisconnect( m_connector, socket );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void onError( SocketMonitor& )
|
|
69
|
+
{
|
|
70
|
+
m_strategy.onError( m_connector );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
void onTimeout( SocketMonitor& )
|
|
74
|
+
{
|
|
75
|
+
m_strategy.onTimeout( m_connector );
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
SocketConnector& m_connector;
|
|
79
|
+
SocketConnector::Strategy& m_strategy;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
SocketConnector::SocketConnector( int timeout )
|
|
83
|
+
: m_monitor( timeout ) {}
|
|
84
|
+
|
|
85
|
+
int SocketConnector::connect( const std::string& address, int port, bool noDelay,
|
|
86
|
+
int sendBufSize, int rcvBufSize )
|
|
87
|
+
{
|
|
88
|
+
int socket = socket_createConnector();
|
|
89
|
+
|
|
90
|
+
if ( socket != -1 )
|
|
91
|
+
{
|
|
92
|
+
if( noDelay )
|
|
93
|
+
socket_setsockopt( socket, TCP_NODELAY );
|
|
94
|
+
if( sendBufSize )
|
|
95
|
+
socket_setsockopt( socket, SO_SNDBUF, sendBufSize );
|
|
96
|
+
if( rcvBufSize )
|
|
97
|
+
socket_setsockopt( socket, SO_RCVBUF, rcvBufSize );
|
|
98
|
+
m_monitor.addConnect( socket );
|
|
99
|
+
socket_connect( socket, address.c_str(), port );
|
|
100
|
+
}
|
|
101
|
+
return socket;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
int SocketConnector::connect( const std::string& address, int port, bool noDelay,
|
|
105
|
+
int sendBufSize, int rcvBufSize, Strategy& strategy )
|
|
106
|
+
{
|
|
107
|
+
int socket = connect( address, port, noDelay, sendBufSize, rcvBufSize );
|
|
108
|
+
return socket;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void SocketConnector::block( Strategy& strategy, bool poll, double timeout )
|
|
112
|
+
{
|
|
113
|
+
ConnectorWrapper wrapper( *this, strategy );
|
|
114
|
+
m_monitor.block( wrapper, poll, timeout );
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* -*- C++ -*- */
|
|
2
|
+
|
|
3
|
+
/****************************************************************************
|
|
4
|
+
** Copyright (c) 2001-2014
|
|
5
|
+
**
|
|
6
|
+
** This file is part of the QuickFIX FIX Engine
|
|
7
|
+
**
|
|
8
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
|
9
|
+
** license as defined by quickfixengine.org and appearing in the file
|
|
10
|
+
** LICENSE included in the packaging of this file.
|
|
11
|
+
**
|
|
12
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
13
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
+
**
|
|
15
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
|
16
|
+
**
|
|
17
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
|
18
|
+
** not clear to you.
|
|
19
|
+
**
|
|
20
|
+
****************************************************************************/
|
|
21
|
+
|
|
22
|
+
#ifndef FIX_SOCKETCONNECTOR_H
|
|
23
|
+
#define FIX_SOCKETCONNECTOR_H
|
|
24
|
+
|
|
25
|
+
#ifdef _MSC_VER
|
|
26
|
+
#pragma warning( disable : 4503 4355 4786 4290 )
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#include "SocketMonitor.h"
|
|
30
|
+
#include <string>
|
|
31
|
+
|
|
32
|
+
namespace FIX
|
|
33
|
+
{
|
|
34
|
+
/// Connects sockets to remote ports and addresses.
|
|
35
|
+
class SocketConnector
|
|
36
|
+
{
|
|
37
|
+
public:
|
|
38
|
+
class Strategy;
|
|
39
|
+
|
|
40
|
+
SocketConnector( int timeout = 0 );
|
|
41
|
+
|
|
42
|
+
int connect( const std::string& address, int port, bool noDelay,
|
|
43
|
+
int sendBufSize, int rcvBufSize );
|
|
44
|
+
int connect( const std::string& address, int port, bool noDelay,
|
|
45
|
+
int sendBufSize, int rcvBufSize, Strategy& );
|
|
46
|
+
void block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
|
|
47
|
+
SocketMonitor& getMonitor() { return m_monitor; }
|
|
48
|
+
|
|
49
|
+
private:
|
|
50
|
+
SocketMonitor m_monitor;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
class Strategy
|
|
54
|
+
{
|
|
55
|
+
public:
|
|
56
|
+
virtual ~Strategy() {}
|
|
57
|
+
virtual void onConnect( SocketConnector&, int socket ) = 0;
|
|
58
|
+
virtual void onWrite( SocketConnector&, int socket ) = 0;
|
|
59
|
+
virtual bool onData( SocketConnector&, int socket ) = 0;
|
|
60
|
+
virtual void onDisconnect( SocketConnector&, int socket ) = 0;
|
|
61
|
+
virtual void onError( SocketConnector& ) = 0;
|
|
62
|
+
virtual void onTimeout( SocketConnector& ) {};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#endif //FIX_SOCKETCONNECTOR_H
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
** Copyright (c) 2001-2014
|
|
3
|
+
**
|
|
4
|
+
** This file is part of the QuickFIX FIX Engine
|
|
5
|
+
**
|
|
6
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
|
7
|
+
** license as defined by quickfixengine.org and appearing in the file
|
|
8
|
+
** LICENSE included in the packaging of this file.
|
|
9
|
+
**
|
|
10
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
11
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
**
|
|
13
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
|
14
|
+
**
|
|
15
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
|
16
|
+
** not clear to you.
|
|
17
|
+
**
|
|
18
|
+
****************************************************************************/
|
|
19
|
+
|
|
20
|
+
#ifdef _MSC_VER
|
|
21
|
+
#include "stdafx.h"
|
|
22
|
+
#else
|
|
23
|
+
#include "config.h"
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#include "SocketInitiator.h"
|
|
27
|
+
#include "Session.h"
|
|
28
|
+
#include "Settings.h"
|
|
29
|
+
|
|
30
|
+
namespace FIX
|
|
31
|
+
{
|
|
32
|
+
SocketInitiator::SocketInitiator( Application& application,
|
|
33
|
+
MessageStoreFactory& factory,
|
|
34
|
+
const SessionSettings& settings )
|
|
35
|
+
throw( ConfigError )
|
|
36
|
+
: Initiator( application, factory, settings ),
|
|
37
|
+
m_connector( 1 ), m_lastConnect( 0 ),
|
|
38
|
+
m_reconnectInterval( 30 ), m_noDelay( false ), m_sendBufSize( 0 ),
|
|
39
|
+
m_rcvBufSize( 0 )
|
|
40
|
+
{
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
SocketInitiator::SocketInitiator( Application& application,
|
|
44
|
+
MessageStoreFactory& factory,
|
|
45
|
+
const SessionSettings& settings,
|
|
46
|
+
LogFactory& logFactory )
|
|
47
|
+
throw( ConfigError )
|
|
48
|
+
: Initiator( application, factory, settings, logFactory ),
|
|
49
|
+
m_connector( 1 ), m_lastConnect( 0 ),
|
|
50
|
+
m_reconnectInterval( 30 ), m_noDelay( false ), m_sendBufSize( 0 ),
|
|
51
|
+
m_rcvBufSize( 0 )
|
|
52
|
+
{
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
SocketInitiator::~SocketInitiator()
|
|
56
|
+
{
|
|
57
|
+
SocketConnections::iterator i;
|
|
58
|
+
for (i = m_connections.begin();
|
|
59
|
+
i != m_connections.end(); ++i)
|
|
60
|
+
delete i->second;
|
|
61
|
+
|
|
62
|
+
for (i = m_pendingConnections.begin();
|
|
63
|
+
i != m_pendingConnections.end(); ++i)
|
|
64
|
+
delete i->second;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void SocketInitiator::onConfigure( const SessionSettings& s )
|
|
68
|
+
throw ( ConfigError )
|
|
69
|
+
{
|
|
70
|
+
const Dictionary& dict = s.get();
|
|
71
|
+
|
|
72
|
+
if( dict.has( RECONNECT_INTERVAL ) )
|
|
73
|
+
m_reconnectInterval = dict.getInt( RECONNECT_INTERVAL );
|
|
74
|
+
if( dict.has( SOCKET_NODELAY ) )
|
|
75
|
+
m_noDelay = dict.getBool( SOCKET_NODELAY );
|
|
76
|
+
if( dict.has( SOCKET_SEND_BUFFER_SIZE ) )
|
|
77
|
+
m_sendBufSize = dict.getInt( SOCKET_SEND_BUFFER_SIZE );
|
|
78
|
+
if( dict.has( SOCKET_RECEIVE_BUFFER_SIZE ) )
|
|
79
|
+
m_rcvBufSize = dict.getInt( SOCKET_RECEIVE_BUFFER_SIZE );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
void SocketInitiator::onInitialize( const SessionSettings& s )
|
|
83
|
+
throw ( RuntimeError )
|
|
84
|
+
{
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void SocketInitiator::onStart()
|
|
88
|
+
{
|
|
89
|
+
connect();
|
|
90
|
+
|
|
91
|
+
while ( !isStopped() ) {
|
|
92
|
+
m_connector.block( *this, false, 1.0 );
|
|
93
|
+
onTimeout( m_connector );
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
time_t start = 0;
|
|
97
|
+
time_t now = 0;
|
|
98
|
+
|
|
99
|
+
::time( &start );
|
|
100
|
+
while ( isLoggedOn() )
|
|
101
|
+
{
|
|
102
|
+
m_connector.block( *this );
|
|
103
|
+
if( ::time(&now) -5 >= start )
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
bool SocketInitiator::onPoll( double timeout )
|
|
109
|
+
{
|
|
110
|
+
time_t start = 0;
|
|
111
|
+
time_t now = 0;
|
|
112
|
+
|
|
113
|
+
if( isStopped() )
|
|
114
|
+
{
|
|
115
|
+
if( start == 0 )
|
|
116
|
+
::time( &start );
|
|
117
|
+
if( !isLoggedOn() )
|
|
118
|
+
return false;
|
|
119
|
+
if( ::time(&now) - 5 >= start )
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
m_connector.block( *this, true, timeout );
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
void SocketInitiator::onStop()
|
|
128
|
+
{
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
void SocketInitiator::doConnect( const SessionID& s, const Dictionary& d )
|
|
132
|
+
{
|
|
133
|
+
try
|
|
134
|
+
{
|
|
135
|
+
std::string address;
|
|
136
|
+
short port = 0;
|
|
137
|
+
Session* session = Session::lookupSession( s );
|
|
138
|
+
if( !session->isSessionTime(UtcTimeStamp()) ) return;
|
|
139
|
+
|
|
140
|
+
Log* log = session->getLog();
|
|
141
|
+
|
|
142
|
+
getHost( s, d, address, port );
|
|
143
|
+
|
|
144
|
+
log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) );
|
|
145
|
+
int result = m_connector.connect( address, port, m_noDelay, m_sendBufSize, m_rcvBufSize );
|
|
146
|
+
setPending( s );
|
|
147
|
+
|
|
148
|
+
m_pendingConnections[ result ]
|
|
149
|
+
= new SocketConnection( *this, s, result, &m_connector.getMonitor() );
|
|
150
|
+
}
|
|
151
|
+
catch ( std::exception& ) {}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
void SocketInitiator::onConnect( SocketConnector&, int s )
|
|
155
|
+
{
|
|
156
|
+
SocketConnections::iterator i = m_pendingConnections.find( s );
|
|
157
|
+
if( i == m_pendingConnections.end() ) return;
|
|
158
|
+
SocketConnection* pSocketConnection = i->second;
|
|
159
|
+
|
|
160
|
+
m_connections[s] = pSocketConnection;
|
|
161
|
+
m_pendingConnections.erase( i );
|
|
162
|
+
setConnected( pSocketConnection->getSession()->getSessionID() );
|
|
163
|
+
pSocketConnection->onTimeout();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
void SocketInitiator::onWrite( SocketConnector& connector, int s )
|
|
167
|
+
{
|
|
168
|
+
SocketConnections::iterator i = m_connections.find( s );
|
|
169
|
+
if ( i == m_connections.end() ) return ;
|
|
170
|
+
SocketConnection* pSocketConnection = i->second;
|
|
171
|
+
if( pSocketConnection->processQueue() )
|
|
172
|
+
pSocketConnection->unsignal();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
bool SocketInitiator::onData( SocketConnector& connector, int s )
|
|
176
|
+
{
|
|
177
|
+
SocketConnections::iterator i = m_connections.find( s );
|
|
178
|
+
if ( i == m_connections.end() ) return false;
|
|
179
|
+
SocketConnection* pSocketConnection = i->second;
|
|
180
|
+
return pSocketConnection->read( connector );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void SocketInitiator::onDisconnect( SocketConnector&, int s )
|
|
184
|
+
{
|
|
185
|
+
SocketConnections::iterator i = m_connections.find( s );
|
|
186
|
+
SocketConnections::iterator j = m_pendingConnections.find( s );
|
|
187
|
+
|
|
188
|
+
SocketConnection* pSocketConnection = 0;
|
|
189
|
+
if( i != m_connections.end() )
|
|
190
|
+
pSocketConnection = i->second;
|
|
191
|
+
if( j != m_pendingConnections.end() )
|
|
192
|
+
pSocketConnection = j->second;
|
|
193
|
+
if( !pSocketConnection )
|
|
194
|
+
return;
|
|
195
|
+
|
|
196
|
+
setDisconnected( pSocketConnection->getSession()->getSessionID() );
|
|
197
|
+
|
|
198
|
+
Session* pSession = pSocketConnection->getSession();
|
|
199
|
+
if ( pSession )
|
|
200
|
+
{
|
|
201
|
+
pSession->disconnect();
|
|
202
|
+
setDisconnected( pSession->getSessionID() );
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
delete pSocketConnection;
|
|
206
|
+
m_connections.erase( s );
|
|
207
|
+
m_pendingConnections.erase( s );
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
void SocketInitiator::onError( SocketConnector& connector )
|
|
211
|
+
{
|
|
212
|
+
onTimeout( connector );
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void SocketInitiator::onTimeout( SocketConnector& )
|
|
216
|
+
{
|
|
217
|
+
time_t now;
|
|
218
|
+
::time( &now );
|
|
219
|
+
|
|
220
|
+
if ( (now - m_lastConnect) >= m_reconnectInterval )
|
|
221
|
+
{
|
|
222
|
+
connect();
|
|
223
|
+
m_lastConnect = now;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
SocketConnections::iterator i;
|
|
227
|
+
for ( i = m_connections.begin(); i != m_connections.end(); ++i )
|
|
228
|
+
i->second->onTimeout();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void SocketInitiator::getHost( const SessionID& s, const Dictionary& d,
|
|
232
|
+
std::string& address, short& port )
|
|
233
|
+
{
|
|
234
|
+
int num = 0;
|
|
235
|
+
SessionToHostNum::iterator i = m_sessionToHostNum.find( s );
|
|
236
|
+
if ( i != m_sessionToHostNum.end() ) num = i->second;
|
|
237
|
+
|
|
238
|
+
std::stringstream hostStream;
|
|
239
|
+
hostStream << SOCKET_CONNECT_HOST << num;
|
|
240
|
+
std::string hostString = hostStream.str();
|
|
241
|
+
|
|
242
|
+
std::stringstream portStream;
|
|
243
|
+
portStream << SOCKET_CONNECT_PORT << num;
|
|
244
|
+
std::string portString = portStream.str();
|
|
245
|
+
|
|
246
|
+
if( d.has(hostString) && d.has(portString) )
|
|
247
|
+
{
|
|
248
|
+
address = d.getString( hostString );
|
|
249
|
+
port = ( short ) d.getInt( portString );
|
|
250
|
+
}
|
|
251
|
+
else
|
|
252
|
+
{
|
|
253
|
+
num = 0;
|
|
254
|
+
address = d.getString( SOCKET_CONNECT_HOST );
|
|
255
|
+
port = ( short ) d.getInt( SOCKET_CONNECT_PORT );
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
m_sessionToHostNum[ s ] = ++num;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* -*- C++ -*- */
|
|
2
|
+
|
|
3
|
+
/****************************************************************************
|
|
4
|
+
** Copyright (c) 2001-2014
|
|
5
|
+
**
|
|
6
|
+
** This file is part of the QuickFIX FIX Engine
|
|
7
|
+
**
|
|
8
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
|
9
|
+
** license as defined by quickfixengine.org and appearing in the file
|
|
10
|
+
** LICENSE included in the packaging of this file.
|
|
11
|
+
**
|
|
12
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
13
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
+
**
|
|
15
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
|
16
|
+
**
|
|
17
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
|
18
|
+
** not clear to you.
|
|
19
|
+
**
|
|
20
|
+
****************************************************************************/
|
|
21
|
+
|
|
22
|
+
#ifndef FIX_SOCKETINITIATOR_H
|
|
23
|
+
#define FIX_SOCKETINITIATOR_H
|
|
24
|
+
|
|
25
|
+
#ifdef _MSC_VER
|
|
26
|
+
#pragma warning( disable : 4503 4355 4786 4290 )
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#include "Initiator.h"
|
|
30
|
+
#include "SocketConnector.h"
|
|
31
|
+
#include "SocketConnection.h"
|
|
32
|
+
|
|
33
|
+
namespace FIX
|
|
34
|
+
{
|
|
35
|
+
/// Socket implementation of Initiator.
|
|
36
|
+
class SocketInitiator : public Initiator, SocketConnector::Strategy
|
|
37
|
+
{
|
|
38
|
+
public:
|
|
39
|
+
SocketInitiator( Application&, MessageStoreFactory&,
|
|
40
|
+
const SessionSettings& ) throw( ConfigError );
|
|
41
|
+
SocketInitiator( Application&, MessageStoreFactory&,
|
|
42
|
+
const SessionSettings&, LogFactory& ) throw( ConfigError );
|
|
43
|
+
|
|
44
|
+
virtual ~SocketInitiator();
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
typedef std::map < int, SocketConnection* > SocketConnections;
|
|
48
|
+
typedef std::map < SessionID, int > SessionToHostNum;
|
|
49
|
+
|
|
50
|
+
void onConfigure( const SessionSettings& ) throw ( ConfigError );
|
|
51
|
+
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
|
|
52
|
+
|
|
53
|
+
void onStart();
|
|
54
|
+
bool onPoll( double timeout );
|
|
55
|
+
void onStop();
|
|
56
|
+
|
|
57
|
+
void doConnect( const SessionID&, const Dictionary& d );
|
|
58
|
+
void onConnect( SocketConnector&, int );
|
|
59
|
+
void onWrite( SocketConnector&, int );
|
|
60
|
+
bool onData( SocketConnector&, int );
|
|
61
|
+
void onDisconnect( SocketConnector&, int );
|
|
62
|
+
void onError( SocketConnector& );
|
|
63
|
+
void onTimeout( SocketConnector& );
|
|
64
|
+
|
|
65
|
+
void getHost( const SessionID&, const Dictionary&, std::string&, short& );
|
|
66
|
+
|
|
67
|
+
SessionSettings m_settings;
|
|
68
|
+
SessionToHostNum m_sessionToHostNum;
|
|
69
|
+
SocketConnector m_connector;
|
|
70
|
+
SocketConnections m_pendingConnections;
|
|
71
|
+
SocketConnections m_connections;
|
|
72
|
+
time_t m_lastConnect;
|
|
73
|
+
int m_reconnectInterval;
|
|
74
|
+
bool m_noDelay;
|
|
75
|
+
int m_sendBufSize;
|
|
76
|
+
int m_rcvBufSize;
|
|
77
|
+
};
|
|
78
|
+
/*! @} */
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#endif //FIX_SOCKETINITIATOR_H
|