quickfix_ruby_ud 2.0.7

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.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +257 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +137 -0
  6. data/ext/quickfix/DOMDocument.h +70 -0
  7. data/ext/quickfix/DataDictionary.cpp +679 -0
  8. data/ext/quickfix/DataDictionary.h +607 -0
  9. data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
  10. data/ext/quickfix/DataDictionaryProvider.h +67 -0
  11. data/ext/quickfix/DatabaseConnectionID.h +98 -0
  12. data/ext/quickfix/DatabaseConnectionPool.h +84 -0
  13. data/ext/quickfix/Dictionary.cpp +157 -0
  14. data/ext/quickfix/Dictionary.h +89 -0
  15. data/ext/quickfix/Event.h +89 -0
  16. data/ext/quickfix/Except.h +39 -0
  17. data/ext/quickfix/Exceptions.h +257 -0
  18. data/ext/quickfix/Field.h +654 -0
  19. data/ext/quickfix/FieldConvertors.cpp +86 -0
  20. data/ext/quickfix/FieldConvertors.h +800 -0
  21. data/ext/quickfix/FieldMap.cpp +254 -0
  22. data/ext/quickfix/FieldMap.h +327 -0
  23. data/ext/quickfix/FieldNumbers.h +44 -0
  24. data/ext/quickfix/FieldTypes.cpp +62 -0
  25. data/ext/quickfix/FieldTypes.h +817 -0
  26. data/ext/quickfix/Fields.h +30 -0
  27. data/ext/quickfix/FileLog.cpp +176 -0
  28. data/ext/quickfix/FileLog.h +110 -0
  29. data/ext/quickfix/FileStore.cpp +369 -0
  30. data/ext/quickfix/FileStore.h +131 -0
  31. data/ext/quickfix/FixCommonFields.h +13 -0
  32. data/ext/quickfix/FixFieldNumbers.h +6132 -0
  33. data/ext/quickfix/FixFields.h +6133 -0
  34. data/ext/quickfix/FixValues.h +5790 -0
  35. data/ext/quickfix/Group.cpp +44 -0
  36. data/ext/quickfix/Group.h +78 -0
  37. data/ext/quickfix/HostDetailsProvider.cpp +79 -0
  38. data/ext/quickfix/HostDetailsProvider.h +44 -0
  39. data/ext/quickfix/HtmlBuilder.h +178 -0
  40. data/ext/quickfix/HttpConnection.cpp +914 -0
  41. data/ext/quickfix/HttpConnection.h +74 -0
  42. data/ext/quickfix/HttpMessage.cpp +229 -0
  43. data/ext/quickfix/HttpMessage.h +112 -0
  44. data/ext/quickfix/HttpParser.cpp +49 -0
  45. data/ext/quickfix/HttpParser.h +49 -0
  46. data/ext/quickfix/HttpServer.cpp +152 -0
  47. data/ext/quickfix/HttpServer.h +76 -0
  48. data/ext/quickfix/Initiator.cpp +310 -0
  49. data/ext/quickfix/Initiator.h +151 -0
  50. data/ext/quickfix/Log.cpp +71 -0
  51. data/ext/quickfix/Log.h +254 -0
  52. data/ext/quickfix/Message.cpp +617 -0
  53. data/ext/quickfix/Message.h +419 -0
  54. data/ext/quickfix/MessageCracker.h +171 -0
  55. data/ext/quickfix/MessageSorters.cpp +101 -0
  56. data/ext/quickfix/MessageSorters.h +185 -0
  57. data/ext/quickfix/MessageStore.cpp +182 -0
  58. data/ext/quickfix/MessageStore.h +164 -0
  59. data/ext/quickfix/Mutex.h +120 -0
  60. data/ext/quickfix/MySQLConnection.h +187 -0
  61. data/ext/quickfix/MySQLLog.cpp +262 -0
  62. data/ext/quickfix/MySQLLog.h +158 -0
  63. data/ext/quickfix/MySQLStore.cpp +323 -0
  64. data/ext/quickfix/MySQLStore.h +161 -0
  65. data/ext/quickfix/MySQLStubs.h +203 -0
  66. data/ext/quickfix/NullStore.cpp +40 -0
  67. data/ext/quickfix/NullStore.h +89 -0
  68. data/ext/quickfix/OdbcConnection.h +241 -0
  69. data/ext/quickfix/OdbcLog.cpp +230 -0
  70. data/ext/quickfix/OdbcLog.h +109 -0
  71. data/ext/quickfix/OdbcStore.cpp +313 -0
  72. data/ext/quickfix/OdbcStore.h +124 -0
  73. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  74. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  75. data/ext/quickfix/Parser.cpp +111 -0
  76. data/ext/quickfix/Parser.h +50 -0
  77. data/ext/quickfix/PostgreSQLConnection.h +163 -0
  78. data/ext/quickfix/PostgreSQLLog.cpp +263 -0
  79. data/ext/quickfix/PostgreSQLLog.h +157 -0
  80. data/ext/quickfix/PostgreSQLStore.cpp +327 -0
  81. data/ext/quickfix/PostgreSQLStore.h +160 -0
  82. data/ext/quickfix/PostgreSQLStubs.h +203 -0
  83. data/ext/quickfix/Queue.h +66 -0
  84. data/ext/quickfix/QuickfixRuby.cpp +131900 -0
  85. data/ext/quickfix/QuickfixRuby.h +56 -0
  86. data/ext/quickfix/Responder.h +41 -0
  87. data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
  88. data/ext/quickfix/SSLSocketAcceptor.h +186 -0
  89. data/ext/quickfix/SSLSocketConnection.cpp +434 -0
  90. data/ext/quickfix/SSLSocketConnection.h +221 -0
  91. data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
  92. data/ext/quickfix/SSLSocketInitiator.h +203 -0
  93. data/ext/quickfix/SSLStubs.h +129 -0
  94. data/ext/quickfix/Session.cpp +1437 -0
  95. data/ext/quickfix/Session.h +343 -0
  96. data/ext/quickfix/SessionFactory.cpp +314 -0
  97. data/ext/quickfix/SessionFactory.h +84 -0
  98. data/ext/quickfix/SessionID.h +136 -0
  99. data/ext/quickfix/SessionSettings.cpp +165 -0
  100. data/ext/quickfix/SessionSettings.h +283 -0
  101. data/ext/quickfix/SessionState.h +260 -0
  102. data/ext/quickfix/Settings.cpp +160 -0
  103. data/ext/quickfix/Settings.h +56 -0
  104. data/ext/quickfix/SharedArray.h +274 -0
  105. data/ext/quickfix/SocketAcceptor.cpp +216 -0
  106. data/ext/quickfix/SocketAcceptor.h +77 -0
  107. data/ext/quickfix/SocketConnection.cpp +256 -0
  108. data/ext/quickfix/SocketConnection.h +102 -0
  109. data/ext/quickfix/SocketConnector.cpp +112 -0
  110. data/ext/quickfix/SocketConnector.h +76 -0
  111. data/ext/quickfix/SocketInitiator.cpp +241 -0
  112. data/ext/quickfix/SocketInitiator.h +76 -0
  113. data/ext/quickfix/SocketMonitor.h +26 -0
  114. data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
  115. data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
  116. data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
  117. data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
  118. data/ext/quickfix/SocketServer.cpp +163 -0
  119. data/ext/quickfix/SocketServer.h +100 -0
  120. data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
  121. data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
  122. data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
  123. data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
  124. data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
  125. data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
  126. data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
  127. data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
  128. data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
  129. data/ext/quickfix/ThreadedSocketConnection.h +89 -0
  130. data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
  131. data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
  132. data/ext/quickfix/TimeRange.cpp +227 -0
  133. data/ext/quickfix/TimeRange.h +215 -0
  134. data/ext/quickfix/Utility.cpp +639 -0
  135. data/ext/quickfix/Utility.h +255 -0
  136. data/ext/quickfix/UtilitySSL.cpp +1612 -0
  137. data/ext/quickfix/UtilitySSL.h +274 -0
  138. data/ext/quickfix/Values.h +63 -0
  139. data/ext/quickfix/config-all.h +10 -0
  140. data/ext/quickfix/config.h +10 -0
  141. data/ext/quickfix/config_unix.h +178 -0
  142. data/ext/quickfix/config_windows.h +0 -0
  143. data/ext/quickfix/dirent_windows.h +838 -0
  144. data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
  145. data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
  146. data/ext/quickfix/double-conversion/bignum.cc +766 -0
  147. data/ext/quickfix/double-conversion/bignum.h +144 -0
  148. data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
  149. data/ext/quickfix/double-conversion/cached-powers.h +64 -0
  150. data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
  151. data/ext/quickfix/double-conversion/diy-fp.h +118 -0
  152. data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
  153. data/ext/quickfix/double-conversion/double-conversion.h +543 -0
  154. data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
  155. data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
  156. data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
  157. data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
  158. data/ext/quickfix/double-conversion/ieee.h +402 -0
  159. data/ext/quickfix/double-conversion/strtod.cc +557 -0
  160. data/ext/quickfix/double-conversion/strtod.h +45 -0
  161. data/ext/quickfix/double-conversion/utils.h +374 -0
  162. data/ext/quickfix/extconf.rb +76 -0
  163. data/ext/quickfix/index.h +37 -0
  164. data/ext/quickfix/pugiconfig.hpp +77 -0
  165. data/ext/quickfix/pugixml.cpp +13237 -0
  166. data/ext/quickfix/pugixml.hpp +1516 -0
  167. data/ext/quickfix/scope_guard.hpp +215 -0
  168. data/ext/quickfix/stdint_msvc.h +254 -0
  169. data/ext/quickfix/strptime.h +7 -0
  170. data/lib/quickfix40.rb +274 -0
  171. data/lib/quickfix41.rb +351 -0
  172. data/lib/quickfix42.rb +1184 -0
  173. data/lib/quickfix43.rb +3504 -0
  174. data/lib/quickfix44.rb +14040 -0
  175. data/lib/quickfix50.rb +20051 -0
  176. data/lib/quickfix50sp1.rb +23596 -0
  177. data/lib/quickfix50sp2.rb +412444 -0
  178. data/lib/quickfix_fields.rb +79393 -0
  179. data/lib/quickfix_ruby.rb +82 -0
  180. data/lib/quickfixt11.rb +65 -0
  181. data/spec/FIX40.xml +862 -0
  182. data/spec/FIX41.xml +1282 -0
  183. data/spec/FIX42.xml +2743 -0
  184. data/spec/FIX43.xml +4230 -0
  185. data/spec/FIX44.xml +6600 -0
  186. data/spec/FIX50.xml +8142 -0
  187. data/spec/FIX50SP1.xml +9506 -0
  188. data/spec/FIX50SP2.xml +26069 -0
  189. data/spec/FIXT11.xml +252 -0
  190. data/test/DataDictionaryTestCase.rb +268 -0
  191. data/test/DictionaryTestCase.rb +112 -0
  192. data/test/FieldBaseTestCase.rb +24 -0
  193. data/test/MessageStoreTestCase.rb +19 -0
  194. data/test/MessageTestCase.rb +368 -0
  195. data/test/SessionSettingsTestCase.rb +41 -0
  196. metadata +236 -0
@@ -0,0 +1,248 @@
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
+
22
+ #include "stdafx.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_timeval.tv_sec = 0;
44
+ m_timeval.tv_usec = 0;
45
+ #ifndef SELECT_DECREMENTS_TIME
46
+ m_ticks = clock();
47
+ #endif
48
+ }
49
+
50
+ SocketMonitor::~SocketMonitor() {
51
+ Sockets::iterator i;
52
+ for (i = m_readSockets.begin(); i != m_readSockets.end(); ++i) {
53
+ socket_close(*i);
54
+ }
55
+
56
+ socket_close(m_signal);
57
+ socket_term();
58
+ }
59
+
60
+ bool SocketMonitor::addConnect(socket_handle s) {
61
+ socket_setnonblock(s);
62
+ Sockets::iterator i = m_connectSockets.find(s);
63
+ if (i != m_connectSockets.end()) {
64
+ return false;
65
+ }
66
+
67
+ m_connectSockets.insert(s);
68
+ return true;
69
+ }
70
+
71
+ bool SocketMonitor::addRead(socket_handle s) {
72
+ socket_setnonblock(s);
73
+ Sockets::iterator i = m_readSockets.find(s);
74
+ if (i != m_readSockets.end()) {
75
+ return false;
76
+ }
77
+
78
+ m_readSockets.insert(s);
79
+ return true;
80
+ }
81
+
82
+ bool SocketMonitor::addWrite(socket_handle s) {
83
+ if (m_readSockets.find(s) == m_readSockets.end()) {
84
+ return false;
85
+ }
86
+
87
+ socket_setnonblock(s);
88
+ Sockets::iterator i = m_writeSockets.find(s);
89
+ if (i != m_writeSockets.end()) {
90
+ return false;
91
+ }
92
+
93
+ m_writeSockets.insert(s);
94
+ return true;
95
+ }
96
+
97
+ bool SocketMonitor::drop(socket_handle s) {
98
+ Sockets::iterator i = m_readSockets.find(s);
99
+ Sockets::iterator j = m_writeSockets.find(s);
100
+ Sockets::iterator k = m_connectSockets.find(s);
101
+
102
+ if (i != m_readSockets.end() || j != m_writeSockets.end() || k != m_connectSockets.end()) {
103
+ socket_close(s);
104
+ m_readSockets.erase(s);
105
+ m_writeSockets.erase(s);
106
+ m_connectSockets.erase(s);
107
+ m_dropped.push(s);
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+
113
+ inline timeval *SocketMonitor::getTimeval(bool poll, double timeout) {
114
+ if (poll) {
115
+ m_timeval.tv_sec = 0;
116
+ m_timeval.tv_usec = 0;
117
+ return &m_timeval;
118
+ }
119
+
120
+ timeout = m_timeout;
121
+
122
+ if (!timeout) {
123
+ return 0;
124
+ }
125
+ #ifdef SELECT_MODIFIES_TIMEVAL
126
+ if (!m_timeval.tv_sec && !m_timeval.tv_usec && timeout) {
127
+ m_timeval.tv_sec = timeout;
128
+ }
129
+ return &m_timeval;
130
+ #else
131
+ double elapsed = (double)(clock() - m_ticks) / (double)CLOCKS_PER_SEC;
132
+ if (elapsed >= timeout || elapsed == 0.0) {
133
+ m_ticks = clock();
134
+ m_timeval.tv_sec = 0;
135
+ m_timeval.tv_usec = (long)(timeout * 1000000);
136
+ } else {
137
+ m_timeval.tv_sec = 0;
138
+ m_timeval.tv_usec = (long)((timeout - elapsed) * 1000000);
139
+ }
140
+ return &m_timeval;
141
+ #endif
142
+ }
143
+
144
+ bool SocketMonitor::sleepIfEmpty(bool poll) {
145
+ if (poll) {
146
+ return false;
147
+ }
148
+
149
+ if (m_readSockets.empty() && m_writeSockets.empty() && m_connectSockets.empty()) {
150
+ process_sleep(m_timeout);
151
+ return true;
152
+ } else {
153
+ return false;
154
+ }
155
+ }
156
+
157
+ void SocketMonitor::signal(socket_handle socket) { socket_send(m_signal, (char *)&socket, sizeof(socket)); }
158
+
159
+ void SocketMonitor::unsignal(socket_handle s) {
160
+ Sockets::iterator i = m_writeSockets.find(s);
161
+ if (i == m_writeSockets.end()) {
162
+ return;
163
+ }
164
+
165
+ m_writeSockets.erase(s);
166
+ }
167
+
168
+ void SocketMonitor::block(Strategy &strategy, bool poll, double timeout) {
169
+ while (m_dropped.size()) {
170
+ strategy.onError(*this, m_dropped.front());
171
+ m_dropped.pop();
172
+ if (m_dropped.size() == 0) {
173
+ return;
174
+ }
175
+ }
176
+
177
+ fd_set readSet;
178
+ FD_ZERO(&readSet);
179
+ buildSet(m_readSockets, readSet);
180
+ fd_set writeSet;
181
+ FD_ZERO(&writeSet);
182
+ buildSet(m_connectSockets, writeSet);
183
+ buildSet(m_writeSockets, writeSet);
184
+ fd_set exceptSet;
185
+ FD_ZERO(&exceptSet);
186
+ buildSet(m_connectSockets, exceptSet);
187
+
188
+ if (sleepIfEmpty(poll)) {
189
+ strategy.onTimeout(*this);
190
+ return;
191
+ }
192
+
193
+ int result = select(FD_SETSIZE, &readSet, &writeSet, &exceptSet, getTimeval(poll, timeout));
194
+
195
+ if (result == 0) {
196
+ strategy.onTimeout(*this);
197
+ return;
198
+ } else if (result > 0) {
199
+ processExceptSet(strategy, exceptSet);
200
+ processWriteSet(strategy, writeSet);
201
+ processReadSet(strategy, readSet);
202
+ } else {
203
+ strategy.onError(*this);
204
+ }
205
+ }
206
+
207
+ void SocketMonitor::processReadSet(Strategy &strategy, fd_set &readSet) {
208
+ for (unsigned i = 0; i < readSet.fd_count; ++i) {
209
+ socket_handle s = readSet.fd_array[i];
210
+ if (s == m_interrupt) {
211
+ socket_handle socket = 0;
212
+ socket_recv(s, (char *)&socket, sizeof(socket));
213
+ addWrite(socket);
214
+ } else {
215
+ strategy.onEvent(*this, s);
216
+ }
217
+ }
218
+ }
219
+
220
+ void SocketMonitor::processWriteSet(Strategy &strategy, fd_set &writeSet) {
221
+ for (unsigned i = 0; i < writeSet.fd_count; ++i) {
222
+ socket_handle s = writeSet.fd_array[i];
223
+ if (m_connectSockets.find(s) != m_connectSockets.end()) {
224
+ m_connectSockets.erase(s);
225
+ m_readSockets.insert(s);
226
+ strategy.onConnect(*this, s);
227
+ } else {
228
+ strategy.onWrite(*this, s);
229
+ }
230
+ }
231
+ }
232
+
233
+ void SocketMonitor::processExceptSet(Strategy &strategy, fd_set &exceptSet) {
234
+ for (unsigned i = 0; i < exceptSet.fd_count; ++i) {
235
+ socket_handle s = exceptSet.fd_array[i];
236
+ strategy.onError(*this, s);
237
+ }
238
+ }
239
+
240
+ void SocketMonitor::buildSet(const Sockets &sockets, fd_set &watchSet) {
241
+ Sockets::const_iterator iter;
242
+ for (iter = sockets.begin(); iter != sockets.end(); ++iter) {
243
+ FD_SET(*iter, &watchSet);
244
+ }
245
+ }
246
+ } // namespace FIX
247
+
248
+ #endif
@@ -0,0 +1,99 @@
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_WIND32_H
23
+ #define FIX_SOCKETMONITOR_WIND32_H
24
+
25
+ #ifdef _MSC_VER
26
+
27
+ #include "Utility.h"
28
+
29
+ #include <Winsock2.h>
30
+ typedef int socklen_t;
31
+
32
+ #include <queue>
33
+ #include <set>
34
+ #include <time.h>
35
+
36
+ namespace FIX {
37
+ /// Monitors events on a collection of sockets.
38
+ class SocketMonitor {
39
+ public:
40
+ class Strategy;
41
+
42
+ SocketMonitor(int timeout = 0);
43
+ virtual ~SocketMonitor();
44
+
45
+ bool addConnect(socket_handle socket);
46
+ bool addRead(socket_handle socket);
47
+ bool addWrite(socket_handle socket);
48
+ bool drop(socket_handle socket);
49
+ void signal(socket_handle socket);
50
+ void unsignal(socket_handle socket);
51
+ void block(Strategy &strategy, bool poll = 0, double timeout = 0.0);
52
+
53
+ size_t numSockets() { return m_readSockets.size() - 1; }
54
+
55
+ private:
56
+ typedef std::set<socket_handle> Sockets;
57
+ typedef std::queue<socket_handle> Queue;
58
+
59
+ void setsockopt();
60
+ bool bind();
61
+ bool listen();
62
+ void buildSet(const Sockets &, fd_set &);
63
+ inline timeval *getTimeval(bool poll, double timeout);
64
+ inline bool sleepIfEmpty(bool poll);
65
+
66
+ void processReadSet(Strategy &, fd_set &);
67
+ void processWriteSet(Strategy &, fd_set &);
68
+ void processExceptSet(Strategy &, fd_set &);
69
+
70
+ int m_timeout;
71
+ timeval m_timeval;
72
+ #ifndef SELECT_DECREMENTS_TIME
73
+ clock_t m_ticks;
74
+ #endif
75
+
76
+ socket_handle m_signal;
77
+ socket_handle m_interrupt;
78
+ Sockets m_connectSockets;
79
+ Sockets m_readSockets;
80
+ Sockets m_writeSockets;
81
+ Queue m_dropped;
82
+
83
+ public:
84
+ class Strategy {
85
+ public:
86
+ virtual ~Strategy() {}
87
+ virtual void onConnect(SocketMonitor &, socket_handle socket) = 0;
88
+ virtual void onEvent(SocketMonitor &, socket_handle socket) = 0;
89
+ virtual void onWrite(SocketMonitor &, socket_handle socket) = 0;
90
+ virtual void onError(SocketMonitor &, socket_handle socket) = 0;
91
+ virtual void onError(SocketMonitor &) = 0;
92
+ virtual void onTimeout(SocketMonitor &) {}
93
+ };
94
+ };
95
+ } // namespace FIX
96
+
97
+ #endif //_MSC_VER
98
+
99
+ #endif // FIX_SOCKETMONITOR_WIN32_H
@@ -0,0 +1,163 @@
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 "Exceptions.h"
27
+ #include "SocketServer.h"
28
+ #include "Utility.h"
29
+ #ifndef _MSC_VER
30
+ #include <sys/ioctl.h>
31
+ #include <sys/stat.h>
32
+ #include <sys/types.h>
33
+ #include <unistd.h>
34
+ #endif
35
+ #include <exception>
36
+
37
+ namespace FIX {
38
+ /// Handles events from SocketMonitor for server connections.
39
+ class ServerWrapper : public SocketMonitor::Strategy {
40
+ public:
41
+ ServerWrapper(std::set<socket_handle> sockets, SocketServer &server, SocketServer::Strategy &strategy)
42
+ : m_sockets(sockets),
43
+ m_server(server),
44
+ m_strategy(strategy) {}
45
+
46
+ private:
47
+ void onConnect(SocketMonitor &, socket_handle socket) {}
48
+
49
+ void onEvent(SocketMonitor &monitor, socket_handle socket) {
50
+ if (m_sockets.find(socket) != m_sockets.end()) {
51
+ m_strategy.onConnect(m_server, socket, m_server.accept(socket));
52
+ } else {
53
+ if (!m_strategy.onData(m_server, socket)) {
54
+ onError(monitor, socket);
55
+ }
56
+ }
57
+ }
58
+
59
+ void onWrite(SocketMonitor &, socket_handle socket) { m_strategy.onWrite(m_server, socket); }
60
+
61
+ void onError(SocketMonitor &monitor, socket_handle socket) {
62
+ m_strategy.onDisconnect(m_server, socket);
63
+ monitor.drop(socket);
64
+ }
65
+
66
+ void onError(SocketMonitor &) { m_strategy.onError(m_server); }
67
+
68
+ void onTimeout(SocketMonitor &) { m_strategy.onTimeout(m_server); };
69
+
70
+ typedef std::set<socket_handle> Sockets;
71
+
72
+ Sockets m_sockets;
73
+ SocketServer &m_server;
74
+ SocketServer::Strategy &m_strategy;
75
+ };
76
+
77
+ SocketServer::SocketServer(int timeout)
78
+ : m_monitor(timeout) {}
79
+
80
+ socket_handle SocketServer::add(int port, bool reuse, bool noDelay, int sendBufSize, int rcvBufSize)
81
+ EXCEPT(SocketException &) {
82
+ if (m_portToInfo.find(port) != m_portToInfo.end()) {
83
+ return m_portToInfo[port].m_socket;
84
+ }
85
+
86
+ socket_handle socket = socket_createAcceptor(port, reuse);
87
+ if (socket == INVALID_SOCKET_HANDLE) {
88
+ throw SocketException();
89
+ }
90
+ if (noDelay) {
91
+ socket_setsockopt(socket, TCP_NODELAY);
92
+ }
93
+ if (sendBufSize) {
94
+ socket_setsockopt(socket, SO_SNDBUF, sendBufSize);
95
+ }
96
+ if (rcvBufSize) {
97
+ socket_setsockopt(socket, SO_RCVBUF, rcvBufSize);
98
+ }
99
+ m_monitor.addRead(socket);
100
+
101
+ SocketInfo info(socket, port, noDelay, sendBufSize, rcvBufSize);
102
+ m_socketToInfo[socket] = info;
103
+ m_portToInfo[port] = info;
104
+ return socket;
105
+ }
106
+
107
+ socket_handle SocketServer::accept(socket_handle socket) {
108
+ SocketInfo info = m_socketToInfo[socket];
109
+
110
+ socket_handle result = socket_accept(socket);
111
+ if (info.m_noDelay) {
112
+ socket_setsockopt(result, TCP_NODELAY);
113
+ }
114
+ if (info.m_sendBufSize) {
115
+ socket_setsockopt(result, SO_SNDBUF, info.m_sendBufSize);
116
+ }
117
+ if (info.m_rcvBufSize) {
118
+ socket_setsockopt(result, SO_RCVBUF, info.m_rcvBufSize);
119
+ }
120
+ if (result != INVALID_SOCKET_HANDLE) {
121
+ m_monitor.addConnect(result);
122
+ }
123
+ return result;
124
+ }
125
+
126
+ void SocketServer::close() {
127
+ for (const SocketToInfo::value_type &socketWithInfo : m_socketToInfo) {
128
+ socket_handle socket = socketWithInfo.first;
129
+ socket_close(socket);
130
+ socket_invalidate(socket);
131
+ }
132
+ }
133
+
134
+ bool SocketServer::block(Strategy &strategy, bool poll, double timeout) {
135
+ std::set<socket_handle> sockets;
136
+ for (const SocketToInfo::value_type &socketWithInfo : m_socketToInfo) {
137
+ if (!socket_isValid(socketWithInfo.first)) {
138
+ return false;
139
+ }
140
+ sockets.insert(socketWithInfo.first);
141
+ }
142
+
143
+ ServerWrapper wrapper(sockets, *this, strategy);
144
+ m_monitor.block(wrapper, poll, timeout);
145
+ return true;
146
+ }
147
+
148
+ int SocketServer::socketToPort(socket_handle socket) {
149
+ SocketToInfo::iterator find = m_socketToInfo.find(socket);
150
+ if (find == m_socketToInfo.end()) {
151
+ return 0;
152
+ }
153
+ return find->second.m_port;
154
+ }
155
+
156
+ socket_handle SocketServer::portToSocket(int port) {
157
+ PortToInfo::iterator find = m_portToInfo.find(port);
158
+ if (find == m_portToInfo.end()) {
159
+ return 0;
160
+ }
161
+ return find->second.m_socket;
162
+ }
163
+ } // namespace FIX
@@ -0,0 +1,100 @@
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_SOCKETSERVER_H
23
+ #define FIX_SOCKETSERVER_H
24
+
25
+ #ifdef _MSC_VER
26
+ #pragma warning(disable : 4503 4355 4786 4290)
27
+ #endif
28
+
29
+ #include "Exceptions.h"
30
+ #include "SocketMonitor.h"
31
+ #include <map>
32
+ #include <queue>
33
+ #include <set>
34
+
35
+ namespace FIX {
36
+ /// Information about listening socket
37
+ struct SocketInfo {
38
+ SocketInfo()
39
+ : m_socket(INVALID_SOCKET_HANDLE),
40
+ m_port(0),
41
+ m_noDelay(false),
42
+ m_sendBufSize(0),
43
+ m_rcvBufSize(0) {}
44
+
45
+ SocketInfo(socket_handle socket, short port, bool noDelay, int sendBufSize, int rcvBufSize)
46
+ : m_socket(socket),
47
+ m_port(port),
48
+ m_noDelay(noDelay),
49
+ m_sendBufSize(sendBufSize),
50
+ m_rcvBufSize(rcvBufSize) {}
51
+
52
+ socket_handle m_socket;
53
+ short m_port;
54
+ bool m_noDelay;
55
+ int m_sendBufSize;
56
+ int m_rcvBufSize;
57
+ };
58
+
59
+ /// Listens for and accepts incoming socket connections on a port.
60
+ class SocketServer {
61
+ public:
62
+ class Strategy;
63
+
64
+ SocketServer(int timeout = 0);
65
+
66
+ socket_handle add(int port, bool reuse = false, bool noDelay = false, int sendBufSize = 0, int rcvBufSize = 0)
67
+ EXCEPT(SocketException &);
68
+ socket_handle accept(socket_handle socket);
69
+ void close();
70
+ bool block(Strategy &strategy, bool poll = 0, double timeout = 0.0);
71
+
72
+ size_t numConnections() { return m_monitor.numSockets() - 1; }
73
+ SocketMonitor &getMonitor() { return m_monitor; }
74
+
75
+ int socketToPort(socket_handle socket);
76
+ socket_handle portToSocket(int port);
77
+
78
+ private:
79
+ typedef std::map<socket_handle, SocketInfo> SocketToInfo;
80
+ typedef std::map<int, SocketInfo> PortToInfo;
81
+
82
+ SocketToInfo m_socketToInfo;
83
+ PortToInfo m_portToInfo;
84
+ SocketMonitor m_monitor;
85
+
86
+ public:
87
+ class Strategy {
88
+ public:
89
+ virtual ~Strategy() {}
90
+ virtual void onConnect(SocketServer &, socket_handle acceptSocket, socket_handle socket) = 0;
91
+ virtual void onWrite(SocketServer &, socket_handle socket) = 0;
92
+ virtual bool onData(SocketServer &, socket_handle socket) = 0;
93
+ virtual void onDisconnect(SocketServer &, socket_handle socket) = 0;
94
+ virtual void onError(SocketServer &) = 0;
95
+ virtual void onTimeout(SocketServer &) {};
96
+ };
97
+ };
98
+ } // namespace FIX
99
+
100
+ #endif // FIX_SOCKETSERVER_H