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,268 @@
|
|
|
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 "ThreadedSocketInitiator.h"
|
|
27
|
+
#include "Session.h"
|
|
28
|
+
#include "Settings.h"
|
|
29
|
+
|
|
30
|
+
namespace FIX
|
|
31
|
+
{
|
|
32
|
+
ThreadedSocketInitiator::ThreadedSocketInitiator(
|
|
33
|
+
Application& application,
|
|
34
|
+
MessageStoreFactory& factory,
|
|
35
|
+
const SessionSettings& settings ) throw( ConfigError )
|
|
36
|
+
: Initiator( application, factory, settings ),
|
|
37
|
+
m_lastConnect( 0 ), m_reconnectInterval( 30 ), m_noDelay( false ),
|
|
38
|
+
m_sendBufSize( 0 ), m_rcvBufSize( 0 )
|
|
39
|
+
{
|
|
40
|
+
socket_init();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ThreadedSocketInitiator::ThreadedSocketInitiator(
|
|
44
|
+
Application& application,
|
|
45
|
+
MessageStoreFactory& factory,
|
|
46
|
+
const SessionSettings& settings,
|
|
47
|
+
LogFactory& logFactory ) throw( ConfigError )
|
|
48
|
+
: Initiator( application, factory, settings, logFactory ),
|
|
49
|
+
m_lastConnect( 0 ), m_reconnectInterval( 30 ), m_noDelay( false ),
|
|
50
|
+
m_sendBufSize( 0 ), m_rcvBufSize( 0 )
|
|
51
|
+
{
|
|
52
|
+
socket_init();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ThreadedSocketInitiator::~ThreadedSocketInitiator()
|
|
56
|
+
{
|
|
57
|
+
socket_term();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void ThreadedSocketInitiator::onConfigure( const SessionSettings& s )
|
|
61
|
+
throw ( ConfigError )
|
|
62
|
+
{
|
|
63
|
+
const Dictionary& dict = s.get();
|
|
64
|
+
|
|
65
|
+
if( dict.has( RECONNECT_INTERVAL ) )
|
|
66
|
+
m_reconnectInterval = dict.getInt( RECONNECT_INTERVAL );
|
|
67
|
+
if( dict.has( SOCKET_NODELAY ) )
|
|
68
|
+
m_noDelay = dict.getBool( SOCKET_NODELAY );
|
|
69
|
+
if( dict.has( SOCKET_SEND_BUFFER_SIZE ) )
|
|
70
|
+
m_sendBufSize = dict.getInt( SOCKET_SEND_BUFFER_SIZE );
|
|
71
|
+
if( dict.has( SOCKET_RECEIVE_BUFFER_SIZE ) )
|
|
72
|
+
m_rcvBufSize = dict.getInt( SOCKET_RECEIVE_BUFFER_SIZE );
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void ThreadedSocketInitiator::onInitialize( const SessionSettings& s )
|
|
76
|
+
throw ( RuntimeError )
|
|
77
|
+
{
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
void ThreadedSocketInitiator::onStart()
|
|
81
|
+
{
|
|
82
|
+
while ( !isStopped() )
|
|
83
|
+
{
|
|
84
|
+
time_t now;
|
|
85
|
+
::time( &now );
|
|
86
|
+
|
|
87
|
+
if ( (now - m_lastConnect) >= m_reconnectInterval )
|
|
88
|
+
{
|
|
89
|
+
Locker l( m_mutex );
|
|
90
|
+
connect();
|
|
91
|
+
m_lastConnect = now;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
process_sleep( 1 );
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
bool ThreadedSocketInitiator::onPoll( double timeout )
|
|
99
|
+
{
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void ThreadedSocketInitiator::onStop()
|
|
104
|
+
{
|
|
105
|
+
SocketToThread threads;
|
|
106
|
+
SocketToThread::iterator i;
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
Locker l(m_mutex);
|
|
110
|
+
|
|
111
|
+
time_t start = 0;
|
|
112
|
+
time_t now = 0;
|
|
113
|
+
|
|
114
|
+
::time( &start );
|
|
115
|
+
while ( isLoggedOn() )
|
|
116
|
+
{
|
|
117
|
+
if( ::time(&now) -5 >= start )
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
threads = m_threads;
|
|
122
|
+
m_threads.clear();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for ( i = threads.begin(); i != threads.end(); ++i )
|
|
126
|
+
socket_close( i->first );
|
|
127
|
+
|
|
128
|
+
for ( i = threads.begin(); i != threads.end(); ++i )
|
|
129
|
+
thread_join( i->second );
|
|
130
|
+
threads.clear();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
void ThreadedSocketInitiator::doConnect( const SessionID& s, const Dictionary& d )
|
|
134
|
+
{
|
|
135
|
+
try
|
|
136
|
+
{
|
|
137
|
+
Session* session = Session::lookupSession( s );
|
|
138
|
+
if( !session->isSessionTime(UtcTimeStamp()) ) return;
|
|
139
|
+
|
|
140
|
+
Log* log = session->getLog();
|
|
141
|
+
|
|
142
|
+
std::string address;
|
|
143
|
+
short port = 0;
|
|
144
|
+
getHost( s, d, address, port );
|
|
145
|
+
|
|
146
|
+
int socket = socket_createConnector();
|
|
147
|
+
if( m_noDelay )
|
|
148
|
+
socket_setsockopt( socket, TCP_NODELAY );
|
|
149
|
+
if( m_sendBufSize )
|
|
150
|
+
socket_setsockopt( socket, SO_SNDBUF, m_sendBufSize );
|
|
151
|
+
if( m_rcvBufSize )
|
|
152
|
+
socket_setsockopt( socket, SO_RCVBUF, m_rcvBufSize );
|
|
153
|
+
|
|
154
|
+
setPending( s );
|
|
155
|
+
log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) );
|
|
156
|
+
|
|
157
|
+
ThreadedSocketConnection* pConnection =
|
|
158
|
+
new ThreadedSocketConnection( s, socket, address, port, getLog() );
|
|
159
|
+
|
|
160
|
+
ThreadPair* pair = new ThreadPair( this, pConnection );
|
|
161
|
+
|
|
162
|
+
{
|
|
163
|
+
Locker l( m_mutex );
|
|
164
|
+
thread_id thread;
|
|
165
|
+
if ( thread_spawn( &socketThread, pair, thread ) )
|
|
166
|
+
{
|
|
167
|
+
addThread( socket, thread );
|
|
168
|
+
}
|
|
169
|
+
else
|
|
170
|
+
{
|
|
171
|
+
delete pair;
|
|
172
|
+
pConnection->disconnect();
|
|
173
|
+
delete pConnection;
|
|
174
|
+
setDisconnected( s );
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch ( std::exception& ) {}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void ThreadedSocketInitiator::addThread( int s, thread_id t )
|
|
182
|
+
{
|
|
183
|
+
Locker l(m_mutex);
|
|
184
|
+
|
|
185
|
+
m_threads[ s ] = t;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
void ThreadedSocketInitiator::removeThread( int s )
|
|
189
|
+
{
|
|
190
|
+
Locker l(m_mutex);
|
|
191
|
+
SocketToThread::iterator i = m_threads.find( s );
|
|
192
|
+
|
|
193
|
+
if ( i != m_threads.end() )
|
|
194
|
+
{
|
|
195
|
+
thread_detach( i->second );
|
|
196
|
+
m_threads.erase( i );
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
THREAD_PROC ThreadedSocketInitiator::socketThread( void* p )
|
|
201
|
+
{
|
|
202
|
+
ThreadPair * pair = reinterpret_cast < ThreadPair* > ( p );
|
|
203
|
+
|
|
204
|
+
ThreadedSocketInitiator* pInitiator = pair->first;
|
|
205
|
+
ThreadedSocketConnection* pConnection = pair->second;
|
|
206
|
+
FIX::SessionID sessionID = pConnection->getSession()->getSessionID();
|
|
207
|
+
FIX::Session* pSession = FIX::Session::lookupSession( sessionID );
|
|
208
|
+
int socket = pConnection->getSocket();
|
|
209
|
+
delete pair;
|
|
210
|
+
|
|
211
|
+
pInitiator->lock();
|
|
212
|
+
|
|
213
|
+
if( !pConnection->connect() )
|
|
214
|
+
{
|
|
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();
|
|
227
|
+
|
|
228
|
+
while ( pConnection->read() ) {}
|
|
229
|
+
|
|
230
|
+
delete pConnection;
|
|
231
|
+
if( !pInitiator->isStopped() )
|
|
232
|
+
pInitiator->removeThread( socket );
|
|
233
|
+
|
|
234
|
+
pInitiator->setDisconnected( sessionID );
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
void ThreadedSocketInitiator::getHost( const SessionID& s, const Dictionary& d,
|
|
239
|
+
std::string& address, short& port )
|
|
240
|
+
{
|
|
241
|
+
int num = 0;
|
|
242
|
+
SessionToHostNum::iterator i = m_sessionToHostNum.find( s );
|
|
243
|
+
if ( i != m_sessionToHostNum.end() ) num = i->second;
|
|
244
|
+
|
|
245
|
+
std::stringstream hostStream;
|
|
246
|
+
hostStream << SOCKET_CONNECT_HOST << num;
|
|
247
|
+
std::string hostString = hostStream.str();
|
|
248
|
+
|
|
249
|
+
std::stringstream portStream;
|
|
250
|
+
portStream << SOCKET_CONNECT_PORT << num;
|
|
251
|
+
std::string portString = portStream.str();
|
|
252
|
+
|
|
253
|
+
if( d.has(hostString) && d.has(portString) )
|
|
254
|
+
{
|
|
255
|
+
address = d.getString( hostString );
|
|
256
|
+
port = ( short ) d.getInt( portString );
|
|
257
|
+
}
|
|
258
|
+
else
|
|
259
|
+
{
|
|
260
|
+
num = 0;
|
|
261
|
+
address = d.getString( SOCKET_CONNECT_HOST );
|
|
262
|
+
port = ( short ) d.getInt( SOCKET_CONNECT_PORT );
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
m_sessionToHostNum[ s ] = ++num;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 "Initiator.h"
|
|
30
|
+
#include "ThreadedSocketConnection.h"
|
|
31
|
+
#include <map>
|
|
32
|
+
|
|
33
|
+
namespace FIX
|
|
34
|
+
{
|
|
35
|
+
/*! \addtogroup user
|
|
36
|
+
* @{
|
|
37
|
+
*/
|
|
38
|
+
/// Threaded Socket implementation of Initiator.
|
|
39
|
+
class ThreadedSocketInitiator : public Initiator
|
|
40
|
+
{
|
|
41
|
+
public:
|
|
42
|
+
ThreadedSocketInitiator( Application&, MessageStoreFactory&,
|
|
43
|
+
const SessionSettings& ) throw( ConfigError );
|
|
44
|
+
ThreadedSocketInitiator( Application&, MessageStoreFactory&,
|
|
45
|
+
const SessionSettings&,
|
|
46
|
+
LogFactory& ) throw( ConfigError );
|
|
47
|
+
|
|
48
|
+
virtual ~ThreadedSocketInitiator();
|
|
49
|
+
|
|
50
|
+
private:
|
|
51
|
+
typedef std::map < int, thread_id > SocketToThread;
|
|
52
|
+
typedef std::map < SessionID, int > SessionToHostNum;
|
|
53
|
+
typedef std::pair < ThreadedSocketInitiator*, ThreadedSocketConnection* > ThreadPair;
|
|
54
|
+
|
|
55
|
+
void onConfigure( const SessionSettings& ) throw ( ConfigError );
|
|
56
|
+
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
|
|
57
|
+
|
|
58
|
+
void onStart();
|
|
59
|
+
bool onPoll( double timeout );
|
|
60
|
+
void onStop();
|
|
61
|
+
|
|
62
|
+
void doConnect( const SessionID& s, const Dictionary& d );
|
|
63
|
+
|
|
64
|
+
void addThread( int s, thread_id t );
|
|
65
|
+
void removeThread( int s );
|
|
66
|
+
void lock() { Locker l(m_mutex); }
|
|
67
|
+
static THREAD_PROC socketThread( void* p );
|
|
68
|
+
|
|
69
|
+
void getHost( const SessionID&, const Dictionary&, std::string&, short& );
|
|
70
|
+
|
|
71
|
+
SessionSettings m_settings;
|
|
72
|
+
SessionToHostNum m_sessionToHostNum;
|
|
73
|
+
time_t m_lastConnect;
|
|
74
|
+
int m_reconnectInterval;
|
|
75
|
+
bool m_noDelay;
|
|
76
|
+
int m_sendBufSize;
|
|
77
|
+
int m_rcvBufSize;
|
|
78
|
+
SocketToThread m_threads;
|
|
79
|
+
Mutex m_mutex;
|
|
80
|
+
};
|
|
81
|
+
/*! @} */
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#endif //FIX_THREADEDSOCKETINITIATOR_H
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
{
|
|
31
|
+
TimeRange::TimeRange( const UtcTimeOnly& startTime,
|
|
32
|
+
const UtcTimeOnly& endTime,
|
|
33
|
+
int startDay,
|
|
34
|
+
int endDay )
|
|
35
|
+
: m_startTime( startTime ), m_endTime( endTime ),
|
|
36
|
+
m_startDay( startDay ), m_endDay( endDay ),
|
|
37
|
+
m_useLocalTime( false )
|
|
38
|
+
{
|
|
39
|
+
if( startDay > 0
|
|
40
|
+
&& endDay > 0
|
|
41
|
+
&& startDay == endDay
|
|
42
|
+
&& endTime > startTime )
|
|
43
|
+
{ m_endTime = m_startTime; }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
TimeRange::TimeRange( const LocalTimeOnly& startTime,
|
|
47
|
+
const LocalTimeOnly& endTime,
|
|
48
|
+
int startDay,
|
|
49
|
+
int endDay )
|
|
50
|
+
: m_startTime( startTime ), m_endTime( endTime ),
|
|
51
|
+
m_startDay( startDay ), m_endDay( endDay ),
|
|
52
|
+
m_useLocalTime( true )
|
|
53
|
+
{
|
|
54
|
+
if( startDay > 0
|
|
55
|
+
&& endDay > 0
|
|
56
|
+
&& startDay == endDay
|
|
57
|
+
&& endTime > startTime )
|
|
58
|
+
{ m_endTime = m_startTime; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
bool TimeRange::isInRange( const DateTime& start,
|
|
62
|
+
const DateTime& end,
|
|
63
|
+
const DateTime& time )
|
|
64
|
+
{
|
|
65
|
+
UtcTimeOnly timeOnly (time);
|
|
66
|
+
|
|
67
|
+
if( start < end )
|
|
68
|
+
return( timeOnly >= start && timeOnly <= end );
|
|
69
|
+
else
|
|
70
|
+
return( timeOnly >= start || timeOnly <= end );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
bool TimeRange::isInRange( const DateTime& startTime,
|
|
74
|
+
const DateTime& endTime,
|
|
75
|
+
int startDay,
|
|
76
|
+
int endDay,
|
|
77
|
+
const DateTime& time,
|
|
78
|
+
int day )
|
|
79
|
+
{
|
|
80
|
+
UtcTimeOnly timeOnly (time);
|
|
81
|
+
|
|
82
|
+
if( startDay == endDay )
|
|
83
|
+
{
|
|
84
|
+
if( day != startDay )
|
|
85
|
+
return true;
|
|
86
|
+
return isInRange( startTime, endTime, time );
|
|
87
|
+
}
|
|
88
|
+
else if( startDay < endDay )
|
|
89
|
+
{
|
|
90
|
+
if( day < startDay || day > endDay )
|
|
91
|
+
return false;
|
|
92
|
+
else if( day == startDay && timeOnly < startTime )
|
|
93
|
+
return false;
|
|
94
|
+
else if( day == endDay && timeOnly > endTime )
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
else if( startDay > endDay )
|
|
98
|
+
{
|
|
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
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
bool TimeRange::isInRange( const DateTime& startTime,
|
|
110
|
+
const DateTime& endTime,
|
|
111
|
+
int startDay,
|
|
112
|
+
int endDay,
|
|
113
|
+
const DateTime& time )
|
|
114
|
+
{
|
|
115
|
+
return isInRange( startTime, endTime, startDay, endDay, time, time.getWeekDay() );
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
bool TimeRange::isInSameRange( const DateTime& start,
|
|
119
|
+
const DateTime& end,
|
|
120
|
+
const DateTime& time1,
|
|
121
|
+
const DateTime& time2 )
|
|
122
|
+
{
|
|
123
|
+
if( !isInRange( start, end, time1 ) ) return false;
|
|
124
|
+
if( !isInRange( start, end, time2 ) ) return false;
|
|
125
|
+
|
|
126
|
+
if( time1 == time2 ) return true;
|
|
127
|
+
|
|
128
|
+
if( start < end || start == end )
|
|
129
|
+
{
|
|
130
|
+
UtcDate time1Date( time1 );
|
|
131
|
+
UtcDate time2Date( time2 );
|
|
132
|
+
|
|
133
|
+
return time1Date == time2Date;
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
{
|
|
137
|
+
int sessionLength = DateTime::SECONDS_PER_DAY - (start - end);
|
|
138
|
+
|
|
139
|
+
if( time1 > time2 )
|
|
140
|
+
{
|
|
141
|
+
UtcTimeOnly time2TimeOnly = UtcTimeOnly(time2);
|
|
142
|
+
|
|
143
|
+
long delta = time2TimeOnly - start;
|
|
144
|
+
if( delta < 0 )
|
|
145
|
+
delta = DateTime::SECONDS_PER_DAY - labs(delta);
|
|
146
|
+
|
|
147
|
+
return (time1 - time2) < (sessionLength - delta);
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
{
|
|
151
|
+
return (time2 - time1) < sessionLength;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
bool TimeRange::isInSameRange( const DateTime& startTime,
|
|
157
|
+
const DateTime& endTime,
|
|
158
|
+
int startDay,
|
|
159
|
+
int endDay,
|
|
160
|
+
const DateTime& time1,
|
|
161
|
+
const DateTime& time2 )
|
|
162
|
+
{
|
|
163
|
+
if( !isInRange( startTime, endTime, startDay, endDay, time1, time1.getWeekDay() ) )
|
|
164
|
+
return false;
|
|
165
|
+
|
|
166
|
+
if( !isInRange( startTime, endTime, startDay, endDay, time2, time2.getWeekDay() ) )
|
|
167
|
+
return false;
|
|
168
|
+
|
|
169
|
+
int absoluteDay1 = time1.getJulianDate() - time1.getWeekDay();
|
|
170
|
+
int absoluteDay2 = time2.getJulianDate() - time2.getWeekDay();
|
|
171
|
+
return absoluteDay1 == absoluteDay2;
|
|
172
|
+
}
|
|
173
|
+
}
|