quickfix_ruby 1.14.3.1 → 1.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/ext/quickfix/Acceptor.h +2 -0
  3. data/ext/quickfix/AtomicCount.h +82 -12
  4. data/ext/quickfix/DOMDocument.h +9 -7
  5. data/ext/quickfix/DataDictionary.cpp +77 -14
  6. data/ext/quickfix/DataDictionary.h +90 -16
  7. data/ext/quickfix/Dictionary.cpp +1 -2
  8. data/ext/quickfix/Exceptions.h +3 -5
  9. data/ext/quickfix/Field.h +83 -32
  10. data/ext/quickfix/FieldConvertors.cpp +93 -0
  11. data/ext/quickfix/FieldConvertors.h +129 -275
  12. data/ext/quickfix/FieldMap.cpp +53 -13
  13. data/ext/quickfix/FieldMap.h +200 -62
  14. data/ext/quickfix/FieldTypes.cpp +10 -10
  15. data/ext/quickfix/FieldTypes.h +293 -44
  16. data/ext/quickfix/FileLog.cpp +6 -10
  17. data/ext/quickfix/FileLog.h +4 -10
  18. data/ext/quickfix/FileStore.cpp +19 -6
  19. data/ext/quickfix/FileStore.h +4 -0
  20. data/ext/quickfix/FixFieldNumbers.h +1462 -1461
  21. data/ext/quickfix/FixFields.h +1462 -1461
  22. data/ext/quickfix/FixValues.h +3230 -3227
  23. data/ext/quickfix/HttpConnection.cpp +1 -1
  24. data/ext/quickfix/Initiator.cpp +7 -1
  25. data/ext/quickfix/Initiator.h +2 -0
  26. data/ext/quickfix/Log.h +6 -12
  27. data/ext/quickfix/Message.cpp +186 -57
  28. data/ext/quickfix/Message.h +109 -47
  29. data/ext/quickfix/MySQLConnection.h +1 -1
  30. data/ext/quickfix/PostgreSQLConnection.h +1 -1
  31. data/ext/quickfix/QuickfixRuby.cpp +79141 -77959
  32. data/ext/quickfix/QuickfixRuby.h +1 -1
  33. data/ext/quickfix/SSLSocketAcceptor.cpp +410 -0
  34. data/ext/quickfix/SSLSocketAcceptor.h +185 -0
  35. data/ext/quickfix/SSLSocketConnection.cpp +427 -0
  36. data/ext/quickfix/SSLSocketConnection.h +206 -0
  37. data/ext/quickfix/SSLSocketInitiator.cpp +485 -0
  38. data/ext/quickfix/SSLSocketInitiator.h +196 -0
  39. data/ext/quickfix/Session.cpp +113 -20
  40. data/ext/quickfix/Session.h +18 -4
  41. data/ext/quickfix/SessionFactory.cpp +10 -3
  42. data/ext/quickfix/SessionSettings.cpp +5 -3
  43. data/ext/quickfix/SessionSettings.h +97 -5
  44. data/ext/quickfix/Settings.cpp +72 -2
  45. data/ext/quickfix/Settings.h +3 -0
  46. data/ext/quickfix/SharedArray.h +140 -6
  47. data/ext/quickfix/SocketConnection.cpp +2 -2
  48. data/ext/quickfix/SocketConnector.cpp +5 -2
  49. data/ext/quickfix/SocketConnector.h +3 -2
  50. data/ext/quickfix/SocketInitiator.cpp +28 -4
  51. data/ext/quickfix/SocketInitiator.h +1 -1
  52. data/ext/quickfix/SocketMonitor.cpp +5 -5
  53. data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +455 -0
  54. data/ext/quickfix/ThreadedSSLSocketAcceptor.h +217 -0
  55. data/ext/quickfix/ThreadedSSLSocketConnection.cpp +404 -0
  56. data/ext/quickfix/ThreadedSSLSocketConnection.h +189 -0
  57. data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +469 -0
  58. data/ext/quickfix/ThreadedSSLSocketInitiator.h +201 -0
  59. data/ext/quickfix/ThreadedSocketAcceptor.cpp +5 -1
  60. data/ext/quickfix/ThreadedSocketConnection.cpp +8 -2
  61. data/ext/quickfix/ThreadedSocketConnection.h +4 -1
  62. data/ext/quickfix/ThreadedSocketInitiator.cpp +24 -4
  63. data/ext/quickfix/ThreadedSocketInitiator.h +1 -1
  64. data/ext/quickfix/Utility.cpp +23 -1
  65. data/ext/quickfix/Utility.h +28 -2
  66. data/ext/quickfix/UtilitySSL.cpp +1733 -0
  67. data/ext/quickfix/UtilitySSL.h +277 -0
  68. data/ext/quickfix/config-all.h +10 -0
  69. data/ext/quickfix/dirent_windows.h +838 -0
  70. data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
  71. data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
  72. data/ext/quickfix/double-conversion/bignum.cc +766 -0
  73. data/ext/quickfix/double-conversion/bignum.h +144 -0
  74. data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
  75. data/ext/quickfix/double-conversion/cached-powers.h +64 -0
  76. data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
  77. data/ext/quickfix/double-conversion/diy-fp.h +118 -0
  78. data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
  79. data/ext/quickfix/double-conversion/double-conversion.h +543 -0
  80. data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
  81. data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
  82. data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
  83. data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
  84. data/ext/quickfix/double-conversion/ieee.h +402 -0
  85. data/ext/quickfix/double-conversion/strtod.cc +557 -0
  86. data/ext/quickfix/double-conversion/strtod.h +45 -0
  87. data/ext/quickfix/double-conversion/utils.h +372 -0
  88. data/ext/quickfix/stdint_msvc.h +254 -0
  89. data/lib/quickfix44.rb +3329 -10
  90. data/lib/quickfix50.rb +6649 -81
  91. data/lib/quickfix50sp1.rb +8054 -142
  92. data/lib/quickfix50sp2.rb +10900 -234
  93. data/lib/quickfix_fields.rb +7662 -7649
  94. data/spec/FIX40.xml +28 -28
  95. data/spec/FIX41.xml +29 -29
  96. data/spec/FIX42.xml +47 -47
  97. data/spec/FIX43.xml +148 -148
  98. data/spec/FIX44.xml +1078 -1081
  99. data/spec/FIX50.xml +1292 -1289
  100. data/spec/FIX50SP1.xml +1811 -1802
  101. data/spec/FIX50SP2.xml +1948 -1939
  102. data/spec/FIXT11.xml +5 -8
  103. data/test/test_FieldBaseTestCase.rb +1 -1
  104. data/test/test_MessageTestCase.rb +2 -2
  105. metadata +42 -6
@@ -0,0 +1,201 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 1998-2006 Ralf S. Engelschall. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following
13
+ * disclaimer in the documentation and/or other materials
14
+ * provided with the distribution.
15
+ *
16
+ * 3. All advertising materials mentioning features or use of this
17
+ * software must display the following acknowledgment:
18
+ * "This product includes software developed by
19
+ * Ralf S. Engelschall <rse@engelschall.com> for use in the
20
+ * mod_ssl project (http://www.modssl.org/)."
21
+ *
22
+ * 4. The names "mod_ssl" must not be used to endorse or promote
23
+ * products derived from this software without prior written
24
+ * permission. For written permission, please contact
25
+ * rse@engelschall.com.
26
+ *
27
+ * 5. Products derived from this software may not be called "mod_ssl"
28
+ * nor may "mod_ssl" appear in their names without prior
29
+ * written permission of Ralf S. Engelschall.
30
+ *
31
+ * 6. Redistributions of any form whatsoever must retain the following
32
+ * acknowledgment:
33
+ * "This product includes software developed by
34
+ * Ralf S. Engelschall <rse@engelschall.com> for use in the
35
+ * mod_ssl project (http://www.modssl.org/)."
36
+ *
37
+ * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
38
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR
41
+ * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
49
+ * ====================================================================
50
+ */
51
+
52
+ /* ====================================================================
53
+ * Copyright (c) 1995-1999 Ben Laurie. All rights reserved.
54
+ *
55
+ * Redistribution and use in source and binary forms, with or without
56
+ * modification, are permitted provided that the following conditions
57
+ * are met:
58
+ *
59
+ * 1. Redistributions of source code must retain the above copyright
60
+ * notice, this list of conditions and the following disclaimer.
61
+ *
62
+ * 2. Redistributions in binary form must reproduce the above copyright
63
+ * notice, this list of conditions and the following disclaimer in
64
+ * the documentation and/or other materials provided with the
65
+ * distribution.
66
+ *
67
+ * 3. All advertising materials mentioning features or use of this
68
+ * software must display the following acknowledgment:
69
+ * "This product includes software developed by Ben Laurie
70
+ * for use in the Apache-SSL HTTP server project."
71
+ *
72
+ * 4. The name "Apache-SSL Server" must not be used to
73
+ * endorse or promote products derived from this software without
74
+ * prior written permission.
75
+ *
76
+ * 5. Redistributions of any form whatsoever must retain the following
77
+ * acknowledgment:
78
+ * "This product includes software developed by Ben Laurie
79
+ * for use in the Apache-SSL HTTP server project."
80
+ *
81
+ * THIS SOFTWARE IS PROVIDED BY BEN LAURIE ``AS IS'' AND ANY
82
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
84
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEN LAURIE OR
85
+ * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
86
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
87
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
88
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
90
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
91
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
92
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
93
+ * ====================================================================
94
+ */
95
+
96
+ /* -*- C++ -*- */
97
+
98
+ /****************************************************************************
99
+ ** Copyright (c) 2001-2014
100
+ **
101
+ ** This file is part of the QuickFIX FIX Engine
102
+ **
103
+ ** This file may be distributed under the terms of the quickfixengine.org
104
+ ** license as defined by quickfixengine.org and appearing in the file
105
+ ** LICENSE included in the packaging of this file.
106
+ **
107
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
108
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
109
+ **
110
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
111
+ **
112
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
113
+ ** not clear to you.
114
+ **
115
+ ****************************************************************************/
116
+
117
+ #ifndef FIX_THREADEDSSLSOCKETINITIATOR_H
118
+ #define FIX_THREADEDSSLSOCKETINITIATOR_H
119
+
120
+ #if (HAVE_SSL > 0)
121
+
122
+ #ifdef _MSC_VER
123
+ #pragma warning(disable : 4503 4355 4786 4290)
124
+ #endif
125
+
126
+ #include "Initiator.h"
127
+ #include "ThreadedSSLSocketConnection.h"
128
+ #include <map>
129
+
130
+ namespace FIX
131
+ {
132
+ /*! \addtogroup user
133
+ * @{
134
+ */
135
+ /// Threaded Socket implementation of Initiator.
136
+ class ThreadedSSLSocketInitiator : public Initiator
137
+ {
138
+ public:
139
+ ThreadedSSLSocketInitiator(Application &, MessageStoreFactory &,
140
+ const SessionSettings &) throw(ConfigError);
141
+ ThreadedSSLSocketInitiator(Application &, MessageStoreFactory &,
142
+ const SessionSettings &,
143
+ LogFactory &) throw(ConfigError);
144
+
145
+ virtual ~ThreadedSSLSocketInitiator();
146
+
147
+ void setPassword(const std::string &pwd) { m_password.assign(pwd); }
148
+
149
+ void setCertAndKey(X509 *cert, RSA *key)
150
+ {
151
+ m_cert = cert;
152
+ m_key = key;
153
+ }
154
+
155
+ int passwordHandleCallback(char *buf, size_t bufsize, int verify, void *job);
156
+
157
+ static int passwordHandleCB(char *buf, int bufsize, int verify, void *job);
158
+
159
+ private:
160
+ typedef std::pair< int, SSL * > SocketKey;
161
+ typedef std::map< SocketKey, thread_id > SocketToThread;
162
+ typedef std::map< SessionID, int > SessionToHostNum;
163
+ typedef std::pair< ThreadedSSLSocketInitiator *,
164
+ ThreadedSSLSocketConnection * > ThreadPair;
165
+
166
+ void onConfigure(const SessionSettings &) throw(ConfigError);
167
+ void onInitialize(const SessionSettings &) throw(RuntimeError);
168
+
169
+ void onStart();
170
+ bool onPoll(double timeout);
171
+ void onStop();
172
+
173
+ void doConnect(const SessionID &s, const Dictionary &d);
174
+
175
+ void addThread(SocketKey s, thread_id t);
176
+ void removeThread(SocketKey s);
177
+ void lock() { Locker l(m_mutex); }
178
+ static THREAD_PROC socketThread(void *p);
179
+
180
+ void getHost(const SessionID &, const Dictionary &, std::string &, short &);
181
+
182
+ SessionToHostNum m_sessionToHostNum;
183
+ time_t m_lastConnect;
184
+ int m_reconnectInterval;
185
+ bool m_noDelay;
186
+ int m_sendBufSize;
187
+ int m_rcvBufSize;
188
+ SocketToThread m_threads;
189
+ Mutex m_mutex;
190
+ bool m_sslInit;
191
+ SSL_CTX *m_ctx;
192
+ std::string m_password;
193
+ X509 *m_cert;
194
+ RSA *m_key;
195
+ };
196
+ /*! @} */
197
+ }
198
+
199
+ #endif // FIX_THREADEDSOCKETINITIATOR_H
200
+
201
+ #endif
@@ -228,8 +228,12 @@ THREAD_PROC ThreadedSocketAcceptor::socketAcceptorThread( void* p )
228
228
 
229
229
  thread_id thread;
230
230
  if ( !thread_spawn( &socketConnectionThread, info, thread ) )
231
+ {
231
232
  delete info;
232
- pAcceptor->addThread( socket, thread );
233
+ delete pConnection;
234
+ }
235
+ else
236
+ pAcceptor->addThread( socket, thread );
233
237
  }
234
238
  }
235
239
 
@@ -44,8 +44,10 @@ ThreadedSocketConnection::ThreadedSocketConnection
44
44
  ThreadedSocketConnection::ThreadedSocketConnection
45
45
  ( const SessionID& sessionID, int s,
46
46
  const std::string& address, short port,
47
- Log* pLog )
47
+ Log* pLog,
48
+ const std::string& sourceAddress, short sourcePort )
48
49
  : m_socket( s ), m_address( address ), m_port( port ),
50
+ m_sourceAddress( sourceAddress ), m_sourcePort( sourcePort ),
49
51
  m_pLog( pLog ),
50
52
  m_pSession( Session::lookupSession( sessionID ) ),
51
53
  m_disconnect( false )
@@ -79,6 +81,10 @@ bool ThreadedSocketConnection::send( const std::string& msg )
79
81
 
80
82
  bool ThreadedSocketConnection::connect()
81
83
  {
84
+ // do the bind in the thread as name resolution may block
85
+ if ( !m_sourceAddress.empty() || m_sourcePort )
86
+ socket_bind( m_socket, m_sourceAddress.c_str(), m_sourcePort );
87
+
82
88
  return socket_connect(getSocket(), m_address.c_str(), m_port) >= 0;
83
89
  }
84
90
 
@@ -101,7 +107,7 @@ bool ThreadedSocketConnection::read()
101
107
  if( result > 0 ) // Something to read
102
108
  {
103
109
  // We can read without blocking
104
- ssize_t size = recv( m_socket, m_buffer, sizeof(m_buffer), 0 );
110
+ ssize_t size = socket_recv( m_socket, m_buffer, sizeof(m_buffer) );
105
111
  if ( size <= 0 ) { throw SocketRecvFailed( size ); }
106
112
  m_parser.addToStream( m_buffer, size );
107
113
  }
@@ -49,7 +49,8 @@ public:
49
49
  ThreadedSocketConnection( int s, Sessions sessions, Log* pLog );
50
50
  ThreadedSocketConnection( const SessionID&, int s,
51
51
  const std::string& address, short port,
52
- Log* pLog );
52
+ Log* pLog,
53
+ const std::string& sourceAddress = "", short sourcePort = 0);
53
54
  virtual ~ThreadedSocketConnection() ;
54
55
 
55
56
  Session* getSession() const { return m_pSession; }
@@ -69,6 +70,8 @@ private:
69
70
 
70
71
  std::string m_address;
71
72
  int m_port;
73
+ std::string m_sourceAddress;
74
+ int m_sourcePort;
72
75
 
73
76
  Log* m_pLog;
74
77
  Parser m_parser;
@@ -141,7 +141,9 @@ void ThreadedSocketInitiator::doConnect( const SessionID& s, const Dictionary& d
141
141
 
142
142
  std::string address;
143
143
  short port = 0;
144
- getHost( s, d, address, port );
144
+ std::string sourceAddress;
145
+ short sourcePort = 0;
146
+ getHost( s, d, address, port, sourceAddress, sourcePort );
145
147
 
146
148
  int socket = socket_createConnector();
147
149
  if( m_noDelay )
@@ -152,10 +154,10 @@ void ThreadedSocketInitiator::doConnect( const SessionID& s, const Dictionary& d
152
154
  socket_setsockopt( socket, SO_RCVBUF, m_rcvBufSize );
153
155
 
154
156
  setPending( s );
155
- log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) );
157
+ log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) + " (Source " + sourceAddress + ":" + IntConvertor::convert((unsigned short)sourcePort) + ")");
156
158
 
157
159
  ThreadedSocketConnection* pConnection =
158
- new ThreadedSocketConnection( s, socket, address, port, getLog() );
160
+ new ThreadedSocketConnection( s, socket, address, port, getLog(), sourceAddress, sourcePort );
159
161
 
160
162
  ThreadPair* pair = new ThreadPair( this, pConnection );
161
163
 
@@ -236,7 +238,8 @@ THREAD_PROC ThreadedSocketInitiator::socketThread( void* p )
236
238
  }
237
239
 
238
240
  void ThreadedSocketInitiator::getHost( const SessionID& s, const Dictionary& d,
239
- std::string& address, short& port )
241
+ std::string& address, short& port,
242
+ std::string& sourceAddress, short& sourcePort )
240
243
  {
241
244
  int num = 0;
242
245
  SessionToHostNum::iterator i = m_sessionToHostNum.find( s );
@@ -254,12 +257,29 @@ void ThreadedSocketInitiator::getHost( const SessionID& s, const Dictionary& d,
254
257
  {
255
258
  address = d.getString( hostString );
256
259
  port = ( short ) d.getInt( portString );
260
+
261
+ std::stringstream sourceHostStream;
262
+ sourceHostStream << SOCKET_CONNECT_SOURCE_HOST << num;
263
+ hostString = sourceHostStream.str();
264
+ if( d.has(hostString) )
265
+ sourceAddress = d.getString( hostString );
266
+
267
+ std::stringstream sourcePortStream;
268
+ sourcePortStream << SOCKET_CONNECT_SOURCE_PORT << num;
269
+ portString = sourcePortStream.str();
270
+ if( d.has(portString) )
271
+ sourcePort = ( short ) d.getInt( portString );
257
272
  }
258
273
  else
259
274
  {
260
275
  num = 0;
261
276
  address = d.getString( SOCKET_CONNECT_HOST );
262
277
  port = ( short ) d.getInt( SOCKET_CONNECT_PORT );
278
+
279
+ if( d.has(SOCKET_CONNECT_SOURCE_HOST) )
280
+ sourceAddress = d.getString( SOCKET_CONNECT_SOURCE_HOST );
281
+ if( d.has(SOCKET_CONNECT_SOURCE_PORT) )
282
+ sourcePort = ( short ) d.getInt( SOCKET_CONNECT_SOURCE_PORT );
263
283
  }
264
284
 
265
285
  m_sessionToHostNum[ s ] = ++num;
@@ -66,7 +66,7 @@ private:
66
66
  void lock() { Locker l(m_mutex); }
67
67
  static THREAD_PROC socketThread( void* p );
68
68
 
69
- void getHost( const SessionID&, const Dictionary&, std::string&, short& );
69
+ void getHost( const SessionID&, const Dictionary&, std::string&, short&, std::string&, short& );
70
70
 
71
71
  SessionSettings m_settings;
72
72
  SessionToHostNum m_sessionToHostNum;
@@ -100,6 +100,23 @@ void socket_term()
100
100
  #endif
101
101
  }
102
102
 
103
+ int socket_bind( int socket, const char* hostname, int port )
104
+ {
105
+ sockaddr_in address;
106
+ socklen_t socklen;
107
+
108
+ address.sin_family = PF_INET;
109
+ address.sin_port = htons( port );
110
+ if ( !hostname || !*hostname )
111
+ address.sin_addr.s_addr = INADDR_ANY;
112
+ else
113
+ address.sin_addr.s_addr = inet_addr( hostname );
114
+ socklen = sizeof( address );
115
+
116
+ return bind( socket, reinterpret_cast < sockaddr* > ( &address ),
117
+ socklen );
118
+ }
119
+
103
120
  int socket_createAcceptor(int port, bool reuse)
104
121
  {
105
122
  int socket = ::socket( PF_INET, SOCK_STREAM, 0 );
@@ -150,6 +167,11 @@ int socket_accept( int s )
150
167
  return accept( s, 0, 0 );
151
168
  }
152
169
 
170
+ ssize_t socket_recv( int s, char* buf, size_t length )
171
+ {
172
+ return recv( s, buf, length, 0 );
173
+ }
174
+
153
175
  ssize_t socket_send( int s, const char* msg, size_t length )
154
176
  {
155
177
  return send( s, msg, length, 0 );
@@ -396,7 +418,7 @@ bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread )
396
418
  #ifdef _MSC_VER
397
419
  thread_id result = 0;
398
420
  unsigned int id = 0;
399
- result = _beginthreadex( NULL, 0, &func, var, 0, &id );
421
+ result = _beginthreadex( NULL, 0, func, var, 0, &id );
400
422
  if ( result == 0 ) return false;
401
423
  #else
402
424
  thread_id result = 0;
@@ -74,6 +74,9 @@ typedef int ssize_t;
74
74
  #include <sys/types.h>
75
75
  #include <sys/socket.h>
76
76
  #include <sys/ioctl.h>
77
+ #if defined(__SUNPRO_CC)
78
+ #include <sys/filio.h>
79
+ #endif
77
80
  #include <sys/time.h>
78
81
  #include <sys/stat.h>
79
82
  #include <netinet/in.h>
@@ -98,11 +101,29 @@ typedef int ssize_t;
98
101
  #include <cstdlib>
99
102
  #include <memory>
100
103
 
104
+ #if !defined(HAVE_STD_UNIQUE_PTR)
105
+ #define SmartPtr std::auto_ptr
106
+ #else
107
+ #include <memory>
108
+ #define SmartPtr std::unique_ptr
109
+ #endif
110
+
101
111
  #if defined(HAVE_STD_SHARED_PTR)
102
112
  namespace ptr = std;
103
113
  #elif defined(HAVE_STD_TR1_SHARED_PTR)
104
114
  #include <tr1/memory>
105
115
  namespace ptr = std::tr1;
116
+ #elif defined(HAVE_BOOST_SHARED_PTR)
117
+ #include <boost/shared_ptr.hpp>
118
+ namespace ptr = boost;
119
+ #elif defined(__SUNPRO_CC)
120
+ #if (__SUNPRO_CC <= 0x5140)
121
+ #include "./wx/sharedptr.h"
122
+ namespace ptr = wxWidgets;
123
+ #endif
124
+ #elif defined(__TOS_AIX__)
125
+ #include <memory>
126
+ namespace ptr = std::tr1;
106
127
  #else
107
128
  namespace ptr = std;
108
129
  #endif
@@ -119,10 +140,12 @@ std::string string_strip( const std::string& value );
119
140
 
120
141
  void socket_init();
121
142
  void socket_term();
143
+ int socket_bind( int socket, const char* hostname, int port );
122
144
  int socket_createAcceptor( int port, bool reuse = false );
123
145
  int socket_createConnector();
124
146
  int socket_connect( int s, const char* address, int port );
125
147
  int socket_accept( int s );
148
+ ssize_t socket_recv( int s, char* buf, size_t length );
126
149
  ssize_t socket_send( int s, const char* msg, size_t length );
127
150
  void socket_close( int s );
128
151
  bool socket_fionread( int s, int& bytes );
@@ -150,8 +173,11 @@ std::pair<int, int> socket_createpair();
150
173
  tm time_gmtime( const time_t* t );
151
174
  tm time_localtime( const time_t* t );
152
175
 
153
- #ifdef _MSC_VER
154
- typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
176
+ #if(_MSC_VER >= 1900)
177
+ typedef _beginthreadex_proc_type THREAD_START_ROUTINE;
178
+ #define THREAD_PROC unsigned int _stdcall
179
+ #elif(_MSC_VER > 0)
180
+ typedef unsigned int (_stdcall * THREAD_START_ROUTINE)(void *);
155
181
  #define THREAD_PROC unsigned int _stdcall
156
182
  #else
157
183
  extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }