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,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
|
+
#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 "ThreadedSocketInitiator.h"
|
29
|
+
|
30
|
+
namespace FIX {
|
31
|
+
ThreadedSocketInitiator::ThreadedSocketInitiator(
|
32
|
+
Application &application,
|
33
|
+
MessageStoreFactory &factory,
|
34
|
+
const SessionSettings &settings) EXCEPT(ConfigError)
|
35
|
+
: Initiator(application, factory, settings),
|
36
|
+
m_lastConnect(0),
|
37
|
+
m_reconnectInterval(30),
|
38
|
+
m_noDelay(false),
|
39
|
+
m_sendBufSize(0),
|
40
|
+
m_rcvBufSize(0) {
|
41
|
+
socket_init();
|
42
|
+
}
|
43
|
+
|
44
|
+
ThreadedSocketInitiator::ThreadedSocketInitiator(
|
45
|
+
Application &application,
|
46
|
+
MessageStoreFactory &factory,
|
47
|
+
const SessionSettings &settings,
|
48
|
+
LogFactory &logFactory) EXCEPT(ConfigError)
|
49
|
+
: Initiator(application, factory, settings, logFactory),
|
50
|
+
m_lastConnect(0),
|
51
|
+
m_reconnectInterval(30),
|
52
|
+
m_noDelay(false),
|
53
|
+
m_sendBufSize(0),
|
54
|
+
m_rcvBufSize(0) {
|
55
|
+
socket_init();
|
56
|
+
}
|
57
|
+
|
58
|
+
ThreadedSocketInitiator::~ThreadedSocketInitiator() { socket_term(); }
|
59
|
+
|
60
|
+
void ThreadedSocketInitiator::onConfigure(const SessionSettings &s) EXCEPT(ConfigError) {
|
61
|
+
const Dictionary &dict = s.get();
|
62
|
+
|
63
|
+
if (dict.has(RECONNECT_INTERVAL)) // ReconnectInterval in [DEFAULT]
|
64
|
+
{
|
65
|
+
m_reconnectInterval = dict.getInt(RECONNECT_INTERVAL);
|
66
|
+
}
|
67
|
+
if (dict.has(SOCKET_NODELAY)) {
|
68
|
+
m_noDelay = dict.getBool(SOCKET_NODELAY);
|
69
|
+
}
|
70
|
+
if (dict.has(SOCKET_SEND_BUFFER_SIZE)) {
|
71
|
+
m_sendBufSize = dict.getInt(SOCKET_SEND_BUFFER_SIZE);
|
72
|
+
}
|
73
|
+
if (dict.has(SOCKET_RECEIVE_BUFFER_SIZE)) {
|
74
|
+
m_rcvBufSize = dict.getInt(SOCKET_RECEIVE_BUFFER_SIZE);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
void ThreadedSocketInitiator::onInitialize(const SessionSettings &s) EXCEPT(RuntimeError) {}
|
79
|
+
|
80
|
+
void ThreadedSocketInitiator::onStart() {
|
81
|
+
while (!isStopped()) {
|
82
|
+
time_t now;
|
83
|
+
::time(&now);
|
84
|
+
|
85
|
+
if ((now - m_lastConnect) >= m_reconnectInterval) {
|
86
|
+
Locker l(m_mutex);
|
87
|
+
connect();
|
88
|
+
m_lastConnect = now;
|
89
|
+
}
|
90
|
+
|
91
|
+
process_sleep(1);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
bool ThreadedSocketInitiator::onPoll() { return false; }
|
96
|
+
|
97
|
+
void ThreadedSocketInitiator::onStop() {
|
98
|
+
SocketToThread threads;
|
99
|
+
SocketToThread::iterator i;
|
100
|
+
|
101
|
+
{
|
102
|
+
Locker l(m_mutex);
|
103
|
+
|
104
|
+
time_t start = 0;
|
105
|
+
time_t now = 0;
|
106
|
+
|
107
|
+
::time(&start);
|
108
|
+
while (isLoggedOn()) {
|
109
|
+
if (::time(&now) - 5 >= start) {
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
threads = m_threads;
|
115
|
+
m_threads.clear();
|
116
|
+
}
|
117
|
+
|
118
|
+
for (i = threads.begin(); i != threads.end(); ++i) {
|
119
|
+
socket_close(i->first);
|
120
|
+
}
|
121
|
+
|
122
|
+
for (i = threads.begin(); i != threads.end(); ++i) {
|
123
|
+
thread_join(i->second);
|
124
|
+
}
|
125
|
+
threads.clear();
|
126
|
+
}
|
127
|
+
|
128
|
+
void ThreadedSocketInitiator::doConnect(const SessionID &s, const Dictionary &d) {
|
129
|
+
try {
|
130
|
+
Session *session = Session::lookupSession(s);
|
131
|
+
if (!session->isSessionTime(UtcTimeStamp::now())) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
|
135
|
+
Log *log = session->getLog();
|
136
|
+
|
137
|
+
HostDetails host = m_hostDetailsProvider.getHost(s, d);
|
138
|
+
if (d.has(RECONNECT_INTERVAL)) // ReconnectInterval in [SESSION]
|
139
|
+
{
|
140
|
+
m_reconnectInterval = d.getInt(RECONNECT_INTERVAL);
|
141
|
+
}
|
142
|
+
|
143
|
+
socket_handle socket = socket_createConnector();
|
144
|
+
if (m_noDelay) {
|
145
|
+
socket_setsockopt(socket, TCP_NODELAY);
|
146
|
+
}
|
147
|
+
if (m_sendBufSize) {
|
148
|
+
socket_setsockopt(socket, SO_SNDBUF, m_sendBufSize);
|
149
|
+
}
|
150
|
+
if (m_rcvBufSize) {
|
151
|
+
socket_setsockopt(socket, SO_RCVBUF, m_rcvBufSize);
|
152
|
+
}
|
153
|
+
|
154
|
+
setPending(s);
|
155
|
+
log->onEvent(
|
156
|
+
"Connecting to " + host.address + " on port " + IntConvertor::convert((unsigned short)host.port) + " (Source "
|
157
|
+
+ host.sourceAddress + ":" + IntConvertor::convert((unsigned short)host.sourcePort)
|
158
|
+
+ ") ReconnectInterval=" + IntConvertor::convert((int)m_reconnectInterval));
|
159
|
+
|
160
|
+
ThreadedSocketConnection *pConnection = new ThreadedSocketConnection(
|
161
|
+
s,
|
162
|
+
socket,
|
163
|
+
host.address,
|
164
|
+
host.port,
|
165
|
+
getLog(),
|
166
|
+
host.sourceAddress,
|
167
|
+
host.sourcePort);
|
168
|
+
|
169
|
+
ThreadPair *pair = new ThreadPair(this, pConnection);
|
170
|
+
|
171
|
+
{
|
172
|
+
Locker l(m_mutex);
|
173
|
+
thread_id thread;
|
174
|
+
if (thread_spawn(&socketThread, pair, thread)) {
|
175
|
+
addThread(socket, thread);
|
176
|
+
} else {
|
177
|
+
delete pair;
|
178
|
+
pConnection->disconnect();
|
179
|
+
delete pConnection;
|
180
|
+
setDisconnected(s);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
} catch (std::exception &) {}
|
184
|
+
}
|
185
|
+
|
186
|
+
void ThreadedSocketInitiator::addThread(socket_handle s, thread_id t) {
|
187
|
+
Locker l(m_mutex);
|
188
|
+
|
189
|
+
m_threads[s] = t;
|
190
|
+
}
|
191
|
+
|
192
|
+
void ThreadedSocketInitiator::removeThread(socket_handle s) {
|
193
|
+
Locker l(m_mutex);
|
194
|
+
SocketToThread::iterator i = m_threads.find(s);
|
195
|
+
|
196
|
+
if (i != m_threads.end()) {
|
197
|
+
thread_detach(i->second);
|
198
|
+
m_threads.erase(i);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
THREAD_PROC ThreadedSocketInitiator::socketThread(void *p) {
|
203
|
+
ThreadPair *pair = reinterpret_cast<ThreadPair *>(p);
|
204
|
+
|
205
|
+
ThreadedSocketInitiator *pInitiator = pair->first;
|
206
|
+
ThreadedSocketConnection *pConnection = pair->second;
|
207
|
+
FIX::SessionID sessionID = pConnection->getSession()->getSessionID();
|
208
|
+
FIX::Session *pSession = FIX::Session::lookupSession(sessionID);
|
209
|
+
socket_handle socket = pConnection->getSocket();
|
210
|
+
delete pair;
|
211
|
+
|
212
|
+
pInitiator->lock();
|
213
|
+
|
214
|
+
if (!pConnection->connect()) {
|
215
|
+
pInitiator->getLog()->onEvent("Connection failed");
|
216
|
+
pConnection->disconnect();
|
217
|
+
delete pConnection;
|
218
|
+
pInitiator->removeThread(socket);
|
219
|
+
pInitiator->setDisconnected(sessionID);
|
220
|
+
return 0;
|
221
|
+
}
|
222
|
+
|
223
|
+
pInitiator->setConnected(sessionID);
|
224
|
+
pInitiator->getLog()->onEvent("Connection succeeded");
|
225
|
+
|
226
|
+
pSession->next(UtcTimeStamp::now());
|
227
|
+
|
228
|
+
while (pConnection->read()) {}
|
229
|
+
|
230
|
+
delete pConnection;
|
231
|
+
if (!pInitiator->isStopped()) {
|
232
|
+
pInitiator->removeThread(socket);
|
233
|
+
}
|
234
|
+
|
235
|
+
pInitiator->setDisconnected(sessionID);
|
236
|
+
return 0;
|
237
|
+
}
|
238
|
+
} // namespace FIX
|
@@ -0,0 +1,78 @@
|
|
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_THREADEDSOCKETINITIATOR_H
|
23
|
+
#define FIX_THREADEDSOCKETINITIATOR_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 "ThreadedSocketConnection.h"
|
32
|
+
#include <map>
|
33
|
+
|
34
|
+
namespace FIX {
|
35
|
+
/*! \addtogroup user
|
36
|
+
* @{
|
37
|
+
*/
|
38
|
+
/// Threaded Socket implementation of Initiator.
|
39
|
+
class ThreadedSocketInitiator : public Initiator {
|
40
|
+
public:
|
41
|
+
ThreadedSocketInitiator(Application &, MessageStoreFactory &, const SessionSettings &) EXCEPT(ConfigError);
|
42
|
+
ThreadedSocketInitiator(Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &)
|
43
|
+
EXCEPT(ConfigError);
|
44
|
+
|
45
|
+
virtual ~ThreadedSocketInitiator();
|
46
|
+
|
47
|
+
private:
|
48
|
+
typedef std::map<socket_handle, thread_id> SocketToThread;
|
49
|
+
typedef std::pair<ThreadedSocketInitiator *, ThreadedSocketConnection *> ThreadPair;
|
50
|
+
|
51
|
+
void onConfigure(const SessionSettings &) EXCEPT(ConfigError);
|
52
|
+
void onInitialize(const SessionSettings &) EXCEPT(RuntimeError);
|
53
|
+
|
54
|
+
void onStart();
|
55
|
+
bool onPoll();
|
56
|
+
void onStop();
|
57
|
+
|
58
|
+
void doConnect(const SessionID &s, const Dictionary &d);
|
59
|
+
|
60
|
+
void addThread(socket_handle s, thread_id t);
|
61
|
+
void removeThread(socket_handle s);
|
62
|
+
void lock() { Locker l(m_mutex); }
|
63
|
+
static THREAD_PROC socketThread(void *p);
|
64
|
+
|
65
|
+
SessionSettings m_settings;
|
66
|
+
HostDetailsProvider m_hostDetailsProvider;
|
67
|
+
time_t m_lastConnect;
|
68
|
+
int m_reconnectInterval;
|
69
|
+
bool m_noDelay;
|
70
|
+
int m_sendBufSize;
|
71
|
+
int m_rcvBufSize;
|
72
|
+
SocketToThread m_threads;
|
73
|
+
Mutex m_mutex;
|
74
|
+
};
|
75
|
+
/*! @} */
|
76
|
+
} // namespace FIX
|
77
|
+
|
78
|
+
#endif // FIX_THREADEDSOCKETINITIATOR_H
|
@@ -0,0 +1,227 @@
|
|
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 "TimeRange.h"
|
27
|
+
#include "Utility.h"
|
28
|
+
|
29
|
+
namespace FIX {
|
30
|
+
TimeRange::TimeRange(const UtcTimeOnly &startTime, const UtcTimeOnly &endTime, int startDay, int endDay)
|
31
|
+
: m_startTime(startTime),
|
32
|
+
m_endTime(endTime),
|
33
|
+
m_startDay(startDay),
|
34
|
+
m_endDay(endDay),
|
35
|
+
m_useLocalTime(false) {
|
36
|
+
if (startDay > 0 && endDay > 0 && startDay == endDay && endTime > startTime) {
|
37
|
+
m_endTime = m_startTime;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
TimeRange::TimeRange(const LocalTimeOnly &startTime, const LocalTimeOnly &endTime, int startDay, int endDay)
|
42
|
+
: m_startTime(startTime),
|
43
|
+
m_endTime(endTime),
|
44
|
+
m_startDay(startDay),
|
45
|
+
m_endDay(endDay),
|
46
|
+
m_useLocalTime(true) {
|
47
|
+
if (startDay > 0 && endDay > 0 && startDay == endDay && endTime > startTime) {
|
48
|
+
m_endTime = m_startTime;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
int TimeRange::getRangeStartDate(const DateTime &time, int startDay, const DateTime &startTime) {
|
53
|
+
if (time.getWeekDay() > startDay) {
|
54
|
+
return time.getJulianDate() - time.getWeekDay() + startDay;
|
55
|
+
} else if (time.getWeekDay() < startDay) {
|
56
|
+
return time.getJulianDate() - time.getWeekDay() + startDay - 7;
|
57
|
+
} else {
|
58
|
+
if (UtcTimeOnly(time) >= UtcTimeOnly(startTime)) {
|
59
|
+
return time.getJulianDate();
|
60
|
+
} else {
|
61
|
+
return time.getJulianDate() - 7;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
bool TimeRange::isInRange(const DateTime &start, const DateTime &end, const DateTime &time) {
|
67
|
+
UtcTimeOnly timeOnly(time);
|
68
|
+
|
69
|
+
if (start < end) {
|
70
|
+
return (timeOnly >= start && timeOnly <= end);
|
71
|
+
} else {
|
72
|
+
return (timeOnly >= start || timeOnly <= end);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
bool TimeRange::isInRange(
|
77
|
+
const DateTime &startTime,
|
78
|
+
const DateTime &endTime,
|
79
|
+
int startDay,
|
80
|
+
int endDay,
|
81
|
+
const DateTime &time,
|
82
|
+
int day) {
|
83
|
+
UtcTimeOnly timeOnly(time);
|
84
|
+
|
85
|
+
if (startDay == endDay) {
|
86
|
+
if (day != startDay) {
|
87
|
+
return true;
|
88
|
+
}
|
89
|
+
return isInRange(startTime, endTime, time);
|
90
|
+
} else if (startDay < endDay) {
|
91
|
+
if (day < startDay || day > endDay) {
|
92
|
+
return false;
|
93
|
+
} else if (day == startDay && timeOnly < startTime) {
|
94
|
+
return false;
|
95
|
+
} else if (day == endDay && timeOnly > endTime) {
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
} else if (startDay > endDay) {
|
99
|
+
if (day < startDay && day > endDay) {
|
100
|
+
return false;
|
101
|
+
} else if (day == startDay && timeOnly < startTime) {
|
102
|
+
return false;
|
103
|
+
} else if (day == endDay && timeOnly > endTime) {
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return true;
|
108
|
+
}
|
109
|
+
|
110
|
+
bool TimeRange::isInRange(
|
111
|
+
const DateTime &startTime,
|
112
|
+
const DateTime &endTime,
|
113
|
+
int startDay,
|
114
|
+
int endDay,
|
115
|
+
const DateTime &time) {
|
116
|
+
return isInRange(startTime, endTime, startDay, endDay, time, time.getWeekDay());
|
117
|
+
}
|
118
|
+
|
119
|
+
bool TimeRange::isInSameRange(
|
120
|
+
const DateTime &start,
|
121
|
+
const DateTime &end,
|
122
|
+
const DateTime &time1,
|
123
|
+
const DateTime &time2) {
|
124
|
+
if (!isInRange(start, end, time1)) {
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
if (!isInRange(start, end, time2)) {
|
128
|
+
return false;
|
129
|
+
}
|
130
|
+
|
131
|
+
if (time1 == time2) {
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (start < end || start == end) {
|
136
|
+
UtcDate time1Date(time1);
|
137
|
+
UtcDate time2Date(time2);
|
138
|
+
|
139
|
+
return time1Date == time2Date;
|
140
|
+
} else {
|
141
|
+
int sessionLength = DateTime::SECONDS_PER_DAY - (start - end);
|
142
|
+
|
143
|
+
if (time1 > time2) {
|
144
|
+
UtcTimeOnly time2TimeOnly = UtcTimeOnly(time2);
|
145
|
+
|
146
|
+
long delta = time2TimeOnly - start;
|
147
|
+
if (delta < 0) {
|
148
|
+
delta = DateTime::SECONDS_PER_DAY - labs(delta);
|
149
|
+
}
|
150
|
+
|
151
|
+
return (time1 - time2) < (sessionLength - delta);
|
152
|
+
} else {
|
153
|
+
return (time2 - time1) < sessionLength;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
bool TimeRange::isInSameRange(
|
159
|
+
const DateTime &startTime,
|
160
|
+
const DateTime &endTime,
|
161
|
+
int startDay,
|
162
|
+
int endDay,
|
163
|
+
const DateTime &time1,
|
164
|
+
const DateTime &time2) {
|
165
|
+
if (!isInRange(startTime, endTime, startDay, endDay, time1, time1.getWeekDay())) {
|
166
|
+
return false;
|
167
|
+
}
|
168
|
+
|
169
|
+
if (!isInRange(startTime, endTime, startDay, endDay, time2, time2.getWeekDay())) {
|
170
|
+
return false;
|
171
|
+
}
|
172
|
+
|
173
|
+
if (startDay != endDay) {
|
174
|
+
int time1RangeStartDate = getRangeStartDate(time1, startDay, startTime);
|
175
|
+
int time2RangeStartDate = getRangeStartDate(time2, startDay, startTime);
|
176
|
+
return time1RangeStartDate == time2RangeStartDate;
|
177
|
+
} else {
|
178
|
+
int day1 = time1.getJulianDate();
|
179
|
+
int day2 = time2.getJulianDate();
|
180
|
+
|
181
|
+
// session start and end day are the same day, which is also both of these time's day
|
182
|
+
if (time1.getJulianDate() == time2.getJulianDate() && startDay == time1.getWeekDay()) {
|
183
|
+
auto time1_utcTimeOnly = UtcTimeOnly(time1);
|
184
|
+
auto time2_utcTimeOnly = UtcTimeOnly(time2);
|
185
|
+
auto startTime_utcTimeOnly = UtcTimeOnly(startTime);
|
186
|
+
auto endTime_utcTimeOnly = UtcTimeOnly(endTime);
|
187
|
+
bool bothBeforeEndOfRange = time1_utcTimeOnly <= endTime_utcTimeOnly && time2_utcTimeOnly <= endTime_utcTimeOnly;
|
188
|
+
bool bothAfterStartOfRange
|
189
|
+
= time1_utcTimeOnly >= startTime_utcTimeOnly && time2_utcTimeOnly >= startTime_utcTimeOnly;
|
190
|
+
return bothBeforeEndOfRange || bothAfterStartOfRange;
|
191
|
+
}
|
192
|
+
|
193
|
+
// session start and end day are the same day, which is neither of these time's day
|
194
|
+
else if (day1 == day2 && startDay != time1.getWeekDay()) {
|
195
|
+
return true;
|
196
|
+
}
|
197
|
+
|
198
|
+
// session start and end day are 7 days apart, so times greater than 7 days apart means different range
|
199
|
+
else if (abs(day1 - day2) > 7) {
|
200
|
+
return false;
|
201
|
+
}
|
202
|
+
|
203
|
+
else if (abs(day1 - day2) == 7) {
|
204
|
+
if (time1.getWeekDay() != startDay) {
|
205
|
+
return false;
|
206
|
+
}
|
207
|
+
|
208
|
+
// a week apart on start days
|
209
|
+
DateTime earlierTime, laterTime;
|
210
|
+
if (day2 > day1) {
|
211
|
+
earlierTime = time1;
|
212
|
+
laterTime = time2;
|
213
|
+
} else {
|
214
|
+
earlierTime = time2;
|
215
|
+
laterTime = time1;
|
216
|
+
}
|
217
|
+
return UtcTimeOnly(earlierTime) >= UtcTimeOnly(startTime) && UtcTimeOnly(laterTime) <= UtcTimeOnly(endTime);
|
218
|
+
}
|
219
|
+
// session start and end day are the same day, which is between these times
|
220
|
+
else {
|
221
|
+
int time1RangeStartDate = getRangeStartDate(time1, startDay, startTime);
|
222
|
+
int time2RangeStartDate = getRangeStartDate(time2, startDay, startTime);
|
223
|
+
return time1RangeStartDate == time2RangeStartDate;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
} // namespace FIX
|