quickfix_ruby_ud 2.0.7-x86_64-linux
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 +257 -0
- data/ext/quickfix/Acceptor.h +127 -0
- data/ext/quickfix/Allocator.h +9 -0
- data/ext/quickfix/Application.h +137 -0
- data/ext/quickfix/DOMDocument.h +70 -0
- data/ext/quickfix/DataDictionary.cpp +679 -0
- data/ext/quickfix/DataDictionary.h +607 -0
- data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
- data/ext/quickfix/DataDictionaryProvider.h +67 -0
- data/ext/quickfix/DatabaseConnectionID.h +98 -0
- data/ext/quickfix/DatabaseConnectionPool.h +84 -0
- data/ext/quickfix/Dictionary.cpp +157 -0
- data/ext/quickfix/Dictionary.h +89 -0
- data/ext/quickfix/Event.h +89 -0
- data/ext/quickfix/Except.h +39 -0
- data/ext/quickfix/Exceptions.h +257 -0
- data/ext/quickfix/Field.h +654 -0
- data/ext/quickfix/FieldConvertors.cpp +86 -0
- data/ext/quickfix/FieldConvertors.h +800 -0
- data/ext/quickfix/FieldMap.cpp +254 -0
- data/ext/quickfix/FieldMap.h +327 -0
- data/ext/quickfix/FieldNumbers.h +44 -0
- data/ext/quickfix/FieldTypes.cpp +62 -0
- data/ext/quickfix/FieldTypes.h +817 -0
- data/ext/quickfix/Fields.h +30 -0
- data/ext/quickfix/FileLog.cpp +176 -0
- data/ext/quickfix/FileLog.h +110 -0
- data/ext/quickfix/FileStore.cpp +369 -0
- data/ext/quickfix/FileStore.h +131 -0
- data/ext/quickfix/FixCommonFields.h +13 -0
- data/ext/quickfix/FixFieldNumbers.h +6132 -0
- data/ext/quickfix/FixFields.h +6133 -0
- data/ext/quickfix/FixValues.h +5790 -0
- data/ext/quickfix/Group.cpp +44 -0
- data/ext/quickfix/Group.h +78 -0
- data/ext/quickfix/HostDetailsProvider.cpp +79 -0
- data/ext/quickfix/HostDetailsProvider.h +44 -0
- data/ext/quickfix/HtmlBuilder.h +178 -0
- data/ext/quickfix/HttpConnection.cpp +914 -0
- data/ext/quickfix/HttpConnection.h +74 -0
- data/ext/quickfix/HttpMessage.cpp +229 -0
- data/ext/quickfix/HttpMessage.h +112 -0
- data/ext/quickfix/HttpParser.cpp +49 -0
- data/ext/quickfix/HttpParser.h +49 -0
- data/ext/quickfix/HttpServer.cpp +152 -0
- data/ext/quickfix/HttpServer.h +76 -0
- data/ext/quickfix/Initiator.cpp +310 -0
- data/ext/quickfix/Initiator.h +151 -0
- data/ext/quickfix/Log.cpp +71 -0
- data/ext/quickfix/Log.h +254 -0
- data/ext/quickfix/Message.cpp +617 -0
- data/ext/quickfix/Message.h +419 -0
- data/ext/quickfix/MessageCracker.h +171 -0
- data/ext/quickfix/MessageSorters.cpp +101 -0
- data/ext/quickfix/MessageSorters.h +185 -0
- data/ext/quickfix/MessageStore.cpp +182 -0
- data/ext/quickfix/MessageStore.h +164 -0
- data/ext/quickfix/Mutex.h +120 -0
- data/ext/quickfix/MySQLConnection.h +187 -0
- data/ext/quickfix/MySQLLog.cpp +262 -0
- data/ext/quickfix/MySQLLog.h +158 -0
- data/ext/quickfix/MySQLStore.cpp +323 -0
- data/ext/quickfix/MySQLStore.h +161 -0
- data/ext/quickfix/MySQLStubs.h +203 -0
- data/ext/quickfix/NullStore.cpp +40 -0
- data/ext/quickfix/NullStore.h +89 -0
- data/ext/quickfix/OdbcConnection.h +241 -0
- data/ext/quickfix/OdbcLog.cpp +230 -0
- data/ext/quickfix/OdbcLog.h +109 -0
- data/ext/quickfix/OdbcStore.cpp +313 -0
- data/ext/quickfix/OdbcStore.h +124 -0
- data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
- data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
- data/ext/quickfix/Parser.cpp +111 -0
- data/ext/quickfix/Parser.h +50 -0
- data/ext/quickfix/PostgreSQLConnection.h +163 -0
- data/ext/quickfix/PostgreSQLLog.cpp +263 -0
- data/ext/quickfix/PostgreSQLLog.h +157 -0
- data/ext/quickfix/PostgreSQLStore.cpp +327 -0
- data/ext/quickfix/PostgreSQLStore.h +160 -0
- data/ext/quickfix/PostgreSQLStubs.h +203 -0
- data/ext/quickfix/Queue.h +66 -0
- data/ext/quickfix/QuickfixRuby.cpp +131900 -0
- data/ext/quickfix/QuickfixRuby.h +56 -0
- data/ext/quickfix/Responder.h +41 -0
- data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
- data/ext/quickfix/SSLSocketAcceptor.h +186 -0
- data/ext/quickfix/SSLSocketConnection.cpp +434 -0
- data/ext/quickfix/SSLSocketConnection.h +221 -0
- data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
- data/ext/quickfix/SSLSocketInitiator.h +203 -0
- data/ext/quickfix/SSLStubs.h +129 -0
- data/ext/quickfix/Session.cpp +1437 -0
- data/ext/quickfix/Session.h +343 -0
- data/ext/quickfix/SessionFactory.cpp +314 -0
- data/ext/quickfix/SessionFactory.h +84 -0
- data/ext/quickfix/SessionID.h +136 -0
- data/ext/quickfix/SessionSettings.cpp +165 -0
- data/ext/quickfix/SessionSettings.h +283 -0
- data/ext/quickfix/SessionState.h +260 -0
- data/ext/quickfix/Settings.cpp +160 -0
- data/ext/quickfix/Settings.h +56 -0
- data/ext/quickfix/SharedArray.h +274 -0
- data/ext/quickfix/SocketAcceptor.cpp +216 -0
- data/ext/quickfix/SocketAcceptor.h +77 -0
- data/ext/quickfix/SocketConnection.cpp +256 -0
- data/ext/quickfix/SocketConnection.h +102 -0
- data/ext/quickfix/SocketConnector.cpp +112 -0
- data/ext/quickfix/SocketConnector.h +76 -0
- data/ext/quickfix/SocketInitiator.cpp +241 -0
- data/ext/quickfix/SocketInitiator.h +76 -0
- data/ext/quickfix/SocketMonitor.h +26 -0
- data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
- data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
- data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
- data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
- data/ext/quickfix/SocketServer.cpp +163 -0
- data/ext/quickfix/SocketServer.h +100 -0
- data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
- data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
- data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
- data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
- data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
- data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
- data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
- data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
- data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
- data/ext/quickfix/ThreadedSocketConnection.h +89 -0
- data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
- data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
- data/ext/quickfix/TimeRange.cpp +227 -0
- data/ext/quickfix/TimeRange.h +215 -0
- data/ext/quickfix/Utility.cpp +639 -0
- data/ext/quickfix/Utility.h +255 -0
- data/ext/quickfix/UtilitySSL.cpp +1612 -0
- data/ext/quickfix/UtilitySSL.h +274 -0
- data/ext/quickfix/Values.h +63 -0
- data/ext/quickfix/config-all.h +10 -0
- data/ext/quickfix/config.h +10 -0
- data/ext/quickfix/config_unix.h +178 -0
- data/ext/quickfix/config_windows.h +0 -0
- data/ext/quickfix/dirent_windows.h +838 -0
- data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
- data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
- data/ext/quickfix/double-conversion/bignum.cc +766 -0
- data/ext/quickfix/double-conversion/bignum.h +144 -0
- data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
- data/ext/quickfix/double-conversion/cached-powers.h +64 -0
- data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
- data/ext/quickfix/double-conversion/diy-fp.h +118 -0
- data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
- data/ext/quickfix/double-conversion/double-conversion.h +543 -0
- data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
- data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
- data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
- data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
- data/ext/quickfix/double-conversion/ieee.h +402 -0
- data/ext/quickfix/double-conversion/strtod.cc +557 -0
- data/ext/quickfix/double-conversion/strtod.h +45 -0
- data/ext/quickfix/double-conversion/utils.h +374 -0
- data/ext/quickfix/extconf.rb +76 -0
- data/ext/quickfix/index.h +37 -0
- data/ext/quickfix/pugiconfig.hpp +77 -0
- data/ext/quickfix/pugixml.cpp +13237 -0
- data/ext/quickfix/pugixml.hpp +1516 -0
- data/ext/quickfix/scope_guard.hpp +215 -0
- data/ext/quickfix/stdint_msvc.h +254 -0
- data/ext/quickfix/strptime.h +7 -0
- data/lib/2.4/quickfix.so +0 -0
- data/lib/2.5/quickfix.so +0 -0
- data/lib/2.6/quickfix.so +0 -0
- data/lib/2.7/quickfix.so +0 -0
- data/lib/3.0/quickfix.so +0 -0
- data/lib/3.1/quickfix.so +0 -0
- data/lib/3.2/quickfix.so +0 -0
- data/lib/3.3/quickfix.so +0 -0
- data/lib/3.4/quickfix.so +0 -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 +14040 -0
- data/lib/quickfix50.rb +20051 -0
- data/lib/quickfix50sp1.rb +23596 -0
- data/lib/quickfix50sp2.rb +412444 -0
- data/lib/quickfix_fields.rb +79393 -0
- data/lib/quickfix_ruby.rb +82 -0
- data/lib/quickfixt11.rb +65 -0
- data/spec/FIX40.xml +862 -0
- data/spec/FIX41.xml +1282 -0
- data/spec/FIX42.xml +2743 -0
- data/spec/FIX43.xml +4230 -0
- data/spec/FIX44.xml +6600 -0
- data/spec/FIX50.xml +8142 -0
- data/spec/FIX50SP1.xml +9506 -0
- data/spec/FIX50SP2.xml +26069 -0
- data/spec/FIXT11.xml +252 -0
- data/test/DataDictionaryTestCase.rb +268 -0
- data/test/DictionaryTestCase.rb +112 -0
- data/test/FieldBaseTestCase.rb +24 -0
- data/test/MessageStoreTestCase.rb +19 -0
- data/test/MessageTestCase.rb +368 -0
- data/test/SessionSettingsTestCase.rb +41 -0
- metadata +247 -0
@@ -0,0 +1,241 @@
|
|
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 "Session.h"
|
27
|
+
#include "Settings.h"
|
28
|
+
#include "SocketInitiator.h"
|
29
|
+
|
30
|
+
namespace FIX {
|
31
|
+
SocketInitiator::SocketInitiator(
|
32
|
+
Application &application,
|
33
|
+
MessageStoreFactory &factory,
|
34
|
+
const SessionSettings &settings) EXCEPT(ConfigError)
|
35
|
+
: Initiator(application, factory, settings),
|
36
|
+
m_connector(1),
|
37
|
+
m_lastConnect(0),
|
38
|
+
m_reconnectInterval(30),
|
39
|
+
m_noDelay(false),
|
40
|
+
m_sendBufSize(0),
|
41
|
+
m_rcvBufSize(0) {}
|
42
|
+
|
43
|
+
SocketInitiator::SocketInitiator(
|
44
|
+
Application &application,
|
45
|
+
MessageStoreFactory &factory,
|
46
|
+
const SessionSettings &settings,
|
47
|
+
LogFactory &logFactory) EXCEPT(ConfigError)
|
48
|
+
: Initiator(application, factory, settings, logFactory),
|
49
|
+
m_connector(1),
|
50
|
+
m_lastConnect(0),
|
51
|
+
m_reconnectInterval(30),
|
52
|
+
m_noDelay(false),
|
53
|
+
m_sendBufSize(0),
|
54
|
+
m_rcvBufSize(0) {}
|
55
|
+
|
56
|
+
SocketInitiator::~SocketInitiator() {
|
57
|
+
SocketConnections::iterator i;
|
58
|
+
for (i = m_connections.begin(); i != m_connections.end(); ++i) {
|
59
|
+
delete i->second;
|
60
|
+
}
|
61
|
+
|
62
|
+
for (i = m_pendingConnections.begin(); i != m_pendingConnections.end(); ++i) {
|
63
|
+
delete i->second;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
void SocketInitiator::onConfigure(const SessionSettings &s) EXCEPT(ConfigError) {
|
68
|
+
const Dictionary &dict = s.get();
|
69
|
+
|
70
|
+
if (dict.has(RECONNECT_INTERVAL)) // ReconnectInterval in [DEFAULT]
|
71
|
+
{
|
72
|
+
m_reconnectInterval = dict.getInt(RECONNECT_INTERVAL);
|
73
|
+
}
|
74
|
+
if (dict.has(SOCKET_NODELAY)) {
|
75
|
+
m_noDelay = dict.getBool(SOCKET_NODELAY);
|
76
|
+
}
|
77
|
+
if (dict.has(SOCKET_SEND_BUFFER_SIZE)) {
|
78
|
+
m_sendBufSize = dict.getInt(SOCKET_SEND_BUFFER_SIZE);
|
79
|
+
}
|
80
|
+
if (dict.has(SOCKET_RECEIVE_BUFFER_SIZE)) {
|
81
|
+
m_rcvBufSize = dict.getInt(SOCKET_RECEIVE_BUFFER_SIZE);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
void SocketInitiator::onInitialize(const SessionSettings &s) EXCEPT(RuntimeError) {}
|
86
|
+
|
87
|
+
void SocketInitiator::onStart() {
|
88
|
+
connect();
|
89
|
+
|
90
|
+
while (!isStopped()) {
|
91
|
+
m_connector.block(*this, false, 1.0);
|
92
|
+
onTimeout(m_connector);
|
93
|
+
}
|
94
|
+
|
95
|
+
time_t start = 0;
|
96
|
+
time_t now = 0;
|
97
|
+
|
98
|
+
::time(&start);
|
99
|
+
while (isLoggedOn()) {
|
100
|
+
m_connector.block(*this);
|
101
|
+
if (::time(&now) - 5 >= start) {
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
bool SocketInitiator::onPoll() {
|
108
|
+
time_t start = 0;
|
109
|
+
time_t now = 0;
|
110
|
+
|
111
|
+
if (isStopped()) {
|
112
|
+
if (start == 0) {
|
113
|
+
::time(&start);
|
114
|
+
}
|
115
|
+
if (!isLoggedOn()) {
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
if (::time(&now) - 5 >= start) {
|
119
|
+
return false;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
m_connector.block(*this, true);
|
124
|
+
return true;
|
125
|
+
}
|
126
|
+
|
127
|
+
void SocketInitiator::onStop() {}
|
128
|
+
|
129
|
+
void SocketInitiator::doConnect(const SessionID &s, const Dictionary &d) {
|
130
|
+
try {
|
131
|
+
|
132
|
+
Session *session = Session::lookupSession(s);
|
133
|
+
if (!session->isSessionTime(UtcTimeStamp::now())) {
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
|
137
|
+
Log *log = session->getLog();
|
138
|
+
|
139
|
+
HostDetails host = m_hostDetailsProvider.getHost(s, d);
|
140
|
+
if (d.has(RECONNECT_INTERVAL)) // ReconnectInterval in [SESSION]
|
141
|
+
{
|
142
|
+
m_reconnectInterval = d.getInt(RECONNECT_INTERVAL);
|
143
|
+
}
|
144
|
+
|
145
|
+
log->onEvent(
|
146
|
+
"Connecting to " + host.address + " on port " + IntConvertor::convert((unsigned short)host.port) + " (Source "
|
147
|
+
+ host.sourceAddress + ":" + IntConvertor::convert((unsigned short)host.sourcePort)
|
148
|
+
+ ") ReconnectInterval=" + IntConvertor::convert((int)m_reconnectInterval));
|
149
|
+
socket_handle result = m_connector.connect(
|
150
|
+
host.address,
|
151
|
+
host.port,
|
152
|
+
m_noDelay,
|
153
|
+
m_sendBufSize,
|
154
|
+
m_rcvBufSize,
|
155
|
+
host.sourceAddress,
|
156
|
+
host.sourcePort);
|
157
|
+
setPending(s);
|
158
|
+
|
159
|
+
m_pendingConnections[result] = new SocketConnection(*this, s, result, &m_connector.getMonitor());
|
160
|
+
} catch (std::exception &) {}
|
161
|
+
}
|
162
|
+
|
163
|
+
void SocketInitiator::onConnect(SocketConnector &, socket_handle s) {
|
164
|
+
SocketConnections::iterator i = m_pendingConnections.find(s);
|
165
|
+
if (i == m_pendingConnections.end()) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
SocketConnection *pSocketConnection = i->second;
|
169
|
+
|
170
|
+
m_connections[s] = pSocketConnection;
|
171
|
+
m_pendingConnections.erase(i);
|
172
|
+
setConnected(pSocketConnection->getSession()->getSessionID());
|
173
|
+
pSocketConnection->onTimeout();
|
174
|
+
}
|
175
|
+
|
176
|
+
void SocketInitiator::onWrite(SocketConnector &connector, socket_handle s) {
|
177
|
+
SocketConnections::iterator i = m_connections.find(s);
|
178
|
+
if (i == m_connections.end()) {
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
SocketConnection *pSocketConnection = i->second;
|
182
|
+
if (pSocketConnection->processQueue()) {
|
183
|
+
pSocketConnection->unsignal();
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
bool SocketInitiator::onData(SocketConnector &connector, socket_handle s) {
|
188
|
+
SocketConnections::iterator i = m_connections.find(s);
|
189
|
+
if (i == m_connections.end()) {
|
190
|
+
return false;
|
191
|
+
}
|
192
|
+
SocketConnection *pSocketConnection = i->second;
|
193
|
+
return pSocketConnection->read(connector);
|
194
|
+
}
|
195
|
+
|
196
|
+
void SocketInitiator::onDisconnect(SocketConnector &, socket_handle s) {
|
197
|
+
SocketConnections::iterator i = m_connections.find(s);
|
198
|
+
SocketConnections::iterator j = m_pendingConnections.find(s);
|
199
|
+
|
200
|
+
SocketConnection *pSocketConnection = 0;
|
201
|
+
if (i != m_connections.end()) {
|
202
|
+
pSocketConnection = i->second;
|
203
|
+
}
|
204
|
+
if (j != m_pendingConnections.end()) {
|
205
|
+
pSocketConnection = j->second;
|
206
|
+
}
|
207
|
+
if (!pSocketConnection) {
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
|
211
|
+
setDisconnected(pSocketConnection->getSession()->getSessionID());
|
212
|
+
|
213
|
+
Session *pSession = pSocketConnection->getSession();
|
214
|
+
if (pSession) {
|
215
|
+
pSession->disconnect();
|
216
|
+
setDisconnected(pSession->getSessionID());
|
217
|
+
}
|
218
|
+
|
219
|
+
delete pSocketConnection;
|
220
|
+
m_connections.erase(s);
|
221
|
+
m_pendingConnections.erase(s);
|
222
|
+
}
|
223
|
+
|
224
|
+
void SocketInitiator::onError(SocketConnector &connector) { onTimeout(connector); }
|
225
|
+
|
226
|
+
void SocketInitiator::onTimeout(SocketConnector &) {
|
227
|
+
time_t now;
|
228
|
+
::time(&now);
|
229
|
+
|
230
|
+
if ((now - m_lastConnect) >= m_reconnectInterval) {
|
231
|
+
connect();
|
232
|
+
m_lastConnect = now;
|
233
|
+
}
|
234
|
+
|
235
|
+
SocketConnections::iterator i;
|
236
|
+
for (i = m_connections.begin(); i != m_connections.end(); ++i) {
|
237
|
+
i->second->onTimeout();
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
} // namespace FIX
|
@@ -0,0 +1,76 @@
|
|
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 "HostDetailsProvider.h"
|
30
|
+
#include "Initiator.h"
|
31
|
+
#include "SocketConnection.h"
|
32
|
+
#include "SocketConnector.h"
|
33
|
+
|
34
|
+
namespace FIX {
|
35
|
+
/// Socket implementation of Initiator.
|
36
|
+
class SocketInitiator : public Initiator, SocketConnector::Strategy {
|
37
|
+
public:
|
38
|
+
SocketInitiator(Application &, MessageStoreFactory &, const SessionSettings &) EXCEPT(ConfigError);
|
39
|
+
SocketInitiator(Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) EXCEPT(ConfigError);
|
40
|
+
|
41
|
+
virtual ~SocketInitiator();
|
42
|
+
|
43
|
+
private:
|
44
|
+
typedef std::map<socket_handle, SocketConnection *> SocketConnections;
|
45
|
+
|
46
|
+
void onConfigure(const SessionSettings &) EXCEPT(ConfigError);
|
47
|
+
void onInitialize(const SessionSettings &) EXCEPT(RuntimeError);
|
48
|
+
|
49
|
+
void onStart();
|
50
|
+
bool onPoll();
|
51
|
+
void onStop();
|
52
|
+
|
53
|
+
void doConnect(const SessionID &, const Dictionary &d);
|
54
|
+
void onConnect(SocketConnector &, socket_handle);
|
55
|
+
void onWrite(SocketConnector &, socket_handle);
|
56
|
+
bool onData(SocketConnector &, socket_handle);
|
57
|
+
void onDisconnect(SocketConnector &, socket_handle);
|
58
|
+
void onError(SocketConnector &);
|
59
|
+
void onTimeout(SocketConnector &);
|
60
|
+
|
61
|
+
SessionSettings m_settings;
|
62
|
+
|
63
|
+
HostDetailsProvider m_hostDetailsProvider;
|
64
|
+
SocketConnector m_connector;
|
65
|
+
SocketConnections m_pendingConnections;
|
66
|
+
SocketConnections m_connections;
|
67
|
+
time_t m_lastConnect;
|
68
|
+
int m_reconnectInterval;
|
69
|
+
bool m_noDelay;
|
70
|
+
int m_sendBufSize;
|
71
|
+
int m_rcvBufSize;
|
72
|
+
};
|
73
|
+
/*! @} */
|
74
|
+
} // namespace FIX
|
75
|
+
|
76
|
+
#endif // FIX_SOCKETINITIATOR_H
|
@@ -0,0 +1,26 @@
|
|
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
|
+
#ifdef _MSC_VER
|
23
|
+
#include "SocketMonitor_WIN32.h"
|
24
|
+
#else
|
25
|
+
#include "SocketMonitor_UNIX.h"
|
26
|
+
#endif
|
@@ -0,0 +1,238 @@
|
|
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
|
+
#ifndef _MSC_VER
|
21
|
+
|
22
|
+
#include "config.h"
|
23
|
+
|
24
|
+
#include "SocketMonitor.h"
|
25
|
+
#include "Utility.h"
|
26
|
+
#include <algorithm>
|
27
|
+
#include <exception>
|
28
|
+
#include <iostream>
|
29
|
+
#include <set>
|
30
|
+
|
31
|
+
namespace FIX {
|
32
|
+
SocketMonitor::SocketMonitor(int timeout)
|
33
|
+
: m_timeout(timeout) {
|
34
|
+
socket_init();
|
35
|
+
|
36
|
+
std::pair<socket_handle, socket_handle> sockets = socket_createpair();
|
37
|
+
m_signal = sockets.first;
|
38
|
+
m_interrupt = sockets.second;
|
39
|
+
socket_setnonblock(m_signal);
|
40
|
+
socket_setnonblock(m_interrupt);
|
41
|
+
m_readSockets.insert(m_interrupt);
|
42
|
+
|
43
|
+
m_ticks = clock();
|
44
|
+
}
|
45
|
+
|
46
|
+
SocketMonitor::~SocketMonitor() {
|
47
|
+
Sockets::iterator i;
|
48
|
+
for (i = m_readSockets.begin(); i != m_readSockets.end(); ++i) {
|
49
|
+
socket_close(*i);
|
50
|
+
}
|
51
|
+
|
52
|
+
socket_close(m_signal);
|
53
|
+
socket_term();
|
54
|
+
}
|
55
|
+
|
56
|
+
bool SocketMonitor::addConnect(socket_handle s) {
|
57
|
+
socket_setnonblock(s);
|
58
|
+
Sockets::iterator i = m_connectSockets.find(s);
|
59
|
+
if (i != m_connectSockets.end()) {
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
|
63
|
+
m_connectSockets.insert(s);
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
|
67
|
+
bool SocketMonitor::addRead(socket_handle s) {
|
68
|
+
socket_setnonblock(s);
|
69
|
+
Sockets::iterator i = m_readSockets.find(s);
|
70
|
+
if (i != m_readSockets.end()) {
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
|
74
|
+
m_readSockets.insert(s);
|
75
|
+
return true;
|
76
|
+
}
|
77
|
+
|
78
|
+
bool SocketMonitor::addWrite(socket_handle s) {
|
79
|
+
if (m_readSockets.find(s) == m_readSockets.end()) {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
|
83
|
+
socket_setnonblock(s);
|
84
|
+
Sockets::iterator i = m_writeSockets.find(s);
|
85
|
+
if (i != m_writeSockets.end()) {
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
|
89
|
+
m_writeSockets.insert(s);
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
|
93
|
+
bool SocketMonitor::drop(socket_handle s) {
|
94
|
+
Sockets::iterator i = m_readSockets.find(s);
|
95
|
+
Sockets::iterator j = m_writeSockets.find(s);
|
96
|
+
Sockets::iterator k = m_connectSockets.find(s);
|
97
|
+
|
98
|
+
if (i != m_readSockets.end() || j != m_writeSockets.end() || k != m_connectSockets.end()) {
|
99
|
+
socket_close(s);
|
100
|
+
m_readSockets.erase(s);
|
101
|
+
m_writeSockets.erase(s);
|
102
|
+
m_connectSockets.erase(s);
|
103
|
+
m_dropped.push(s);
|
104
|
+
return true;
|
105
|
+
}
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
|
109
|
+
inline int SocketMonitor::getTimeval(bool poll, double timeout) {
|
110
|
+
if (poll) {
|
111
|
+
return 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
timeout = m_timeout;
|
115
|
+
|
116
|
+
if (!timeout) {
|
117
|
+
return 0;
|
118
|
+
}
|
119
|
+
|
120
|
+
double elapsed = (double)(clock() - m_ticks) / (double)CLOCKS_PER_SEC;
|
121
|
+
if (elapsed >= timeout || elapsed == 0.0) {
|
122
|
+
m_ticks = clock();
|
123
|
+
return (timeout * 1000);
|
124
|
+
} else {
|
125
|
+
return ((timeout - elapsed) * 1000);
|
126
|
+
}
|
127
|
+
return (timeout * 1000);
|
128
|
+
}
|
129
|
+
|
130
|
+
bool SocketMonitor::sleepIfEmpty(bool poll) {
|
131
|
+
if (poll) {
|
132
|
+
return false;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (m_readSockets.empty() && m_writeSockets.empty() && m_connectSockets.empty()) {
|
136
|
+
process_sleep(m_timeout);
|
137
|
+
return true;
|
138
|
+
} else {
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
void SocketMonitor::signal(socket_handle socket) { socket_send(m_signal, (char *)&socket, sizeof(socket)); }
|
144
|
+
|
145
|
+
void SocketMonitor::unsignal(socket_handle s) {
|
146
|
+
Sockets::iterator i = m_writeSockets.find(s);
|
147
|
+
if (i == m_writeSockets.end()) {
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
|
151
|
+
m_writeSockets.erase(s);
|
152
|
+
}
|
153
|
+
|
154
|
+
void SocketMonitor::block(Strategy &strategy, bool should_poll, double timeout) {
|
155
|
+
while (m_dropped.size()) {
|
156
|
+
strategy.onError(*this, m_dropped.front());
|
157
|
+
m_dropped.pop();
|
158
|
+
if (m_dropped.size() == 0) {
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
int pfds_size = m_readSockets.size() + m_connectSockets.size() + m_writeSockets.size();
|
164
|
+
struct pollfd pfds[pfds_size];
|
165
|
+
buildSet(m_readSockets, pfds, POLLPRI | POLLIN);
|
166
|
+
buildSet(m_connectSockets, pfds + m_readSockets.size(), POLLOUT | POLLERR);
|
167
|
+
buildSet(m_writeSockets, pfds + m_readSockets.size() + m_connectSockets.size(), POLLOUT);
|
168
|
+
|
169
|
+
if (sleepIfEmpty(should_poll)) {
|
170
|
+
strategy.onTimeout(*this);
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
|
174
|
+
int result = poll(pfds, pfds_size, getTimeval(should_poll, timeout));
|
175
|
+
|
176
|
+
if (result == 0) {
|
177
|
+
strategy.onTimeout(*this);
|
178
|
+
return;
|
179
|
+
} else if (result > 0) {
|
180
|
+
processPollList(strategy, pfds, pfds_size);
|
181
|
+
} else {
|
182
|
+
strategy.onError(*this);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
void SocketMonitor::processRead(Strategy &strategy, socket_handle socket_fd) {
|
187
|
+
int s = socket_fd;
|
188
|
+
if (s == m_interrupt) {
|
189
|
+
socket_handle socket = 0;
|
190
|
+
recv(s, (char *)&socket, sizeof(socket), 0);
|
191
|
+
addWrite(socket);
|
192
|
+
} else {
|
193
|
+
strategy.onEvent(*this, s);
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
void SocketMonitor::processWrite(Strategy &strategy, socket_handle socket_fd) {
|
198
|
+
socket_handle s = socket_fd;
|
199
|
+
if (m_connectSockets.find(s) != m_connectSockets.end()) {
|
200
|
+
m_connectSockets.erase(s);
|
201
|
+
m_readSockets.insert(s);
|
202
|
+
strategy.onConnect(*this, s);
|
203
|
+
} else {
|
204
|
+
strategy.onWrite(*this, s);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
void SocketMonitor::processError(Strategy &strategy, socket_handle socket_fd) { strategy.onError(*this, socket_fd); }
|
209
|
+
|
210
|
+
void SocketMonitor::processPollList(Strategy &strategy, struct pollfd *pfds, unsigned pfds_size) {
|
211
|
+
for (unsigned i = 0; i < pfds_size; ++i) {
|
212
|
+
if ((pfds[i].revents & POLLIN) || (pfds[i].revents & POLLPRI)) {
|
213
|
+
processRead(strategy, pfds[i].fd);
|
214
|
+
}
|
215
|
+
|
216
|
+
if ((pfds[i].revents & POLLOUT)) {
|
217
|
+
processWrite(strategy, pfds[i].fd);
|
218
|
+
}
|
219
|
+
if ((pfds[i].revents & POLLERR)) {
|
220
|
+
processError(strategy, pfds[i].fd);
|
221
|
+
}
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
void SocketMonitor::buildSet(const Sockets &sockets, struct pollfd *pfds, short events) {
|
226
|
+
Sockets::const_iterator iter;
|
227
|
+
unsigned int i = 0;
|
228
|
+
for (iter = sockets.begin(); iter != sockets.end(); ++iter) {
|
229
|
+
pfds[i].fd = *iter;
|
230
|
+
pfds[i].events = events;
|
231
|
+
pfds[i].revents = 0;
|
232
|
+
i += 1;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
} // namespace FIX
|
237
|
+
|
238
|
+
#endif
|
@@ -0,0 +1,101 @@
|
|
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_SOCKETMONITOR_UNIX_H
|
23
|
+
#define FIX_SOCKETMONITOR_UNIX_H
|
24
|
+
|
25
|
+
#ifndef _MSC_VER
|
26
|
+
|
27
|
+
#include <arpa/inet.h>
|
28
|
+
#include <netinet/in.h>
|
29
|
+
#include <sys/socket.h>
|
30
|
+
#include <sys/time.h>
|
31
|
+
#include <sys/types.h>
|
32
|
+
|
33
|
+
#include <poll.h>
|
34
|
+
#include <queue>
|
35
|
+
#include <set>
|
36
|
+
#include <time.h>
|
37
|
+
|
38
|
+
#include "Utility.h"
|
39
|
+
|
40
|
+
namespace FIX {
|
41
|
+
/// Monitors events on a collection of sockets.
|
42
|
+
class SocketMonitor {
|
43
|
+
public:
|
44
|
+
class Strategy;
|
45
|
+
|
46
|
+
SocketMonitor(int timeout = 0);
|
47
|
+
virtual ~SocketMonitor();
|
48
|
+
|
49
|
+
bool addConnect(socket_handle socket);
|
50
|
+
bool addRead(socket_handle socket);
|
51
|
+
bool addWrite(socket_handle socket);
|
52
|
+
bool drop(socket_handle socket);
|
53
|
+
void signal(socket_handle socket);
|
54
|
+
void unsignal(socket_handle socket);
|
55
|
+
void block(Strategy &strategy, bool poll = 0, double timeout = 0.0);
|
56
|
+
|
57
|
+
size_t numSockets() { return m_readSockets.size() - 1; }
|
58
|
+
|
59
|
+
private:
|
60
|
+
typedef std::set<socket_handle> Sockets;
|
61
|
+
typedef std::queue<socket_handle> Queue;
|
62
|
+
|
63
|
+
void setsockopt();
|
64
|
+
bool bind();
|
65
|
+
bool listen();
|
66
|
+
void buildSet(const Sockets &, struct pollfd *pfds, short events);
|
67
|
+
inline int getTimeval(bool poll, double timeout);
|
68
|
+
inline bool sleepIfEmpty(bool poll);
|
69
|
+
|
70
|
+
void processRead(Strategy &, socket_handle socket_fd);
|
71
|
+
void processWrite(Strategy &, socket_handle socket_fd);
|
72
|
+
void processError(Strategy &, socket_handle socket_fd);
|
73
|
+
void processPollList(Strategy &strategy, struct pollfd *pfds, unsigned pfds_size);
|
74
|
+
|
75
|
+
int m_timeout;
|
76
|
+
clock_t m_ticks;
|
77
|
+
|
78
|
+
socket_handle m_signal;
|
79
|
+
socket_handle m_interrupt;
|
80
|
+
Sockets m_connectSockets;
|
81
|
+
Sockets m_readSockets;
|
82
|
+
Sockets m_writeSockets;
|
83
|
+
Queue m_dropped;
|
84
|
+
|
85
|
+
public:
|
86
|
+
class Strategy {
|
87
|
+
public:
|
88
|
+
virtual ~Strategy() {}
|
89
|
+
virtual void onConnect(SocketMonitor &, socket_handle socket) = 0;
|
90
|
+
virtual void onEvent(SocketMonitor &, socket_handle socket) = 0;
|
91
|
+
virtual void onWrite(SocketMonitor &, socket_handle socket) = 0;
|
92
|
+
virtual void onError(SocketMonitor &, socket_handle socket) = 0;
|
93
|
+
virtual void onError(SocketMonitor &) = 0;
|
94
|
+
virtual void onTimeout(SocketMonitor &) {}
|
95
|
+
};
|
96
|
+
};
|
97
|
+
} // namespace FIX
|
98
|
+
|
99
|
+
#endif //_MSC_VER
|
100
|
+
|
101
|
+
#endif // FIX_SOCKETMONITOR_UNIX_H
|