eventmachine 1.0.3-x86-mingw32 → 1.2.0.dev.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +84 -1
  3. data/README.md +6 -7
  4. data/ext/binder.cpp +10 -10
  5. data/ext/binder.h +5 -5
  6. data/ext/cmain.cpp +173 -61
  7. data/ext/ed.cpp +262 -127
  8. data/ext/ed.h +50 -30
  9. data/ext/em.cpp +491 -445
  10. data/ext/em.h +101 -36
  11. data/ext/eventmachine.h +67 -51
  12. data/ext/extconf.rb +124 -31
  13. data/ext/fastfilereader/extconf.rb +9 -2
  14. data/ext/fastfilereader/mapper.cpp +3 -1
  15. data/ext/fastfilereader/rubymain.cpp +7 -7
  16. data/ext/kb.cpp +1 -1
  17. data/ext/pipe.cpp +11 -4
  18. data/ext/project.h +26 -6
  19. data/ext/rubymain.cpp +408 -201
  20. data/ext/ssl.cpp +167 -20
  21. data/ext/ssl.h +11 -2
  22. data/java/src/com/rubyeventmachine/EmReactor.java +16 -0
  23. data/java/src/com/rubyeventmachine/EventableChannel.java +2 -0
  24. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +6 -0
  25. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +55 -10
  26. data/lib/1.9/fastfilereaderext.so +0 -0
  27. data/lib/1.9/rubyeventmachine.so +0 -0
  28. data/lib/2.0/fastfilereaderext.so +0 -0
  29. data/lib/2.0/rubyeventmachine.so +0 -0
  30. data/lib/2.1/fastfilereaderext.so +0 -0
  31. data/lib/2.1/rubyeventmachine.so +0 -0
  32. data/lib/2.2/fastfilereaderext.so +0 -0
  33. data/lib/2.2/rubyeventmachine.so +0 -0
  34. data/lib/2.3/fastfilereaderext.so +0 -0
  35. data/lib/2.3/rubyeventmachine.so +0 -0
  36. data/lib/em/buftok.rb +34 -85
  37. data/lib/em/channel.rb +5 -0
  38. data/lib/em/completion.rb +2 -2
  39. data/lib/em/connection.rb +62 -4
  40. data/lib/em/iterator.rb +30 -48
  41. data/lib/em/pool.rb +1 -1
  42. data/lib/em/protocols/httpclient.rb +31 -11
  43. data/lib/em/protocols/line_and_text.rb +4 -4
  44. data/lib/em/protocols/linetext2.rb +44 -39
  45. data/lib/em/protocols/smtpclient.rb +60 -31
  46. data/lib/em/protocols/smtpserver.rb +32 -9
  47. data/lib/em/pure_ruby.rb +8 -3
  48. data/lib/em/queue.rb +16 -7
  49. data/lib/em/resolver.rb +64 -24
  50. data/lib/em/threaded_resource.rb +2 -2
  51. data/lib/em/tick_loop.rb +19 -19
  52. data/lib/em/version.rb +1 -1
  53. data/lib/eventmachine.rb +96 -49
  54. data/lib/jeventmachine.rb +17 -0
  55. data/rakelib/package.rake +31 -4
  56. data/tests/dhparam.pem +13 -0
  57. data/tests/em_test_helper.rb +87 -0
  58. data/tests/test_attach.rb +25 -0
  59. data/tests/test_basic.rb +27 -38
  60. data/tests/test_channel.rb +14 -1
  61. data/tests/test_completion.rb +1 -0
  62. data/tests/test_connection_count.rb +22 -1
  63. data/tests/test_connection_write.rb +35 -0
  64. data/tests/test_defer.rb +17 -0
  65. data/tests/test_epoll.rb +26 -14
  66. data/tests/test_file_watch.rb +1 -0
  67. data/tests/test_fork.rb +75 -0
  68. data/tests/test_httpclient.rb +43 -0
  69. data/tests/test_idle_connection.rb +6 -4
  70. data/tests/test_ipv4.rb +125 -0
  71. data/tests/test_ipv6.rb +131 -0
  72. data/tests/test_iterator.rb +115 -0
  73. data/tests/test_kb.rb +19 -25
  74. data/tests/test_ltp2.rb +20 -0
  75. data/tests/test_many_fds.rb +22 -0
  76. data/tests/test_pause.rb +29 -0
  77. data/tests/test_pool.rb +2 -0
  78. data/tests/test_process_watch.rb +2 -0
  79. data/tests/test_processes.rb +7 -7
  80. data/tests/test_queue.rb +14 -0
  81. data/tests/test_resolver.rb +56 -7
  82. data/tests/test_set_sock_opt.rb +2 -0
  83. data/tests/test_smtpclient.rb +20 -0
  84. data/tests/test_ssl_args.rb +2 -2
  85. data/tests/test_ssl_dhparam.rb +83 -0
  86. data/tests/test_ssl_ecdh_curve.rb +79 -0
  87. data/tests/test_ssl_extensions.rb +49 -0
  88. data/tests/test_ssl_methods.rb +22 -5
  89. data/tests/test_ssl_protocols.rb +246 -0
  90. data/tests/test_ssl_verify.rb +103 -59
  91. data/tests/test_system.rb +4 -0
  92. data/tests/test_threaded_resource.rb +8 -0
  93. data/tests/test_unbind_reason.rb +5 -1
  94. metadata +173 -107
  95. data/.gitignore +0 -21
  96. data/.travis.yml +0 -12
  97. data/.yardopts +0 -7
  98. data/Gemfile +0 -2
  99. data/Rakefile +0 -20
  100. data/eventmachine.gemspec +0 -36
  101. data/rakelib/cpp.rake_example +0 -77
@@ -12,6 +12,9 @@ def add_define(name)
12
12
  $defs.push("-D#{name}")
13
13
  end
14
14
 
15
+ # Eager check devs tools
16
+ have_devel? if respond_to?(:have_devel?)
17
+
15
18
  add_define 'BUILD_FOR_RUBY'
16
19
 
17
20
  # Minor platform details between *nix and Windows:
@@ -43,7 +46,7 @@ when /mswin32/, /mingw32/, /bccwin32/
43
46
  check_libs(%w[kernel32 rpcrt4 gdi32], true)
44
47
 
45
48
  if GNU_CHAIN
46
- CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
49
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -static-libgcc -static-libstdc++"
47
50
  else
48
51
  $defs.push "-EHs"
49
52
  $defs.push "-GR"
@@ -53,13 +56,17 @@ when /solaris/
53
56
  add_define 'OS_SOLARIS8'
54
57
  check_libs(%w[nsl socket], true)
55
58
 
56
- if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
59
+ if CONFIG['CC'] == 'cc' && (
60
+ `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
61
+ `cc -V 2>&1` =~ /Sun/ # detect Solaris Studio compiler
62
+ )
57
63
  # SUN CHAIN
58
64
  add_define 'CC_SUNWspro'
59
65
  $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
60
66
  $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
61
67
  CONFIG['CCDLFLAGS'] = "-KPIC"
62
68
  CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
69
+ CONFIG['LDSHAREDXX'] = "$(CXX) -G -KPIC -lCstd"
63
70
  else
64
71
  # GNU CHAIN
65
72
  # on Unix we need a g++ link, not gcc.
@@ -89,6 +89,8 @@ void Mapper_t::Close()
89
89
  // Calls to GetChunk are invalid after a call to Close.
90
90
  if (MapPoint) {
91
91
  #ifdef CC_SUNWspro
92
+ // TODO: The void * cast works fine on Solaris 11, but
93
+ // I don't know at what point that changed from older Solaris.
92
94
  munmap ((char*)MapPoint, FileSize);
93
95
  #else
94
96
  munmap ((void*)MapPoint, FileSize);
@@ -195,7 +197,7 @@ void Mapper_t::Close()
195
197
  }
196
198
  if (hFile != INVALID_HANDLE_VALUE) {
197
199
  CloseHandle (hFile);
198
- hMapping = INVALID_HANDLE_VALUE;
200
+ hFile = INVALID_HANDLE_VALUE;
199
201
  }
200
202
  }
201
203
 
@@ -48,9 +48,9 @@ mapper_new
48
48
 
49
49
  static VALUE mapper_new (VALUE self, VALUE filename)
50
50
  {
51
- Mapper_t *m = new Mapper_t (StringValuePtr (filename));
51
+ Mapper_t *m = new Mapper_t (StringValueCStr (filename));
52
52
  if (!m)
53
- rb_raise (rb_eException, "No Mapper Object");
53
+ rb_raise (rb_eStandardError, "No Mapper Object");
54
54
  VALUE v = Data_Wrap_Struct (Mapper, 0, mapper_dt, (void*)m);
55
55
  return v;
56
56
  }
@@ -65,17 +65,17 @@ static VALUE mapper_get_chunk (VALUE self, VALUE start, VALUE length)
65
65
  Mapper_t *m = NULL;
66
66
  Data_Get_Struct (self, Mapper_t, m);
67
67
  if (!m)
68
- rb_raise (rb_eException, "No Mapper Object");
68
+ rb_raise (rb_eStandardError, "No Mapper Object");
69
69
 
70
70
  // TODO, what if some moron sends us a negative start value?
71
71
  unsigned _start = NUM2INT (start);
72
72
  unsigned _length = NUM2INT (length);
73
73
  if ((_start + _length) > m->GetFileSize())
74
- rb_raise (rb_eException, "Mapper Range Error");
74
+ rb_raise (rb_eStandardError, "Mapper Range Error");
75
75
 
76
76
  const char *chunk = m->GetChunk (_start);
77
77
  if (!chunk)
78
- rb_raise (rb_eException, "No Mapper Chunk");
78
+ rb_raise (rb_eStandardError, "No Mapper Chunk");
79
79
  return rb_str_new (chunk, _length);
80
80
  }
81
81
 
@@ -88,7 +88,7 @@ static VALUE mapper_close (VALUE self)
88
88
  Mapper_t *m = NULL;
89
89
  Data_Get_Struct (self, Mapper_t, m);
90
90
  if (!m)
91
- rb_raise (rb_eException, "No Mapper Object");
91
+ rb_raise (rb_eStandardError, "No Mapper Object");
92
92
  m->Close();
93
93
  return Qnil;
94
94
  }
@@ -102,7 +102,7 @@ static VALUE mapper_size (VALUE self)
102
102
  Mapper_t *m = NULL;
103
103
  Data_Get_Struct (self, Mapper_t, m);
104
104
  if (!m)
105
- rb_raise (rb_eException, "No Mapper Object");
105
+ rb_raise (rb_eStandardError, "No Mapper Object");
106
106
  return INT2NUM (m->GetFileSize());
107
107
  }
108
108
 
data/ext/kb.cpp CHANGED
@@ -74,6 +74,6 @@ KeyboardDescriptor::Read
74
74
  void KeyboardDescriptor::Read()
75
75
  {
76
76
  char c;
77
- read (GetSocket(), &c, 1);
77
+ (void)read (GetSocket(), &c, 1);
78
78
  _GenericInboundDispatch(&c, 1);
79
79
  }
@@ -229,6 +229,11 @@ void PipeDescriptor::Write()
229
229
 
230
230
  assert (GetSocket() != INVALID_SOCKET);
231
231
  int bytes_written = write (GetSocket(), output_buffer, nbytes);
232
+ #ifdef OS_WIN32
233
+ int e = WSAGetLastError();
234
+ #else
235
+ int e = errno;
236
+ #endif
232
237
 
233
238
  if (bytes_written > 0) {
234
239
  OutboundDataSize -= bytes_written;
@@ -242,17 +247,19 @@ void PipeDescriptor::Write()
242
247
  OutboundPages.push_front (OutboundPage (buffer, len));
243
248
  }
244
249
  #ifdef HAVE_EPOLL
245
- EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
250
+ EpollEvent.events = EPOLLIN;
251
+ if (SelectForWrite())
252
+ EpollEvent.events |= EPOLLOUT;
246
253
  assert (MyEventMachine);
247
254
  MyEventMachine->Modify (this);
248
255
  #endif
249
256
  }
250
257
  else {
251
258
  #ifdef OS_UNIX
252
- if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK) && (errno != EINTR))
259
+ if ((e != EINPROGRESS) && (e != EWOULDBLOCK) && (e != EINTR))
253
260
  #endif
254
261
  #ifdef OS_WIN32
255
- if ((errno != WSAEINPROGRESS) && (errno != WSAEWOULDBLOCK))
262
+ if ((e != WSAEINPROGRESS) && (e != WSAEWOULDBLOCK))
256
263
  #endif
257
264
  Close();
258
265
  }
@@ -305,7 +312,7 @@ bool PipeDescriptor::SelectForWrite()
305
312
  PipeDescriptor::SendOutboundData
306
313
  ********************************/
307
314
 
308
- int PipeDescriptor::SendOutboundData (const char *data, int length)
315
+ int PipeDescriptor::SendOutboundData (const char *data, unsigned long length)
309
316
  {
310
317
  //if (bCloseNow || bCloseAfterWriting)
311
318
  if (IsCloseScheduled())
@@ -22,10 +22,6 @@ See the file COPYING for complete licensing information.
22
22
  #define __Project__H_
23
23
 
24
24
 
25
- #ifdef OS_WIN32
26
- #pragma warning(disable:4786)
27
- #endif
28
-
29
25
  #include <iostream>
30
26
  #include <map>
31
27
  #include <set>
@@ -78,6 +74,11 @@ typedef int SOCKET;
78
74
  #endif
79
75
  #endif /* _AIX */
80
76
 
77
+ #ifdef OS_DARWIN
78
+ #include <mach/mach.h>
79
+ #include <mach/mach_time.h>
80
+ #endif /* OS_DARWIN */
81
+
81
82
  #endif /* OS_UNIX */
82
83
 
83
84
  #ifdef OS_WIN32
@@ -85,7 +86,9 @@ typedef int SOCKET;
85
86
  // 18Jun12: fd_setsize must be changed in the ruby binary (not in this extension). redefining it also causes segvs, see eventmachine/eventmachine#333
86
87
  //#define FD_SETSIZE 1024
87
88
 
89
+ // WIN32_LEAN_AND_MEAN excludes APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.
88
90
  #define WIN32_LEAN_AND_MEAN
91
+
89
92
  #include <windows.h>
90
93
  #include <winsock2.h>
91
94
  #include <ws2tcpip.h>
@@ -93,10 +96,21 @@ typedef int SOCKET;
93
96
  #include <fcntl.h>
94
97
  #include <assert.h>
95
98
 
96
- typedef int socklen_t;
97
- typedef int pid_t;
99
+ // Older versions of MinGW in the Ruby Dev Kit do not provide the getaddrinfo hint flags
100
+ #ifndef AI_ADDRCONFIG
101
+ #define AI_ADDRCONFIG 0x0400
98
102
  #endif
99
103
 
104
+ #ifndef AI_NUMERICSERV
105
+ #define AI_NUMERICSERV 0x0008
106
+ #endif
107
+
108
+ // Use the Win32 wrapper library that Ruby owns to be able to close sockets with the close() function
109
+ #define RUBY_EXPORT
110
+ #include <ruby/defines.h>
111
+ #include <ruby/win32.h>
112
+ #endif /* OS_WIN32 */
113
+
100
114
  #if !defined(_MSC_VER) || _MSC_VER > 1500
101
115
  #include <stdint.h>
102
116
  #endif
@@ -146,6 +160,12 @@ extern "C" {
146
160
  }
147
161
  #endif
148
162
 
163
+ #if defined(__GNUC__) && (__GNUC__ >= 3)
164
+ #define UNUSED __attribute__ ((unused))
165
+ #else
166
+ #define UNUSED
167
+ #endif
168
+
149
169
  #include "binder.h"
150
170
  #include "em.h"
151
171
  #include "ed.h"
@@ -25,6 +25,26 @@ See the file COPYING for complete licensing information.
25
25
  #define RFLOAT_VALUE(arg) RFLOAT(arg)->value
26
26
  #endif
27
27
 
28
+ /* Adapted from NUM2BSIG / BSIG2NUM in ext/fiddle/conversions.h,
29
+ * we'll call it a BSIG for Binding Signature here. */
30
+ #if SIZEOF_VOIDP == SIZEOF_LONG
31
+ # define BSIG2NUM(x) (ULONG2NUM((unsigned long)(x)))
32
+ # define NUM2BSIG(x) (NUM2ULONG(x))
33
+ # ifdef OS_WIN32
34
+ # define PRIFBSIG "I32u"
35
+ # else
36
+ # define PRIFBSIG "lu"
37
+ # endif
38
+ #else
39
+ # define BSIG2NUM(x) (ULL2NUM((unsigned long long)(x)))
40
+ # define NUM2BSIG(x) (NUM2ULL(x))
41
+ # ifdef OS_WIN32
42
+ # define PRIFBSIG "I64u"
43
+ # else
44
+ # define PRIFBSIG "llu"
45
+ # endif
46
+ #endif
47
+
28
48
  /*******
29
49
  Statics
30
50
  *******/
@@ -47,6 +67,7 @@ static VALUE Intern_event_callback;
47
67
  static VALUE Intern_run_deferred_callbacks;
48
68
  static VALUE Intern_delete;
49
69
  static VALUE Intern_call;
70
+ static VALUE Intern_at;
50
71
  static VALUE Intern_receive_data;
51
72
  static VALUE Intern_ssl_handshake_completed;
52
73
  static VALUE Intern_ssl_verify_peer;
@@ -59,17 +80,17 @@ static VALUE Intern_connection_completed;
59
80
  static VALUE rb_cProcStatus;
60
81
 
61
82
  struct em_event {
62
- unsigned long signature;
83
+ uintptr_t signature;
63
84
  int event;
64
85
  const char *data_str;
65
86
  unsigned long data_num;
66
87
  };
67
88
 
68
- static inline VALUE ensure_conn(const unsigned long signature)
89
+ static inline VALUE ensure_conn(const uintptr_t signature)
69
90
  {
70
- VALUE conn = rb_hash_aref (EmConnsHash, ULONG2NUM (signature));
91
+ VALUE conn = rb_hash_aref (EmConnsHash, BSIG2NUM (signature));
71
92
  if (conn == Qnil)
72
- rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", signature);
93
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %" PRIFBSIG, signature);
73
94
  return conn;
74
95
  }
75
96
 
@@ -80,7 +101,7 @@ t_event_callback
80
101
 
81
102
  static inline void event_callback (struct em_event* e)
82
103
  {
83
- const unsigned long signature = e->signature;
104
+ const uintptr_t signature = e->signature;
84
105
  int event = e->event;
85
106
  const char *data_str = e->data_str;
86
107
  const unsigned long data_num = e->data_num;
@@ -88,20 +109,20 @@ static inline void event_callback (struct em_event* e)
88
109
  switch (event) {
89
110
  case EM_CONNECTION_READ:
90
111
  {
91
- VALUE conn = rb_hash_aref (EmConnsHash, ULONG2NUM (signature));
112
+ VALUE conn = rb_hash_aref (EmConnsHash, BSIG2NUM (signature));
92
113
  if (conn == Qnil)
93
- rb_raise (EM_eConnectionNotBound, "received %lu bytes of data for unknown signature: %lu", data_num, signature);
114
+ rb_raise (EM_eConnectionNotBound, "received %lu bytes of data for unknown signature: %" PRIFBSIG, data_num, signature);
94
115
  rb_funcall (conn, Intern_receive_data, 1, rb_str_new (data_str, data_num));
95
116
  return;
96
117
  }
97
118
  case EM_CONNECTION_ACCEPTED:
98
119
  {
99
- rb_funcall (EmModule, Intern_event_callback, 3, ULONG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
120
+ rb_funcall (EmModule, Intern_event_callback, 3, BSIG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
100
121
  return;
101
122
  }
102
123
  case EM_CONNECTION_UNBOUND:
103
124
  {
104
- rb_funcall (EmModule, Intern_event_callback, 3, ULONG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
125
+ rb_funcall (EmModule, Intern_event_callback, 3, BSIG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
105
126
  return;
106
127
  }
107
128
  case EM_CONNECTION_COMPLETED:
@@ -174,7 +195,7 @@ static inline void event_callback (struct em_event* e)
174
195
  event_error_handler
175
196
  *******************/
176
197
 
177
- static void event_error_handler(VALUE unused, VALUE err)
198
+ static void event_error_handler(VALUE self UNUSED, VALUE err)
178
199
  {
179
200
  VALUE error_handler = rb_ivar_get(EmModule, Intern_at_error_handler);
180
201
  rb_funcall (error_handler, Intern_call, 1, err);
@@ -184,7 +205,7 @@ static void event_error_handler(VALUE unused, VALUE err)
184
205
  event_callback_wrapper
185
206
  **********************/
186
207
 
187
- static void event_callback_wrapper (const unsigned long signature, int event, const char *data_str, const unsigned long data_num)
208
+ static void event_callback_wrapper (const uintptr_t signature, int event, const char *data_str, const unsigned long data_num)
188
209
  {
189
210
  struct em_event e;
190
211
  e.signature = signature;
@@ -202,7 +223,7 @@ static void event_callback_wrapper (const unsigned long signature, int event, co
202
223
  t_initialize_event_machine
203
224
  **************************/
204
225
 
205
- static VALUE t_initialize_event_machine (VALUE self)
226
+ static VALUE t_initialize_event_machine (VALUE self UNUSED)
206
227
  {
207
228
  EmConnsHash = rb_ivar_get (EmModule, Intern_at_conns);
208
229
  EmTimersHash = rb_ivar_get (EmModule, Intern_at_timers);
@@ -213,12 +234,21 @@ static VALUE t_initialize_event_machine (VALUE self)
213
234
  }
214
235
 
215
236
 
237
+ /******************
238
+ t_run_machine_once
239
+ ******************/
216
240
 
217
- /*****************************
218
- t_run_machine_without_threads
219
- *****************************/
241
+ static VALUE t_run_machine_once (VALUE self UNUSED)
242
+ {
243
+ return evma_run_machine_once () ? Qtrue : Qfalse;
244
+ }
220
245
 
221
- static VALUE t_run_machine_without_threads (VALUE self)
246
+
247
+ /*************
248
+ t_run_machine
249
+ *************/
250
+
251
+ static VALUE t_run_machine (VALUE self UNUSED)
222
252
  {
223
253
  evma_run_machine();
224
254
  return Qnil;
@@ -229,12 +259,12 @@ static VALUE t_run_machine_without_threads (VALUE self)
229
259
  t_add_oneshot_timer
230
260
  *******************/
231
261
 
232
- static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
262
+ static VALUE t_add_oneshot_timer (VALUE self UNUSED, VALUE interval)
233
263
  {
234
- const unsigned long f = evma_install_oneshot_timer (FIX2INT (interval));
264
+ const uintptr_t f = evma_install_oneshot_timer (FIX2INT (interval));
235
265
  if (!f)
236
266
  rb_raise (rb_eRuntimeError, "%s", "ran out of timers; use #set_max_timers to increase limit");
237
- return ULONG2NUM (f);
267
+ return BSIG2NUM (f);
238
268
  }
239
269
 
240
270
 
@@ -242,21 +272,21 @@ static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
242
272
  t_start_server
243
273
  **************/
244
274
 
245
- static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
275
+ static VALUE t_start_server (VALUE self UNUSED, VALUE server, VALUE port)
246
276
  {
247
- const unsigned long f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
277
+ const uintptr_t f = evma_create_tcp_server (StringValueCStr(server), FIX2INT(port));
248
278
  if (!f)
249
279
  rb_raise (rb_eRuntimeError, "%s", "no acceptor (port is in use or requires root privileges)");
250
- return ULONG2NUM (f);
280
+ return BSIG2NUM (f);
251
281
  }
252
282
 
253
283
  /*************
254
284
  t_stop_server
255
285
  *************/
256
286
 
257
- static VALUE t_stop_server (VALUE self, VALUE signature)
287
+ static VALUE t_stop_server (VALUE self UNUSED, VALUE signature)
258
288
  {
259
- evma_stop_tcp_server (NUM2ULONG (signature));
289
+ evma_stop_tcp_server (NUM2BSIG (signature));
260
290
  return Qnil;
261
291
  }
262
292
 
@@ -265,23 +295,34 @@ static VALUE t_stop_server (VALUE self, VALUE signature)
265
295
  t_start_unix_server
266
296
  *******************/
267
297
 
268
- static VALUE t_start_unix_server (VALUE self, VALUE filename)
298
+ static VALUE t_start_unix_server (VALUE self UNUSED, VALUE filename)
269
299
  {
270
- const unsigned long f = evma_create_unix_domain_server (StringValuePtr(filename));
300
+ const uintptr_t f = evma_create_unix_domain_server (StringValueCStr(filename));
271
301
  if (!f)
272
302
  rb_raise (rb_eRuntimeError, "%s", "no unix-domain acceptor");
273
- return ULONG2NUM (f);
303
+ return BSIG2NUM (f);
274
304
  }
275
305
 
306
+ /********************
307
+ t_attach_sd
308
+ ********************/
309
+
310
+ static VALUE t_attach_sd(VALUE self UNUSED, VALUE sd)
311
+ {
312
+ const uintptr_t f = evma_attach_sd(FIX2INT(sd));
313
+ if (!f)
314
+ rb_raise (rb_eRuntimeError, "%s", "no socket descriptor acceptor");
315
+ return BSIG2NUM (f);
316
+ }
276
317
 
277
318
 
278
319
  /***********
279
320
  t_send_data
280
321
  ***********/
281
322
 
282
- static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_length)
323
+ static VALUE t_send_data (VALUE self UNUSED, VALUE signature, VALUE data, VALUE data_length)
283
324
  {
284
- int b = evma_send_data_to_connection (NUM2ULONG (signature), StringValuePtr (data), FIX2INT (data_length));
325
+ int b = evma_send_data_to_connection (NUM2BSIG (signature), StringValuePtr (data), FIX2INT (data_length));
285
326
  return INT2NUM (b);
286
327
  }
287
328
 
@@ -290,9 +331,9 @@ static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_le
290
331
  t_start_tls
291
332
  ***********/
292
333
 
293
- static VALUE t_start_tls (VALUE self, VALUE signature)
334
+ static VALUE t_start_tls (VALUE self UNUSED, VALUE signature)
294
335
  {
295
- evma_start_tls (NUM2ULONG (signature));
336
+ evma_start_tls (NUM2BSIG (signature));
296
337
  return Qnil;
297
338
  }
298
339
 
@@ -300,14 +341,14 @@ static VALUE t_start_tls (VALUE self, VALUE signature)
300
341
  t_set_tls_parms
301
342
  ***************/
302
343
 
303
- static VALUE t_set_tls_parms (VALUE self, VALUE signature, VALUE privkeyfile, VALUE certchainfile, VALUE verify_peer)
344
+ static VALUE t_set_tls_parms (VALUE self UNUSED, VALUE signature, VALUE privkeyfile, VALUE certchainfile, VALUE verify_peer, VALUE fail_if_no_peer_cert, VALUE snihostname, VALUE cipherlist, VALUE ecdh_curve, VALUE dhparam, VALUE ssl_version)
304
345
  {
305
346
  /* set_tls_parms takes a series of positional arguments for specifying such things
306
347
  * as private keys and certificate chains.
307
348
  * It's expected that the parameter list will grow as we add more supported features.
308
349
  * ALL of these parameters are optional, and can be specified as empty or NULL strings.
309
350
  */
310
- evma_set_tls_parms (NUM2ULONG (signature), StringValuePtr (privkeyfile), StringValuePtr (certchainfile), (verify_peer == Qtrue ? 1 : 0));
351
+ evma_set_tls_parms (NUM2BSIG (signature), StringValueCStr (privkeyfile), StringValueCStr (certchainfile), (verify_peer == Qtrue ? 1 : 0), (fail_if_no_peer_cert == Qtrue ? 1 : 0), StringValueCStr (snihostname), StringValueCStr (cipherlist), StringValueCStr (ecdh_curve), StringValueCStr (dhparam), NUM2INT (ssl_version));
311
352
  return Qnil;
312
353
  }
313
354
 
@@ -315,16 +356,16 @@ static VALUE t_set_tls_parms (VALUE self, VALUE signature, VALUE privkeyfile, VA
315
356
  t_get_peer_cert
316
357
  ***************/
317
358
 
318
- static VALUE t_get_peer_cert (VALUE self, VALUE signature)
359
+ #ifdef WITH_SSL
360
+ static VALUE t_get_peer_cert (VALUE self UNUSED, VALUE signature)
319
361
  {
320
362
  VALUE ret = Qnil;
321
363
 
322
- #ifdef WITH_SSL
323
364
  X509 *cert = NULL;
324
365
  BUF_MEM *buf;
325
366
  BIO *out;
326
367
 
327
- cert = evma_get_peer_cert (NUM2ULONG (signature));
368
+ cert = evma_get_peer_cert (NUM2BSIG (signature));
328
369
 
329
370
  if (cert != NULL) {
330
371
  out = BIO_new(BIO_s_mem());
@@ -334,20 +375,104 @@ static VALUE t_get_peer_cert (VALUE self, VALUE signature)
334
375
  X509_free(cert);
335
376
  BIO_free(out);
336
377
  }
337
- #endif
338
378
 
339
379
  return ret;
340
380
  }
381
+ #else
382
+ static VALUE t_get_peer_cert (VALUE self UNUSED, VALUE signature UNUSED)
383
+ {
384
+ return Qnil;
385
+ }
386
+ #endif
387
+
388
+ /***************
389
+ t_get_cipher_bits
390
+ ***************/
391
+
392
+ #ifdef WITH_SSL
393
+ static VALUE t_get_cipher_bits (VALUE self UNUSED, VALUE signature)
394
+ {
395
+ int bits = evma_get_cipher_bits (NUM2BSIG (signature));
396
+ if (bits == -1)
397
+ return Qnil;
398
+ return INT2NUM (bits);
399
+ }
400
+ #else
401
+ static VALUE t_get_cipher_bits (VALUE self UNUSED, VALUE signature UNUSED)
402
+ {
403
+ return Qnil;
404
+ }
405
+ #endif
406
+
407
+ /***************
408
+ t_get_cipher_name
409
+ ***************/
410
+
411
+ #ifdef WITH_SSL
412
+ static VALUE t_get_cipher_name (VALUE self UNUSED, VALUE signature)
413
+ {
414
+ const char *protocol = evma_get_cipher_name (NUM2BSIG (signature));
415
+ if (protocol)
416
+ return rb_str_new2 (protocol);
417
+
418
+ return Qnil;
419
+ }
420
+ #else
421
+ static VALUE t_get_cipher_name (VALUE self UNUSED, VALUE signature UNUSED)
422
+ {
423
+ return Qnil;
424
+ }
425
+ #endif
426
+
427
+ /***************
428
+ t_get_cipher_protocol
429
+ ***************/
430
+
431
+ #ifdef WITH_SSL
432
+ static VALUE t_get_cipher_protocol (VALUE self UNUSED, VALUE signature)
433
+ {
434
+ const char *cipher = evma_get_cipher_protocol (NUM2BSIG (signature));
435
+ if (cipher)
436
+ return rb_str_new2 (cipher);
437
+
438
+ return Qnil;
439
+ }
440
+ #else
441
+ static VALUE t_get_cipher_protocol (VALUE self UNUSED, VALUE signature UNUSED)
442
+ {
443
+ return Qnil;
444
+ }
445
+ #endif
446
+
447
+ /***************
448
+ t_get_sni_hostname
449
+ ***************/
450
+
451
+ #ifdef WITH_SSL
452
+ static VALUE t_get_sni_hostname (VALUE self UNUSED, VALUE signature)
453
+ {
454
+ const char *sni_hostname = evma_get_sni_hostname (NUM2BSIG (signature));
455
+ if (sni_hostname)
456
+ return rb_str_new2 (sni_hostname);
457
+
458
+ return Qnil;
459
+ }
460
+ #else
461
+ static VALUE t_get_sni_hostname (VALUE self UNUSED, VALUE signature UNUSED)
462
+ {
463
+ return Qnil;
464
+ }
465
+ #endif
341
466
 
342
467
  /**************
343
468
  t_get_peername
344
469
  **************/
345
470
 
346
- static VALUE t_get_peername (VALUE self, VALUE signature)
471
+ static VALUE t_get_peername (VALUE self UNUSED, VALUE signature)
347
472
  {
348
473
  char buf[1024];
349
474
  socklen_t len = sizeof buf;
350
- if (evma_get_peername (NUM2ULONG (signature), (struct sockaddr*)buf, &len)) {
475
+ if (evma_get_peername (NUM2BSIG (signature), (struct sockaddr*)buf, &len)) {
351
476
  return rb_str_new (buf, len);
352
477
  }
353
478
 
@@ -358,11 +483,11 @@ static VALUE t_get_peername (VALUE self, VALUE signature)
358
483
  t_get_sockname
359
484
  **************/
360
485
 
361
- static VALUE t_get_sockname (VALUE self, VALUE signature)
486
+ static VALUE t_get_sockname (VALUE self UNUSED, VALUE signature)
362
487
  {
363
488
  char buf[1024];
364
489
  socklen_t len = sizeof buf;
365
- if (evma_get_sockname (NUM2ULONG (signature), (struct sockaddr*)buf, &len)) {
490
+ if (evma_get_sockname (NUM2BSIG (signature), (struct sockaddr*)buf, &len)) {
366
491
  return rb_str_new (buf, len);
367
492
  }
368
493
 
@@ -373,10 +498,10 @@ static VALUE t_get_sockname (VALUE self, VALUE signature)
373
498
  t_get_subprocess_pid
374
499
  ********************/
375
500
 
376
- static VALUE t_get_subprocess_pid (VALUE self, VALUE signature)
501
+ static VALUE t_get_subprocess_pid (VALUE self UNUSED, VALUE signature)
377
502
  {
378
503
  pid_t pid;
379
- if (evma_get_subprocess_pid (NUM2ULONG (signature), &pid)) {
504
+ if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
380
505
  return INT2NUM (pid);
381
506
  }
382
507
 
@@ -387,18 +512,32 @@ static VALUE t_get_subprocess_pid (VALUE self, VALUE signature)
387
512
  t_get_subprocess_status
388
513
  ***********************/
389
514
 
390
- static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
515
+ static VALUE t_get_subprocess_status (VALUE self UNUSED, VALUE signature)
391
516
  {
392
517
  VALUE proc_status = Qnil;
393
518
 
394
519
  int status;
395
520
  pid_t pid;
396
521
 
397
- if (evma_get_subprocess_status (NUM2ULONG (signature), &status)) {
398
- if (evma_get_subprocess_pid (NUM2ULONG (signature), &pid)) {
522
+ if (evma_get_subprocess_status (NUM2BSIG (signature), &status)) {
523
+ if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
399
524
  proc_status = rb_obj_alloc(rb_cProcStatus);
525
+
526
+ /* MRI Ruby uses hidden instance vars */
400
527
  rb_iv_set(proc_status, "status", INT2FIX(status));
401
528
  rb_iv_set(proc_status, "pid", INT2FIX(pid));
529
+
530
+ #ifdef RUBINIUS
531
+ /* Rubinius uses standard instance vars */
532
+ rb_iv_set(proc_status, "@pid", INT2FIX(pid));
533
+ if (WIFEXITED(status)) {
534
+ rb_iv_set(proc_status, "@status", INT2FIX(WEXITSTATUS(status)));
535
+ } else if (WIFSIGNALED(status)) {
536
+ rb_iv_set(proc_status, "@termsig", INT2FIX(WTERMSIG(status)));
537
+ } else if (WIFSTOPPED(status)){
538
+ rb_iv_set(proc_status, "@stopsig", INT2FIX(WSTOPSIG(status)));
539
+ }
540
+ #endif
402
541
  }
403
542
  }
404
543
 
@@ -409,7 +548,7 @@ static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
409
548
  t_get_connection_count
410
549
  **********************/
411
550
 
412
- static VALUE t_get_connection_count (VALUE self)
551
+ static VALUE t_get_connection_count (VALUE self UNUSED)
413
552
  {
414
553
  return INT2NUM(evma_get_connection_count());
415
554
  }
@@ -418,19 +557,19 @@ static VALUE t_get_connection_count (VALUE self)
418
557
  t_get_comm_inactivity_timeout
419
558
  *****************************/
420
559
 
421
- static VALUE t_get_comm_inactivity_timeout (VALUE self, VALUE signature)
560
+ static VALUE t_get_comm_inactivity_timeout (VALUE self UNUSED, VALUE signature)
422
561
  {
423
- return rb_float_new(evma_get_comm_inactivity_timeout(NUM2ULONG (signature)));
562
+ return rb_float_new(evma_get_comm_inactivity_timeout(NUM2BSIG (signature)));
424
563
  }
425
564
 
426
565
  /*****************************
427
566
  t_set_comm_inactivity_timeout
428
567
  *****************************/
429
568
 
430
- static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
569
+ static VALUE t_set_comm_inactivity_timeout (VALUE self UNUSED, VALUE signature, VALUE timeout)
431
570
  {
432
571
  float ti = RFLOAT_VALUE(timeout);
433
- if (evma_set_comm_inactivity_timeout(NUM2ULONG(signature), ti)) {
572
+ if (evma_set_comm_inactivity_timeout(NUM2BSIG(signature), ti)) {
434
573
  return Qtrue;
435
574
  }
436
575
  return Qfalse;
@@ -440,19 +579,19 @@ static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE t
440
579
  t_get_pending_connect_timeout
441
580
  *****************************/
442
581
 
443
- static VALUE t_get_pending_connect_timeout (VALUE self, VALUE signature)
582
+ static VALUE t_get_pending_connect_timeout (VALUE self UNUSED, VALUE signature)
444
583
  {
445
- return rb_float_new(evma_get_pending_connect_timeout(NUM2ULONG (signature)));
584
+ return rb_float_new(evma_get_pending_connect_timeout(NUM2BSIG (signature)));
446
585
  }
447
586
 
448
587
  /*****************************
449
588
  t_set_pending_connect_timeout
450
589
  *****************************/
451
590
 
452
- static VALUE t_set_pending_connect_timeout (VALUE self, VALUE signature, VALUE timeout)
591
+ static VALUE t_set_pending_connect_timeout (VALUE self UNUSED, VALUE signature, VALUE timeout)
453
592
  {
454
593
  float ti = RFLOAT_VALUE(timeout);
455
- if (evma_set_pending_connect_timeout(NUM2ULONG(signature), ti)) {
594
+ if (evma_set_pending_connect_timeout(NUM2BSIG(signature), ti)) {
456
595
  return Qtrue;
457
596
  }
458
597
  return Qfalse;
@@ -462,9 +601,11 @@ static VALUE t_set_pending_connect_timeout (VALUE self, VALUE signature, VALUE t
462
601
  t_send_datagram
463
602
  ***************/
464
603
 
465
- static VALUE t_send_datagram (VALUE self, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
604
+ static VALUE t_send_datagram (VALUE self UNUSED, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
466
605
  {
467
- int b = evma_send_datagram (NUM2ULONG (signature), StringValuePtr (data), FIX2INT (data_length), StringValuePtr(address), FIX2INT(port));
606
+ int b = evma_send_datagram (NUM2BSIG (signature), StringValuePtr (data), FIX2INT (data_length), StringValueCStr(address), FIX2INT(port));
607
+ if (b < 0)
608
+ rb_raise (EM_eConnectionError, "%s", "error in sending datagram"); // FIXME: this could be more specific.
468
609
  return INT2NUM (b);
469
610
  }
470
611
 
@@ -473,9 +614,9 @@ static VALUE t_send_datagram (VALUE self, VALUE signature, VALUE data, VALUE dat
473
614
  t_close_connection
474
615
  ******************/
475
616
 
476
- static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writing)
617
+ static VALUE t_close_connection (VALUE self UNUSED, VALUE signature, VALUE after_writing)
477
618
  {
478
- evma_close_connection (NUM2ULONG (signature), ((after_writing == Qtrue) ? 1 : 0));
619
+ evma_close_connection (NUM2BSIG (signature), ((after_writing == Qtrue) ? 1 : 0));
479
620
  return Qnil;
480
621
  }
481
622
 
@@ -483,9 +624,9 @@ static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writin
483
624
  t_report_connection_error_status
484
625
  ********************************/
485
626
 
486
- static VALUE t_report_connection_error_status (VALUE self, VALUE signature)
627
+ static VALUE t_report_connection_error_status (VALUE self UNUSED, VALUE signature)
487
628
  {
488
- int b = evma_report_connection_error_status (NUM2ULONG (signature));
629
+ int b = evma_report_connection_error_status (NUM2BSIG (signature));
489
630
  return INT2NUM (b);
490
631
  }
491
632
 
@@ -495,17 +636,17 @@ static VALUE t_report_connection_error_status (VALUE self, VALUE signature)
495
636
  t_connect_server
496
637
  ****************/
497
638
 
498
- static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
639
+ static VALUE t_connect_server (VALUE self UNUSED, VALUE server, VALUE port)
499
640
  {
500
641
  // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
501
642
  // Specifically, if the value of port comes in as a string rather than an integer,
502
643
  // NUM2INT will throw a type error, but FIX2INT will generate garbage.
503
644
 
504
645
  try {
505
- const unsigned long f = evma_connect_to_server (NULL, 0, StringValuePtr(server), NUM2INT(port));
646
+ const uintptr_t f = evma_connect_to_server (NULL, 0, StringValueCStr(server), NUM2INT(port));
506
647
  if (!f)
507
648
  rb_raise (EM_eConnectionError, "%s", "no connection");
508
- return ULONG2NUM (f);
649
+ return BSIG2NUM (f);
509
650
  } catch (std::runtime_error e) {
510
651
  rb_raise (EM_eConnectionError, "%s", e.what());
511
652
  }
@@ -516,17 +657,17 @@ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
516
657
  t_bind_connect_server
517
658
  *********************/
518
659
 
519
- static VALUE t_bind_connect_server (VALUE self, VALUE bind_addr, VALUE bind_port, VALUE server, VALUE port)
660
+ static VALUE t_bind_connect_server (VALUE self UNUSED, VALUE bind_addr, VALUE bind_port, VALUE server, VALUE port)
520
661
  {
521
662
  // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
522
663
  // Specifically, if the value of port comes in as a string rather than an integer,
523
664
  // NUM2INT will throw a type error, but FIX2INT will generate garbage.
524
665
 
525
666
  try {
526
- const unsigned long f = evma_connect_to_server (StringValuePtr(bind_addr), NUM2INT(bind_port), StringValuePtr(server), NUM2INT(port));
667
+ const uintptr_t f = evma_connect_to_server (StringValueCStr(bind_addr), NUM2INT(bind_port), StringValueCStr(server), NUM2INT(port));
527
668
  if (!f)
528
669
  rb_raise (EM_eConnectionError, "%s", "no connection");
529
- return ULONG2NUM (f);
670
+ return BSIG2NUM (f);
530
671
  } catch (std::runtime_error e) {
531
672
  rb_raise (EM_eConnectionError, "%s", e.what());
532
673
  }
@@ -537,42 +678,50 @@ static VALUE t_bind_connect_server (VALUE self, VALUE bind_addr, VALUE bind_port
537
678
  t_connect_unix_server
538
679
  *********************/
539
680
 
540
- static VALUE t_connect_unix_server (VALUE self, VALUE serversocket)
681
+ static VALUE t_connect_unix_server (VALUE self UNUSED, VALUE serversocket)
541
682
  {
542
- const unsigned long f = evma_connect_to_unix_server (StringValuePtr(serversocket));
683
+ const uintptr_t f = evma_connect_to_unix_server (StringValueCStr(serversocket));
543
684
  if (!f)
544
685
  rb_raise (rb_eRuntimeError, "%s", "no connection");
545
- return ULONG2NUM (f);
686
+ return BSIG2NUM (f);
546
687
  }
547
688
 
548
689
  /***********
549
690
  t_attach_fd
550
691
  ***********/
551
692
 
552
- static VALUE t_attach_fd (VALUE self, VALUE file_descriptor, VALUE watch_mode)
693
+ static VALUE t_attach_fd (VALUE self UNUSED, VALUE file_descriptor, VALUE watch_mode)
553
694
  {
554
- const unsigned long f = evma_attach_fd (NUM2INT(file_descriptor), watch_mode == Qtrue);
695
+ const uintptr_t f = evma_attach_fd (NUM2INT(file_descriptor), watch_mode == Qtrue);
555
696
  if (!f)
556
697
  rb_raise (rb_eRuntimeError, "%s", "no connection");
557
- return ULONG2NUM (f);
698
+ return BSIG2NUM (f);
558
699
  }
559
700
 
560
701
  /***********
561
702
  t_detach_fd
562
703
  ***********/
563
704
 
564
- static VALUE t_detach_fd (VALUE self, VALUE signature)
705
+ static VALUE t_detach_fd (VALUE self UNUSED, VALUE signature)
706
+ {
707
+ return INT2NUM(evma_detach_fd (NUM2BSIG (signature)));
708
+ }
709
+
710
+ /*********************
711
+ t_get_file_descriptor
712
+ *********************/
713
+ static VALUE t_get_file_descriptor (VALUE self UNUSED, VALUE signature)
565
714
  {
566
- return INT2NUM(evma_detach_fd (NUM2ULONG (signature)));
715
+ return INT2NUM(evma_get_file_descriptor (NUM2BSIG (signature)));
567
716
  }
568
717
 
569
718
  /**************
570
719
  t_get_sock_opt
571
720
  **************/
572
721
 
573
- static VALUE t_get_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optname)
722
+ static VALUE t_get_sock_opt (VALUE self UNUSED, VALUE signature, VALUE lev, VALUE optname)
574
723
  {
575
- int fd = evma_get_file_descriptor (NUM2ULONG (signature));
724
+ int fd = evma_get_file_descriptor (NUM2BSIG (signature));
576
725
  int level = NUM2INT(lev), option = NUM2INT(optname);
577
726
  socklen_t len = 128;
578
727
  char buf[128];
@@ -587,12 +736,12 @@ static VALUE t_get_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optna
587
736
  t_set_sock_opt
588
737
  **************/
589
738
 
590
- static VALUE t_set_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optname, VALUE optval)
739
+ static VALUE t_set_sock_opt (VALUE self UNUSED, VALUE signature, VALUE lev, VALUE optname, VALUE optval)
591
740
  {
592
- int fd = evma_get_file_descriptor (NUM2ULONG (signature));
741
+ int fd = evma_get_file_descriptor (NUM2BSIG (signature));
593
742
  int level = NUM2INT(lev), option = NUM2INT(optname);
594
743
  int i;
595
- void *v;
744
+ const void *v;
596
745
  socklen_t len;
597
746
 
598
747
  switch (TYPE(optval)) {
@@ -625,18 +774,18 @@ static VALUE t_set_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optna
625
774
  t_is_notify_readable
626
775
  ********************/
627
776
 
628
- static VALUE t_is_notify_readable (VALUE self, VALUE signature)
777
+ static VALUE t_is_notify_readable (VALUE self UNUSED, VALUE signature)
629
778
  {
630
- return evma_is_notify_readable(NUM2ULONG (signature)) ? Qtrue : Qfalse;
779
+ return evma_is_notify_readable(NUM2BSIG (signature)) ? Qtrue : Qfalse;
631
780
  }
632
781
 
633
782
  /*********************
634
783
  t_set_notify_readable
635
784
  *********************/
636
785
 
637
- static VALUE t_set_notify_readable (VALUE self, VALUE signature, VALUE mode)
786
+ static VALUE t_set_notify_readable (VALUE self UNUSED, VALUE signature, VALUE mode)
638
787
  {
639
- evma_set_notify_readable(NUM2ULONG (signature), mode == Qtrue);
788
+ evma_set_notify_readable(NUM2BSIG(signature), mode == Qtrue);
640
789
  return Qnil;
641
790
  }
642
791
 
@@ -644,18 +793,18 @@ static VALUE t_set_notify_readable (VALUE self, VALUE signature, VALUE mode)
644
793
  t_is_notify_readable
645
794
  ********************/
646
795
 
647
- static VALUE t_is_notify_writable (VALUE self, VALUE signature)
796
+ static VALUE t_is_notify_writable (VALUE self UNUSED, VALUE signature)
648
797
  {
649
- return evma_is_notify_writable(NUM2ULONG (signature)) ? Qtrue : Qfalse;
798
+ return evma_is_notify_writable(NUM2BSIG (signature)) ? Qtrue : Qfalse;
650
799
  }
651
800
 
652
801
  /*********************
653
802
  t_set_notify_writable
654
803
  *********************/
655
804
 
656
- static VALUE t_set_notify_writable (VALUE self, VALUE signature, VALUE mode)
805
+ static VALUE t_set_notify_writable (VALUE self UNUSED, VALUE signature, VALUE mode)
657
806
  {
658
- evma_set_notify_writable(NUM2ULONG (signature), mode == Qtrue);
807
+ evma_set_notify_writable(NUM2BSIG (signature), mode == Qtrue);
659
808
  return Qnil;
660
809
  }
661
810
 
@@ -663,34 +812,34 @@ static VALUE t_set_notify_writable (VALUE self, VALUE signature, VALUE mode)
663
812
  t_pause
664
813
  *******/
665
814
 
666
- static VALUE t_pause (VALUE self, VALUE signature)
815
+ static VALUE t_pause (VALUE self UNUSED, VALUE signature)
667
816
  {
668
- return evma_pause(NUM2ULONG (signature)) ? Qtrue : Qfalse;
817
+ return evma_pause(NUM2BSIG (signature)) ? Qtrue : Qfalse;
669
818
  }
670
819
 
671
820
  /********
672
821
  t_resume
673
822
  ********/
674
823
 
675
- static VALUE t_resume (VALUE self, VALUE signature)
824
+ static VALUE t_resume (VALUE self UNUSED, VALUE signature)
676
825
  {
677
- return evma_resume(NUM2ULONG (signature)) ? Qtrue : Qfalse;
826
+ return evma_resume(NUM2BSIG (signature)) ? Qtrue : Qfalse;
678
827
  }
679
828
 
680
829
  /**********
681
830
  t_paused_p
682
831
  **********/
683
832
 
684
- static VALUE t_paused_p (VALUE self, VALUE signature)
833
+ static VALUE t_paused_p (VALUE self UNUSED, VALUE signature)
685
834
  {
686
- return evma_is_paused(NUM2ULONG (signature)) ? Qtrue : Qfalse;
835
+ return evma_is_paused(NUM2BSIG (signature)) ? Qtrue : Qfalse;
687
836
  }
688
837
 
689
838
  /*********************
690
839
  t_num_close_scheduled
691
840
  *********************/
692
841
 
693
- static VALUE t_num_close_scheduled (VALUE self)
842
+ static VALUE t_num_close_scheduled (VALUE self UNUSED)
694
843
  {
695
844
  return INT2FIX(evma_num_close_scheduled());
696
845
  }
@@ -699,12 +848,12 @@ static VALUE t_num_close_scheduled (VALUE self)
699
848
  t_open_udp_socket
700
849
  *****************/
701
850
 
702
- static VALUE t_open_udp_socket (VALUE self, VALUE server, VALUE port)
851
+ static VALUE t_open_udp_socket (VALUE self UNUSED, VALUE server, VALUE port)
703
852
  {
704
- const unsigned long f = evma_open_datagram_socket (StringValuePtr(server), FIX2INT(port));
853
+ const uintptr_t f = evma_open_datagram_socket (StringValueCStr(server), FIX2INT(port));
705
854
  if (!f)
706
855
  rb_raise (rb_eRuntimeError, "%s", "no datagram socket");
707
- return ULONG2NUM (f);
856
+ return BSIG2NUM(f);
708
857
  }
709
858
 
710
859
 
@@ -713,7 +862,7 @@ static VALUE t_open_udp_socket (VALUE self, VALUE server, VALUE port)
713
862
  t_release_machine
714
863
  *****************/
715
864
 
716
- static VALUE t_release_machine (VALUE self)
865
+ static VALUE t_release_machine (VALUE self UNUSED)
717
866
  {
718
867
  evma_release_library();
719
868
  return Qnil;
@@ -724,7 +873,7 @@ static VALUE t_release_machine (VALUE self)
724
873
  t_stop
725
874
  ******/
726
875
 
727
- static VALUE t_stop (VALUE self)
876
+ static VALUE t_stop (VALUE self UNUSED)
728
877
  {
729
878
  evma_stop_machine();
730
879
  return Qnil;
@@ -734,7 +883,7 @@ static VALUE t_stop (VALUE self)
734
883
  t_signal_loopbreak
735
884
  ******************/
736
885
 
737
- static VALUE t_signal_loopbreak (VALUE self)
886
+ static VALUE t_signal_loopbreak (VALUE self UNUSED)
738
887
  {
739
888
  evma_signal_loopbreak();
740
889
  return Qnil;
@@ -744,7 +893,7 @@ static VALUE t_signal_loopbreak (VALUE self)
744
893
  t_library_type
745
894
  **************/
746
895
 
747
- static VALUE t_library_type (VALUE self)
896
+ static VALUE t_library_type (VALUE self UNUSED)
748
897
  {
749
898
  return rb_eval_string (":extension");
750
899
  }
@@ -755,39 +904,54 @@ static VALUE t_library_type (VALUE self)
755
904
  t_set_timer_quantum
756
905
  *******************/
757
906
 
758
- static VALUE t_set_timer_quantum (VALUE self, VALUE interval)
907
+ static VALUE t_set_timer_quantum (VALUE self UNUSED, VALUE interval)
759
908
  {
760
- evma_set_timer_quantum (FIX2INT (interval));
761
- return Qnil;
909
+ evma_set_timer_quantum (FIX2INT (interval));
910
+ return Qnil;
762
911
  }
763
912
 
764
913
  /********************
765
914
  t_get_max_timer_count
766
915
  ********************/
767
916
 
768
- static VALUE t_get_max_timer_count (VALUE self)
917
+ static VALUE t_get_max_timer_count (VALUE self UNUSED)
769
918
  {
770
- return INT2FIX (evma_get_max_timer_count());
919
+ return INT2FIX (evma_get_max_timer_count());
771
920
  }
772
921
 
773
922
  /********************
774
923
  t_set_max_timer_count
775
924
  ********************/
776
925
 
777
- static VALUE t_set_max_timer_count (VALUE self, VALUE ct)
926
+ static VALUE t_set_max_timer_count (VALUE self UNUSED, VALUE ct)
778
927
  {
779
- evma_set_max_timer_count (FIX2INT (ct));
780
- return Qnil;
928
+ evma_set_max_timer_count (FIX2INT (ct));
929
+ return Qnil;
930
+ }
931
+
932
+ /********************
933
+ t_get/set_simultaneous_accept_count
934
+ ********************/
935
+
936
+ static VALUE t_get_simultaneous_accept_count (VALUE self UNUSED)
937
+ {
938
+ return INT2FIX (evma_get_simultaneous_accept_count());
939
+ }
940
+
941
+ static VALUE t_set_simultaneous_accept_count (VALUE self UNUSED, VALUE ct)
942
+ {
943
+ evma_set_simultaneous_accept_count (FIX2INT (ct));
944
+ return Qnil;
781
945
  }
782
946
 
783
947
  /***************
784
948
  t_setuid_string
785
949
  ***************/
786
950
 
787
- static VALUE t_setuid_string (VALUE self, VALUE username)
951
+ static VALUE t_setuid_string (VALUE self UNUSED, VALUE username)
788
952
  {
789
- evma_setuid_string (StringValuePtr (username));
790
- return Qnil;
953
+ evma_setuid_string (StringValueCStr (username));
954
+ return Qnil;
791
955
  }
792
956
 
793
957
 
@@ -796,25 +960,29 @@ static VALUE t_setuid_string (VALUE self, VALUE username)
796
960
  t_invoke_popen
797
961
  **************/
798
962
 
799
- static VALUE t_invoke_popen (VALUE self, VALUE cmd)
963
+ static VALUE t_invoke_popen (VALUE self UNUSED, VALUE cmd)
800
964
  {
801
- // 1.8.7+
802
- #ifdef RARRAY_LEN
803
- int len = RARRAY_LEN(cmd);
804
- #else
805
- int len = RARRAY (cmd)->len;
965
+ #ifdef OS_WIN32
966
+ rb_raise (EM_eUnsupported, "popen is not available on this platform");
806
967
  #endif
968
+
969
+ int len = RARRAY_LEN(cmd);
807
970
  if (len >= 2048)
808
971
  rb_raise (rb_eRuntimeError, "%s", "too many arguments to popen");
809
972
  char *strings [2048];
810
973
  for (int i=0; i < len; i++) {
811
974
  VALUE ix = INT2FIX (i);
812
975
  VALUE s = rb_ary_aref (1, &ix, cmd);
813
- strings[i] = StringValuePtr (s);
976
+ strings[i] = StringValueCStr (s);
814
977
  }
815
978
  strings[len] = NULL;
816
979
 
817
- const unsigned long f = evma_popen (strings);
980
+ uintptr_t f = 0;
981
+ try {
982
+ f = evma_popen (strings);
983
+ } catch (std::runtime_error e) {
984
+ rb_raise (rb_eRuntimeError, "%s", e.what());
985
+ }
818
986
  if (!f) {
819
987
  char *err = strerror (errno);
820
988
  char buf[100];
@@ -822,7 +990,7 @@ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
822
990
  snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
823
991
  rb_raise (rb_eRuntimeError, "%s", buf);
824
992
  }
825
- return ULONG2NUM (f);
993
+ return BSIG2NUM (f);
826
994
  }
827
995
 
828
996
 
@@ -830,12 +998,12 @@ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
830
998
  t_read_keyboard
831
999
  ***************/
832
1000
 
833
- static VALUE t_read_keyboard (VALUE self)
1001
+ static VALUE t_read_keyboard (VALUE self UNUSED)
834
1002
  {
835
- const unsigned long f = evma_open_keyboard();
1003
+ const uintptr_t f = evma_open_keyboard();
836
1004
  if (!f)
837
1005
  rb_raise (rb_eRuntimeError, "%s", "no keyboard reader");
838
- return ULONG2NUM (f);
1006
+ return BSIG2NUM (f);
839
1007
  }
840
1008
 
841
1009
 
@@ -843,10 +1011,10 @@ static VALUE t_read_keyboard (VALUE self)
843
1011
  t_watch_filename
844
1012
  ****************/
845
1013
 
846
- static VALUE t_watch_filename (VALUE self, VALUE fname)
1014
+ static VALUE t_watch_filename (VALUE self UNUSED, VALUE fname)
847
1015
  {
848
1016
  try {
849
- return ULONG2NUM(evma_watch_filename(StringValuePtr(fname)));
1017
+ return BSIG2NUM(evma_watch_filename(StringValueCStr(fname)));
850
1018
  } catch (std::runtime_error e) {
851
1019
  rb_raise (EM_eUnsupported, "%s", e.what());
852
1020
  }
@@ -858,9 +1026,9 @@ static VALUE t_watch_filename (VALUE self, VALUE fname)
858
1026
  t_unwatch_filename
859
1027
  ******************/
860
1028
 
861
- static VALUE t_unwatch_filename (VALUE self, VALUE sig)
1029
+ static VALUE t_unwatch_filename (VALUE self UNUSED, VALUE sig)
862
1030
  {
863
- evma_unwatch_filename(NUM2ULONG (sig));
1031
+ evma_unwatch_filename(NUM2BSIG (sig));
864
1032
  return Qnil;
865
1033
  }
866
1034
 
@@ -869,10 +1037,10 @@ static VALUE t_unwatch_filename (VALUE self, VALUE sig)
869
1037
  t_watch_pid
870
1038
  ***********/
871
1039
 
872
- static VALUE t_watch_pid (VALUE self, VALUE pid)
1040
+ static VALUE t_watch_pid (VALUE self UNUSED, VALUE pid)
873
1041
  {
874
1042
  try {
875
- return ULONG2NUM(evma_watch_pid(NUM2INT(pid)));
1043
+ return BSIG2NUM(evma_watch_pid(NUM2INT(pid)));
876
1044
  } catch (std::runtime_error e) {
877
1045
  rb_raise (EM_eUnsupported, "%s", e.what());
878
1046
  }
@@ -884,9 +1052,9 @@ static VALUE t_watch_pid (VALUE self, VALUE pid)
884
1052
  t_unwatch_pid
885
1053
  *************/
886
1054
 
887
- static VALUE t_unwatch_pid (VALUE self, VALUE sig)
1055
+ static VALUE t_unwatch_pid (VALUE self UNUSED, VALUE sig)
888
1056
  {
889
- evma_unwatch_pid(NUM2ULONG (sig));
1057
+ evma_unwatch_pid(NUM2BSIG (sig));
890
1058
  return Qnil;
891
1059
  }
892
1060
 
@@ -895,21 +1063,24 @@ static VALUE t_unwatch_pid (VALUE self, VALUE sig)
895
1063
  t__epoll_p
896
1064
  **********/
897
1065
 
898
- static VALUE t__epoll_p (VALUE self)
1066
+ static VALUE t__epoll_p (VALUE self UNUSED)
899
1067
  {
900
- #ifdef HAVE_EPOLL
901
- return Qtrue;
902
- #else
903
- return Qfalse;
904
- #endif
1068
+ #ifdef HAVE_EPOLL
1069
+ return Qtrue;
1070
+ #else
1071
+ return Qfalse;
1072
+ #endif
905
1073
  }
906
1074
 
907
1075
  /********
908
1076
  t__epoll
909
1077
  ********/
910
1078
 
911
- static VALUE t__epoll (VALUE self)
1079
+ static VALUE t__epoll (VALUE self UNUSED)
912
1080
  {
1081
+ if (t__epoll_p(self) == Qfalse)
1082
+ return Qfalse;
1083
+
913
1084
  evma_set_epoll (1);
914
1085
  return Qtrue;
915
1086
  }
@@ -920,7 +1091,7 @@ t__epoll_set
920
1091
 
921
1092
  static VALUE t__epoll_set (VALUE self, VALUE val)
922
1093
  {
923
- if (t__epoll_p(self) == Qfalse)
1094
+ if (t__epoll_p(self) == Qfalse && val == Qtrue)
924
1095
  rb_raise (EM_eUnsupported, "%s", "epoll is not supported on this platform");
925
1096
 
926
1097
  evma_set_epoll (val == Qtrue ? 1 : 0);
@@ -932,21 +1103,24 @@ static VALUE t__epoll_set (VALUE self, VALUE val)
932
1103
  t__kqueue_p
933
1104
  ***********/
934
1105
 
935
- static VALUE t__kqueue_p (VALUE self)
1106
+ static VALUE t__kqueue_p (VALUE self UNUSED)
936
1107
  {
937
- #ifdef HAVE_KQUEUE
938
- return Qtrue;
939
- #else
940
- return Qfalse;
941
- #endif
1108
+ #ifdef HAVE_KQUEUE
1109
+ return Qtrue;
1110
+ #else
1111
+ return Qfalse;
1112
+ #endif
942
1113
  }
943
1114
 
944
1115
  /*********
945
1116
  t__kqueue
946
1117
  *********/
947
1118
 
948
- static VALUE t__kqueue (VALUE self)
1119
+ static VALUE t__kqueue (VALUE self UNUSED)
949
1120
  {
1121
+ if (t__kqueue_p(self) == Qfalse)
1122
+ return Qfalse;
1123
+
950
1124
  evma_set_kqueue (1);
951
1125
  return Qtrue;
952
1126
  }
@@ -957,7 +1131,7 @@ t__kqueue_set
957
1131
 
958
1132
  static VALUE t__kqueue_set (VALUE self, VALUE val)
959
1133
  {
960
- if (t__kqueue_p(self) == Qfalse)
1134
+ if (t__kqueue_p(self) == Qfalse && val == Qtrue)
961
1135
  rb_raise (EM_eUnsupported, "%s", "kqueue is not supported on this platform");
962
1136
 
963
1137
  evma_set_kqueue (val == Qtrue ? 1 : 0);
@@ -969,13 +1143,30 @@ static VALUE t__kqueue_set (VALUE self, VALUE val)
969
1143
  t__ssl_p
970
1144
  ********/
971
1145
 
972
- static VALUE t__ssl_p (VALUE self)
1146
+ static VALUE t__ssl_p (VALUE self UNUSED)
1147
+ {
1148
+ #ifdef WITH_SSL
1149
+ return Qtrue;
1150
+ #else
1151
+ return Qfalse;
1152
+ #endif
1153
+ }
1154
+
1155
+ /********
1156
+ t_stopping
1157
+ ********/
1158
+
1159
+ static VALUE t_stopping ()
973
1160
  {
974
- #ifdef WITH_SSL
975
- return Qtrue;
976
- #else
977
- return Qfalse;
978
- #endif
1161
+ if (evma_stopping())
1162
+ {
1163
+ return Qtrue;
1164
+ }
1165
+ else
1166
+ {
1167
+ return Qfalse;
1168
+ }
1169
+
979
1170
  }
980
1171
 
981
1172
 
@@ -983,7 +1174,7 @@ static VALUE t__ssl_p (VALUE self)
983
1174
  t_send_file_data
984
1175
  ****************/
985
1176
 
986
- static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
1177
+ static VALUE t_send_file_data (VALUE self UNUSED, VALUE signature, VALUE filename)
987
1178
  {
988
1179
 
989
1180
  /* The current implementation of evma_send_file_data_to_connection enforces a strict
@@ -994,14 +1185,14 @@ static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
994
1185
  * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
995
1186
  */
996
1187
 
997
- int b = evma_send_file_data_to_connection (NUM2ULONG (signature), StringValuePtr(filename));
1188
+ int b = evma_send_file_data_to_connection (NUM2BSIG (signature), StringValueCStr(filename));
998
1189
  if (b == -1)
999
1190
  rb_raise(rb_eRuntimeError, "%s", "File too large. send_file_data() supports files under 32k.");
1000
1191
  if (b > 0) {
1001
1192
  char *err = strerror (b);
1002
1193
  char buf[1024];
1003
1194
  memset (buf, 0, sizeof(buf));
1004
- snprintf (buf, sizeof(buf)-1, ": %s %s", StringValuePtr(filename),(err?err:"???"));
1195
+ snprintf (buf, sizeof(buf)-1, ": %s %s", StringValueCStr(filename),(err?err:"???"));
1005
1196
 
1006
1197
  rb_raise (rb_eIOError, "%s", buf);
1007
1198
  }
@@ -1014,7 +1205,7 @@ static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
1014
1205
  t_set_rlimit_nofile
1015
1206
  *******************/
1016
1207
 
1017
- static VALUE t_set_rlimit_nofile (VALUE self, VALUE arg)
1208
+ static VALUE t_set_rlimit_nofile (VALUE self UNUSED, VALUE arg)
1018
1209
  {
1019
1210
  arg = (NIL_P(arg)) ? -1 : NUM2INT (arg);
1020
1211
  return INT2NUM (evma_set_rlimit_nofile (arg));
@@ -1027,7 +1218,7 @@ conn_get_outbound_data_size
1027
1218
  static VALUE conn_get_outbound_data_size (VALUE self)
1028
1219
  {
1029
1220
  VALUE sig = rb_ivar_get (self, Intern_at_signature);
1030
- return INT2NUM (evma_get_outbound_data_size (NUM2ULONG (sig)));
1221
+ return INT2NUM (evma_get_outbound_data_size (NUM2BSIG (sig)));
1031
1222
  }
1032
1223
 
1033
1224
 
@@ -1035,7 +1226,7 @@ static VALUE conn_get_outbound_data_size (VALUE self)
1035
1226
  conn_associate_callback_target
1036
1227
  ******************************/
1037
1228
 
1038
- static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
1229
+ static VALUE conn_associate_callback_target (VALUE self UNUSED, VALUE sig UNUSED)
1039
1230
  {
1040
1231
  // No-op for the time being.
1041
1232
  return Qnil;
@@ -1046,22 +1237,19 @@ static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
1046
1237
  t_get_loop_time
1047
1238
  ****************/
1048
1239
 
1049
- static VALUE t_get_loop_time (VALUE self)
1240
+ static VALUE t_get_loop_time (VALUE self UNUSED)
1050
1241
  {
1051
- #ifndef HAVE_RB_TIME_NEW
1052
- static VALUE cTime = rb_path2class("Time");
1053
- static ID at = rb_intern("at");
1054
- #endif
1242
+ uint64_t current_time = evma_get_current_loop_time();
1243
+ if (current_time == 0) {
1244
+ return Qnil;
1245
+ }
1055
1246
 
1056
- uint64_t current_time = evma_get_current_loop_time();
1057
- if (current_time != 0) {
1058
- #ifndef HAVE_RB_TIME_NEW
1059
- return rb_funcall(cTime, at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000));
1060
- #else
1061
- return rb_time_new(current_time / 1000000, current_time % 1000000);
1062
- #endif
1063
- }
1064
- return Qnil;
1247
+ // Generally the industry has moved to 64-bit time_t, this is just in case we're 32-bit time_t.
1248
+ if (sizeof(time_t) < 8 && current_time > INT_MAX) {
1249
+ return rb_funcall(rb_cTime, Intern_at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000));
1250
+ } else {
1251
+ return rb_time_new(current_time / 1000000, current_time % 1000000);
1252
+ }
1065
1253
  }
1066
1254
 
1067
1255
 
@@ -1069,10 +1257,10 @@ static VALUE t_get_loop_time (VALUE self)
1069
1257
  t_start_proxy
1070
1258
  **************/
1071
1259
 
1072
- static VALUE t_start_proxy (VALUE self, VALUE from, VALUE to, VALUE bufsize, VALUE length)
1260
+ static VALUE t_start_proxy (VALUE self UNUSED, VALUE from, VALUE to, VALUE bufsize, VALUE length)
1073
1261
  {
1074
1262
  try {
1075
- evma_start_proxy(NUM2ULONG (from), NUM2ULONG (to), NUM2ULONG(bufsize), NUM2ULONG(length));
1263
+ evma_start_proxy(NUM2BSIG (from), NUM2BSIG (to), NUM2ULONG(bufsize), NUM2ULONG(length));
1076
1264
  } catch (std::runtime_error e) {
1077
1265
  rb_raise (EM_eConnectionError, "%s", e.what());
1078
1266
  }
@@ -1084,10 +1272,10 @@ static VALUE t_start_proxy (VALUE self, VALUE from, VALUE to, VALUE bufsize, VAL
1084
1272
  t_stop_proxy
1085
1273
  *************/
1086
1274
 
1087
- static VALUE t_stop_proxy (VALUE self, VALUE from)
1275
+ static VALUE t_stop_proxy (VALUE self UNUSED, VALUE from)
1088
1276
  {
1089
1277
  try{
1090
- evma_stop_proxy(NUM2ULONG (from));
1278
+ evma_stop_proxy(NUM2BSIG (from));
1091
1279
  } catch (std::runtime_error e) {
1092
1280
  rb_raise (EM_eConnectionError, "%s", e.what());
1093
1281
  }
@@ -1098,10 +1286,10 @@ static VALUE t_stop_proxy (VALUE self, VALUE from)
1098
1286
  t_proxied_bytes
1099
1287
  ****************/
1100
1288
 
1101
- static VALUE t_proxied_bytes (VALUE self, VALUE from)
1289
+ static VALUE t_proxied_bytes (VALUE self UNUSED, VALUE from)
1102
1290
  {
1103
1291
  try{
1104
- return ULONG2NUM(evma_proxied_bytes(NUM2ULONG (from)));
1292
+ return BSIG2NUM(evma_proxied_bytes(NUM2BSIG (from)));
1105
1293
  } catch (std::runtime_error e) {
1106
1294
  rb_raise (EM_eConnectionError, "%s", e.what());
1107
1295
  }
@@ -1112,14 +1300,14 @@ static VALUE t_proxied_bytes (VALUE self, VALUE from)
1112
1300
  t_get_idle_time
1113
1301
  ****************/
1114
1302
 
1115
- static VALUE t_get_idle_time (VALUE self, VALUE from)
1303
+ static VALUE t_get_idle_time (VALUE self UNUSED, VALUE from)
1116
1304
  {
1117
1305
  try{
1118
1306
  uint64_t current_time = evma_get_current_loop_time();
1119
- uint64_t time = evma_get_last_activity_time(NUM2ULONG (from));
1307
+ uint64_t time = evma_get_last_activity_time(NUM2BSIG (from));
1120
1308
  if (current_time != 0 && time != 0) {
1121
1309
  if (time >= current_time)
1122
- return ULONG2NUM(0);
1310
+ return BSIG2NUM(0);
1123
1311
  else {
1124
1312
  uint64_t diff = current_time - time;
1125
1313
  float seconds = diff / (1000.0*1000.0);
@@ -1137,7 +1325,7 @@ static VALUE t_get_idle_time (VALUE self, VALUE from)
1137
1325
  t_get_heartbeat_interval
1138
1326
  *************************/
1139
1327
 
1140
- static VALUE t_get_heartbeat_interval (VALUE self)
1328
+ static VALUE t_get_heartbeat_interval (VALUE self UNUSED)
1141
1329
  {
1142
1330
  return rb_float_new(evma_get_heartbeat_interval());
1143
1331
  }
@@ -1147,7 +1335,7 @@ static VALUE t_get_heartbeat_interval (VALUE self)
1147
1335
  t_set_heartbeat_interval
1148
1336
  *************************/
1149
1337
 
1150
- static VALUE t_set_heartbeat_interval (VALUE self, VALUE interval)
1338
+ static VALUE t_set_heartbeat_interval (VALUE self UNUSED, VALUE interval)
1151
1339
  {
1152
1340
  float iv = RFLOAT_VALUE(interval);
1153
1341
  if (evma_set_heartbeat_interval(iv))
@@ -1176,6 +1364,7 @@ extern "C" void Init_rubyeventmachine()
1176
1364
  Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
1177
1365
  Intern_delete = rb_intern ("delete");
1178
1366
  Intern_call = rb_intern ("call");
1367
+ Intern_at = rb_intern("at");
1179
1368
  Intern_receive_data = rb_intern ("receive_data");
1180
1369
  Intern_ssl_handshake_completed = rb_intern ("ssl_handshake_completed");
1181
1370
  Intern_ssl_verify_peer = rb_intern ("ssl_verify_peer");
@@ -1198,15 +1387,21 @@ extern "C" void Init_rubyeventmachine()
1198
1387
  EM_eUnsupported = rb_define_class_under (EmModule, "Unsupported", rb_eRuntimeError);
1199
1388
 
1200
1389
  rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
1201
- rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
1202
- rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine_without_threads, 0);
1390
+ rb_define_module_function (EmModule, "run_machine_once", (VALUE(*)(...))t_run_machine_once, 0);
1391
+ rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine, 0);
1392
+ rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine, 0);
1203
1393
  rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
1204
1394
  rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
1205
1395
  rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
1206
1396
  rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
1207
- rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 4);
1397
+ rb_define_module_function (EmModule, "attach_sd", (VALUE(*)(...))t_attach_sd, 1);
1398
+ rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 10);
1208
1399
  rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
1209
1400
  rb_define_module_function (EmModule, "get_peer_cert", (VALUE(*)(...))t_get_peer_cert, 1);
1401
+ rb_define_module_function (EmModule, "get_cipher_bits", (VALUE(*)(...))t_get_cipher_bits, 1);
1402
+ rb_define_module_function (EmModule, "get_cipher_name", (VALUE(*)(...))t_get_cipher_name, 1);
1403
+ rb_define_module_function (EmModule, "get_cipher_protocol", (VALUE(*)(...))t_get_cipher_protocol, 1);
1404
+ rb_define_module_function (EmModule, "get_sni_hostname", (VALUE(*)(...))t_get_sni_hostname, 1);
1210
1405
  rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
1211
1406
  rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
1212
1407
  rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
@@ -1217,6 +1412,7 @@ extern "C" void Init_rubyeventmachine()
1217
1412
 
1218
1413
  rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 2);
1219
1414
  rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
1415
+ rb_define_module_function (EmModule, "get_file_descriptor", (VALUE (*)(...))t_get_file_descriptor, 1);
1220
1416
  rb_define_module_function (EmModule, "get_sock_opt", (VALUE (*)(...))t_get_sock_opt, 3);
1221
1417
  rb_define_module_function (EmModule, "set_sock_opt", (VALUE (*)(...))t_set_sock_opt, 4);
1222
1418
  rb_define_module_function (EmModule, "set_notify_readable", (VALUE (*)(...))t_set_notify_readable, 2);
@@ -1250,6 +1446,8 @@ extern "C" void Init_rubyeventmachine()
1250
1446
  rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
1251
1447
  rb_define_module_function (EmModule, "get_max_timer_count", (VALUE(*)(...))t_get_max_timer_count, 0);
1252
1448
  rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
1449
+ rb_define_module_function (EmModule, "get_simultaneous_accept_count", (VALUE(*)(...))t_get_simultaneous_accept_count, 0);
1450
+ rb_define_module_function (EmModule, "set_simultaneous_accept_count", (VALUE(*)(...))t_set_simultaneous_accept_count, 1);
1253
1451
  rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
1254
1452
  rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
1255
1453
  rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
@@ -1277,21 +1475,30 @@ extern "C" void Init_rubyeventmachine()
1277
1475
  rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);
1278
1476
 
1279
1477
  rb_define_module_function (EmModule, "ssl?", (VALUE(*)(...))t__ssl_p, 0);
1478
+ rb_define_module_function(EmModule, "stopping?",(VALUE(*)(...))t_stopping, 0);
1280
1479
 
1281
1480
  rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
1282
1481
  rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
1283
1482
 
1284
- rb_define_const (EmModule, "TimerFired", INT2NUM(100));
1285
- rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
1286
- rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(102));
1287
- rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(103));
1288
- rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(104));
1289
- rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(105));
1290
-
1291
- rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(106));
1292
- rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(107));
1293
-
1294
- rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(108));
1295
-
1483
+ // Connection states
1484
+ rb_define_const (EmModule, "TimerFired", INT2NUM(EM_TIMER_FIRED ));
1485
+ rb_define_const (EmModule, "ConnectionData", INT2NUM(EM_CONNECTION_READ ));
1486
+ rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(EM_CONNECTION_UNBOUND ));
1487
+ rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(EM_CONNECTION_ACCEPTED ));
1488
+ rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(EM_CONNECTION_COMPLETED ));
1489
+ rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(EM_LOOPBREAK_SIGNAL ));
1490
+ rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(EM_CONNECTION_NOTIFY_READABLE));
1491
+ rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(EM_CONNECTION_NOTIFY_WRITABLE));
1492
+ rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(EM_SSL_HANDSHAKE_COMPLETED ));
1493
+ // EM_SSL_VERIFY = 109,
1494
+ // EM_PROXY_TARGET_UNBOUND = 110,
1495
+ // EM_PROXY_COMPLETED = 111
1496
+
1497
+ // SSL Protocols
1498
+ rb_define_const (EmModule, "EM_PROTO_SSLv2", INT2NUM(EM_PROTO_SSLv2 ));
1499
+ rb_define_const (EmModule, "EM_PROTO_SSLv3", INT2NUM(EM_PROTO_SSLv3 ));
1500
+ rb_define_const (EmModule, "EM_PROTO_TLSv1", INT2NUM(EM_PROTO_TLSv1 ));
1501
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_1", INT2NUM(EM_PROTO_TLSv1_1));
1502
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_2", INT2NUM(EM_PROTO_TLSv1_2));
1296
1503
  }
1297
1504