eventmachine-mkroman 1.3.0.dev.1

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 (182) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +179 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +110 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +520 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +52 -0
  35. data/ext/cmain.cpp +1046 -0
  36. data/ext/ed.cpp +2243 -0
  37. data/ext/ed.h +463 -0
  38. data/ext/em.cpp +2378 -0
  39. data/ext/em.h +266 -0
  40. data/ext/eventmachine.h +152 -0
  41. data/ext/extconf.rb +291 -0
  42. data/ext/fastfilereader/extconf.rb +120 -0
  43. data/ext/fastfilereader/mapper.cpp +214 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +126 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +174 -0
  51. data/ext/rubymain.cpp +1643 -0
  52. data/ext/ssl.cpp +701 -0
  53. data/ext/ssl.h +103 -0
  54. data/ext/wait_for_single_fd.h +36 -0
  55. data/java/.classpath +8 -0
  56. data/java/.project +17 -0
  57. data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
  58. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  59. data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
  60. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  61. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  62. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  63. data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
  64. data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
  65. data/lib/em/buftok.rb +59 -0
  66. data/lib/em/callback.rb +58 -0
  67. data/lib/em/channel.rb +69 -0
  68. data/lib/em/completion.rb +307 -0
  69. data/lib/em/connection.rb +802 -0
  70. data/lib/em/deferrable/pool.rb +2 -0
  71. data/lib/em/deferrable.rb +210 -0
  72. data/lib/em/file_watch.rb +73 -0
  73. data/lib/em/future.rb +61 -0
  74. data/lib/em/io_streamer.rb +68 -0
  75. data/lib/em/iterator.rb +252 -0
  76. data/lib/em/messages.rb +66 -0
  77. data/lib/em/pool.rb +151 -0
  78. data/lib/em/process_watch.rb +45 -0
  79. data/lib/em/processes.rb +123 -0
  80. data/lib/em/protocols/header_and_content.rb +138 -0
  81. data/lib/em/protocols/httpclient.rb +303 -0
  82. data/lib/em/protocols/httpclient2.rb +602 -0
  83. data/lib/em/protocols/line_and_text.rb +125 -0
  84. data/lib/em/protocols/line_protocol.rb +33 -0
  85. data/lib/em/protocols/linetext2.rb +179 -0
  86. data/lib/em/protocols/memcache.rb +331 -0
  87. data/lib/em/protocols/object_protocol.rb +46 -0
  88. data/lib/em/protocols/postgres3.rb +246 -0
  89. data/lib/em/protocols/saslauth.rb +175 -0
  90. data/lib/em/protocols/smtpclient.rb +394 -0
  91. data/lib/em/protocols/smtpserver.rb +666 -0
  92. data/lib/em/protocols/socks4.rb +66 -0
  93. data/lib/em/protocols/stomp.rb +205 -0
  94. data/lib/em/protocols/tcptest.rb +54 -0
  95. data/lib/em/protocols.rb +37 -0
  96. data/lib/em/pure_ruby.rb +1300 -0
  97. data/lib/em/queue.rb +80 -0
  98. data/lib/em/resolver.rb +232 -0
  99. data/lib/em/spawnable.rb +84 -0
  100. data/lib/em/streamer.rb +118 -0
  101. data/lib/em/threaded_resource.rb +90 -0
  102. data/lib/em/tick_loop.rb +85 -0
  103. data/lib/em/timers.rb +61 -0
  104. data/lib/em/version.rb +3 -0
  105. data/lib/eventmachine.rb +1602 -0
  106. data/lib/jeventmachine.rb +319 -0
  107. data/rakelib/package.rake +120 -0
  108. data/rakelib/test.rake +6 -0
  109. data/rakelib/test_pure.rake +11 -0
  110. data/tests/client.crt +31 -0
  111. data/tests/client.key +51 -0
  112. data/tests/dhparam.pem +13 -0
  113. data/tests/em_ssl_handlers.rb +165 -0
  114. data/tests/em_test_helper.rb +198 -0
  115. data/tests/encoded_client.key +54 -0
  116. data/tests/jruby/test_jeventmachine.rb +38 -0
  117. data/tests/test_attach.rb +199 -0
  118. data/tests/test_basic.rb +321 -0
  119. data/tests/test_channel.rb +75 -0
  120. data/tests/test_completion.rb +178 -0
  121. data/tests/test_connection_count.rb +83 -0
  122. data/tests/test_connection_write.rb +35 -0
  123. data/tests/test_defer.rb +35 -0
  124. data/tests/test_deferrable.rb +35 -0
  125. data/tests/test_epoll.rb +141 -0
  126. data/tests/test_error_handler.rb +38 -0
  127. data/tests/test_exc.rb +37 -0
  128. data/tests/test_file_watch.rb +86 -0
  129. data/tests/test_fork.rb +75 -0
  130. data/tests/test_futures.rb +170 -0
  131. data/tests/test_handler_check.rb +35 -0
  132. data/tests/test_hc.rb +155 -0
  133. data/tests/test_httpclient.rb +238 -0
  134. data/tests/test_httpclient2.rb +132 -0
  135. data/tests/test_idle_connection.rb +31 -0
  136. data/tests/test_inactivity_timeout.rb +102 -0
  137. data/tests/test_io_streamer.rb +48 -0
  138. data/tests/test_ipv4.rb +96 -0
  139. data/tests/test_ipv6.rb +107 -0
  140. data/tests/test_iterator.rb +122 -0
  141. data/tests/test_kb.rb +28 -0
  142. data/tests/test_keepalive.rb +113 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +155 -0
  145. data/tests/test_ltp2.rb +332 -0
  146. data/tests/test_many_fds.rb +21 -0
  147. data/tests/test_next_tick.rb +104 -0
  148. data/tests/test_object_protocol.rb +36 -0
  149. data/tests/test_pause.rb +109 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +196 -0
  152. data/tests/test_process_watch.rb +50 -0
  153. data/tests/test_processes.rb +147 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +156 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +129 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +46 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +32 -0
  162. data/tests/test_shutdown_hooks.rb +23 -0
  163. data/tests/test_smtpclient.rb +75 -0
  164. data/tests/test_smtpserver.rb +90 -0
  165. data/tests/test_sock_opt.rb +53 -0
  166. data/tests/test_spawn.rb +290 -0
  167. data/tests/test_ssl_args.rb +70 -0
  168. data/tests/test_ssl_dhparam.rb +57 -0
  169. data/tests/test_ssl_ecdh_curve.rb +57 -0
  170. data/tests/test_ssl_extensions.rb +24 -0
  171. data/tests/test_ssl_inline_cert.rb +222 -0
  172. data/tests/test_ssl_methods.rb +31 -0
  173. data/tests/test_ssl_protocols.rb +190 -0
  174. data/tests/test_ssl_verify.rb +108 -0
  175. data/tests/test_stomp.rb +38 -0
  176. data/tests/test_system.rb +46 -0
  177. data/tests/test_threaded_resource.rb +68 -0
  178. data/tests/test_tick_loop.rb +58 -0
  179. data/tests/test_timers.rb +150 -0
  180. data/tests/test_ud.rb +8 -0
  181. data/tests/test_unbind_reason.rb +40 -0
  182. metadata +389 -0
data/ext/rubymain.cpp ADDED
@@ -0,0 +1,1643 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: rubymain.cpp
6
+ Date: 06Apr06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+ #include "project.h"
21
+ #include "eventmachine.h"
22
+ #include <ruby.h>
23
+
24
+ /* Adapted from NUM2BSIG / BSIG2NUM in ext/fiddle/conversions.h,
25
+ * we'll call it a BSIG for Binding Signature here. */
26
+ #if SIZEOF_VOIDP == SIZEOF_LONG
27
+ # define BSIG2NUM(x) (ULONG2NUM((unsigned long)(x)))
28
+ # define NUM2BSIG(x) (NUM2ULONG(x))
29
+ # ifdef OS_WIN32
30
+ # define PRIFBSIG "I32u"
31
+ # else
32
+ # define PRIFBSIG "lu"
33
+ # endif
34
+ #else
35
+ # define BSIG2NUM(x) (ULL2NUM((unsigned long long)(x)))
36
+ # define NUM2BSIG(x) (NUM2ULL(x))
37
+ # ifdef OS_WIN32
38
+ # define PRIFBSIG "I64u"
39
+ # else
40
+ # define PRIFBSIG "llu"
41
+ # endif
42
+ #endif
43
+
44
+ /* Adapted from SWIG's changes for Ruby 2.7 compatibility.
45
+ * Before Ruby 2.7, rb_rescue takes (VALUE (*))(ANYARGS)
46
+ * whereas in Ruby 2.7, rb_rescue takes (VALUE (*))(VALUE)
47
+ * */
48
+ #if defined(__cplusplus) && !defined(RB_METHOD_DEFINITION_DECL)
49
+ # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
50
+ #else
51
+ # define VALUEFUNC(f) (f)
52
+ #endif
53
+
54
+ /*******
55
+ Statics
56
+ *******/
57
+
58
+ static VALUE EmModule;
59
+ static VALUE EmConnection;
60
+ static VALUE EmConnsHash;
61
+ static VALUE EmTimersHash;
62
+
63
+ static VALUE EM_eConnectionError;
64
+ static VALUE EM_eUnknownTimerFired;
65
+ static VALUE EM_eConnectionNotBound;
66
+ static VALUE EM_eUnsupported;
67
+ static VALUE EM_eInvalidSignature;
68
+ static VALUE EM_eInvalidPrivateKey;
69
+
70
+ static VALUE Intern_at_signature;
71
+ static VALUE Intern_at_timers;
72
+ static VALUE Intern_at_conns;
73
+ static VALUE Intern_at_error_handler;
74
+ static VALUE Intern_event_callback;
75
+ static VALUE Intern_run_deferred_callbacks;
76
+ static VALUE Intern_delete;
77
+ static VALUE Intern_call;
78
+ static VALUE Intern_at;
79
+ static VALUE Intern_receive_data;
80
+ static VALUE Intern_ssl_handshake_completed;
81
+ static VALUE Intern_ssl_verify_peer;
82
+ static VALUE Intern_notify_readable;
83
+ static VALUE Intern_notify_writable;
84
+ static VALUE Intern_proxy_target_unbound;
85
+ static VALUE Intern_proxy_completed;
86
+ static VALUE Intern_connection_completed;
87
+
88
+ static VALUE rb_cProcessStatus;
89
+
90
+ #ifdef IS_RUBY_3_OR_LATER
91
+ /* Structure definition from MRI Ruby 3.0 process.c */
92
+ struct rb_process_status {
93
+ rb_pid_t pid;
94
+ int status;
95
+ int error;
96
+ };
97
+ #endif
98
+
99
+ struct em_event {
100
+ uintptr_t signature;
101
+ int event;
102
+ const char *data_str;
103
+ unsigned long data_num;
104
+ };
105
+
106
+ static inline VALUE ensure_conn(const uintptr_t signature)
107
+ {
108
+ VALUE conn = rb_hash_aref (EmConnsHash, BSIG2NUM (signature));
109
+ if (conn == Qnil)
110
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %" PRIFBSIG, signature);
111
+ return conn;
112
+ }
113
+
114
+
115
+ /****************
116
+ t_event_callback
117
+ ****************/
118
+
119
+ static inline VALUE event_callback (VALUE e_value)
120
+ {
121
+ struct em_event *e = (struct em_event *)e_value;
122
+ const uintptr_t signature = e->signature;
123
+ int event = e->event;
124
+ const char *data_str = e->data_str;
125
+ const unsigned long data_num = e->data_num;
126
+
127
+ switch (event) {
128
+ case EM_CONNECTION_READ:
129
+ {
130
+ VALUE conn = rb_hash_aref (EmConnsHash, BSIG2NUM (signature));
131
+ if (conn == Qnil)
132
+ rb_raise (EM_eConnectionNotBound, "received %lu bytes of data for unknown signature: %" PRIFBSIG, data_num, signature);
133
+ rb_funcall (conn, Intern_receive_data, 1, rb_str_new (data_str, data_num));
134
+ return Qnil;
135
+ }
136
+ case EM_CONNECTION_ACCEPTED:
137
+ {
138
+ rb_funcall (EmModule, Intern_event_callback, 3, BSIG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
139
+ return Qnil;
140
+ }
141
+ case EM_CONNECTION_UNBOUND:
142
+ {
143
+ rb_funcall (EmModule, Intern_event_callback, 3, BSIG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
144
+ return Qnil;
145
+ }
146
+ case EM_CONNECTION_COMPLETED:
147
+ {
148
+ VALUE conn = ensure_conn(signature);
149
+ rb_funcall (conn, Intern_connection_completed, 0);
150
+ return Qnil;
151
+ }
152
+ case EM_CONNECTION_NOTIFY_READABLE:
153
+ {
154
+ VALUE conn = ensure_conn(signature);
155
+ rb_funcall (conn, Intern_notify_readable, 0);
156
+ return Qnil;
157
+ }
158
+ case EM_CONNECTION_NOTIFY_WRITABLE:
159
+ {
160
+ VALUE conn = ensure_conn(signature);
161
+ rb_funcall (conn, Intern_notify_writable, 0);
162
+ return Qnil;
163
+ }
164
+ case EM_LOOPBREAK_SIGNAL:
165
+ {
166
+ rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
167
+ return Qnil;
168
+ }
169
+ case EM_TIMER_FIRED:
170
+ {
171
+ VALUE timer = rb_funcall (EmTimersHash, Intern_delete, 1, ULONG2NUM (data_num));
172
+ if (timer == Qnil) {
173
+ rb_raise (EM_eUnknownTimerFired, "no such timer: %lu", data_num);
174
+ } else if (timer == Qfalse) {
175
+ /* Timer Canceled */
176
+ } else {
177
+ rb_funcall (timer, Intern_call, 0);
178
+ }
179
+ return Qnil;
180
+ }
181
+ #ifdef WITH_SSL
182
+ case EM_SSL_HANDSHAKE_COMPLETED:
183
+ {
184
+ VALUE conn = ensure_conn(signature);
185
+ rb_funcall (conn, Intern_ssl_handshake_completed, 0);
186
+ return Qnil;
187
+ }
188
+ case EM_SSL_VERIFY:
189
+ {
190
+ VALUE conn = ensure_conn(signature);
191
+ VALUE should_accept = rb_funcall (conn, Intern_ssl_verify_peer, 1, rb_str_new(data_str, data_num));
192
+ if (RTEST(should_accept))
193
+ evma_accept_ssl_peer (signature);
194
+ return Qnil;
195
+ }
196
+ #endif
197
+ case EM_PROXY_TARGET_UNBOUND:
198
+ {
199
+ VALUE conn = ensure_conn(signature);
200
+ rb_funcall (conn, Intern_proxy_target_unbound, 0);
201
+ return Qnil;
202
+ }
203
+ case EM_PROXY_COMPLETED:
204
+ {
205
+ VALUE conn = ensure_conn(signature);
206
+ rb_funcall (conn, Intern_proxy_completed, 0);
207
+ return Qnil;
208
+ }
209
+ }
210
+
211
+ return Qnil;
212
+ }
213
+
214
+ /*******************
215
+ event_error_handler
216
+ *******************/
217
+
218
+ static VALUE event_error_handler(VALUE self UNUSED, VALUE err)
219
+ {
220
+ VALUE error_handler = rb_ivar_get(EmModule, Intern_at_error_handler);
221
+ rb_funcall (error_handler, Intern_call, 1, err);
222
+ return Qnil;
223
+ }
224
+
225
+ /**********************
226
+ event_callback_wrapper
227
+ **********************/
228
+
229
+ static void event_callback_wrapper (const uintptr_t signature, int event, const char *data_str, const unsigned long data_num)
230
+ {
231
+ struct em_event e;
232
+ e.signature = signature;
233
+ e.event = event;
234
+ e.data_str = data_str;
235
+ e.data_num = data_num;
236
+
237
+ if (!rb_ivar_defined(EmModule, Intern_at_error_handler))
238
+ event_callback((VALUE)&e);
239
+ else
240
+ rb_rescue(VALUEFUNC(event_callback), (VALUE)&e, VALUEFUNC(event_error_handler), Qnil);
241
+ }
242
+
243
+ /**************************
244
+ t_initialize_event_machine
245
+ **************************/
246
+
247
+ static VALUE t_initialize_event_machine (VALUE self UNUSED)
248
+ {
249
+ EmConnsHash = rb_ivar_get (EmModule, Intern_at_conns);
250
+ EmTimersHash = rb_ivar_get (EmModule, Intern_at_timers);
251
+ assert(EmConnsHash != Qnil);
252
+ assert(EmTimersHash != Qnil);
253
+ evma_initialize_library ((EMCallback)event_callback_wrapper);
254
+ return Qnil;
255
+ }
256
+
257
+
258
+ /******************
259
+ t_run_machine_once
260
+ ******************/
261
+
262
+ static VALUE t_run_machine_once (VALUE self UNUSED)
263
+ {
264
+ return evma_run_machine_once () ? Qtrue : Qfalse;
265
+ }
266
+
267
+
268
+ /*************
269
+ t_run_machine
270
+ *************/
271
+
272
+ static VALUE t_run_machine (VALUE self UNUSED)
273
+ {
274
+ evma_run_machine();
275
+ return Qnil;
276
+ }
277
+
278
+ /*****************************
279
+ t_get_timer_count
280
+ *****************************/
281
+
282
+ static VALUE t_get_timer_count ()
283
+ {
284
+ return SIZET2NUM (evma_get_timer_count ());
285
+ }
286
+
287
+ /*******************
288
+ t_add_oneshot_timer
289
+ *******************/
290
+
291
+ static VALUE t_add_oneshot_timer (VALUE self UNUSED, VALUE interval)
292
+ {
293
+ const uintptr_t f = evma_install_oneshot_timer (FIX2LONG (interval));
294
+ if (!f)
295
+ rb_raise (rb_eRuntimeError, "%s", "ran out of timers; use #set_max_timers to increase limit");
296
+ return BSIG2NUM (f);
297
+ }
298
+
299
+
300
+ /**************
301
+ t_start_server
302
+ **************/
303
+
304
+ static VALUE t_start_server (VALUE self UNUSED, VALUE server, VALUE port)
305
+ {
306
+ const uintptr_t f = evma_create_tcp_server (StringValueCStr(server), FIX2INT(port));
307
+ if (!f)
308
+ rb_raise (rb_eRuntimeError, "%s", "no acceptor (port is in use or requires root privileges)");
309
+ return BSIG2NUM (f);
310
+ }
311
+
312
+ /*************
313
+ t_stop_server
314
+ *************/
315
+
316
+ static VALUE t_stop_server (VALUE self UNUSED, VALUE signature)
317
+ {
318
+ evma_stop_tcp_server (NUM2BSIG (signature));
319
+ return Qnil;
320
+ }
321
+
322
+
323
+ /*******************
324
+ t_start_unix_server
325
+ *******************/
326
+
327
+ static VALUE t_start_unix_server (VALUE self UNUSED, VALUE filename)
328
+ {
329
+ const uintptr_t f = evma_create_unix_domain_server (StringValueCStr(filename));
330
+ if (!f)
331
+ rb_raise (rb_eRuntimeError, "%s", "no unix-domain acceptor");
332
+ return BSIG2NUM (f);
333
+ }
334
+
335
+ /********************
336
+ t_attach_sd
337
+ ********************/
338
+
339
+ static VALUE t_attach_sd(VALUE self UNUSED, VALUE sd)
340
+ {
341
+ const uintptr_t f = evma_attach_sd(FIX2INT(sd));
342
+ if (!f)
343
+ rb_raise (rb_eRuntimeError, "%s", "no socket descriptor acceptor");
344
+ return BSIG2NUM (f);
345
+ }
346
+
347
+
348
+ /***********
349
+ t_send_data
350
+ ***********/
351
+
352
+ static VALUE t_send_data (VALUE self UNUSED, VALUE signature, VALUE data, VALUE data_length)
353
+ {
354
+ int b = evma_send_data_to_connection (NUM2BSIG (signature), StringValuePtr (data), FIX2INT (data_length));
355
+ return INT2NUM (b);
356
+ }
357
+
358
+
359
+ /***********
360
+ t_start_tls
361
+ ***********/
362
+
363
+ static VALUE t_start_tls (VALUE self UNUSED, VALUE signature)
364
+ {
365
+ try {
366
+ evma_start_tls (NUM2BSIG (signature));
367
+ } catch (const std::runtime_error& e) {
368
+ rb_raise (EM_eInvalidPrivateKey, e.what(), signature);
369
+ }
370
+ return Qnil;
371
+ }
372
+
373
+ /***************
374
+ t_set_tls_parms
375
+ ***************/
376
+
377
+ static VALUE t_set_tls_parms (VALUE self UNUSED, VALUE signature, VALUE privkeyfile, VALUE privkey, VALUE privkeypass, VALUE certchainfile, VALUE cert, VALUE verify_peer, VALUE fail_if_no_peer_cert, VALUE snihostname, VALUE cipherlist, VALUE ecdh_curve, VALUE dhparam, VALUE ssl_version)
378
+ {
379
+ /* set_tls_parms takes a series of positional arguments for specifying such things
380
+ * as private keys and certificate chains.
381
+ * It's expected that the parameter list will grow as we add more supported features.
382
+ * ALL of these parameters are optional, and can be specified as empty or NULL strings.
383
+ */
384
+ evma_set_tls_parms (NUM2BSIG (signature), StringValueCStr (privkeyfile), StringValueCStr (privkey), StringValueCStr (privkeypass), StringValueCStr (certchainfile), StringValueCStr (cert), (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));
385
+ return Qnil;
386
+ }
387
+
388
+ /***************
389
+ t_get_peer_cert
390
+ ***************/
391
+
392
+ #ifdef WITH_SSL
393
+ static VALUE t_get_peer_cert (VALUE self UNUSED, VALUE signature)
394
+ {
395
+ VALUE ret = Qnil;
396
+
397
+ X509 *cert = NULL;
398
+ BUF_MEM *buf;
399
+ BIO *out;
400
+
401
+ cert = evma_get_peer_cert (NUM2BSIG (signature));
402
+
403
+ if (cert != NULL) {
404
+ out = BIO_new(BIO_s_mem());
405
+ PEM_write_bio_X509(out, cert);
406
+ BIO_get_mem_ptr(out, &buf);
407
+ ret = rb_str_new(buf->data, buf->length);
408
+ X509_free(cert);
409
+ BIO_free(out);
410
+ }
411
+
412
+ return ret;
413
+ }
414
+ #else
415
+ static VALUE t_get_peer_cert (VALUE self UNUSED, VALUE signature UNUSED)
416
+ {
417
+ return Qnil;
418
+ }
419
+ #endif
420
+
421
+ /***************
422
+ t_get_cipher_bits
423
+ ***************/
424
+
425
+ #ifdef WITH_SSL
426
+ static VALUE t_get_cipher_bits (VALUE self UNUSED, VALUE signature)
427
+ {
428
+ int bits = evma_get_cipher_bits (NUM2BSIG (signature));
429
+ if (bits == -1)
430
+ return Qnil;
431
+ return INT2NUM (bits);
432
+ }
433
+ #else
434
+ static VALUE t_get_cipher_bits (VALUE self UNUSED, VALUE signature UNUSED)
435
+ {
436
+ return Qnil;
437
+ }
438
+ #endif
439
+
440
+ /***************
441
+ t_get_cipher_name
442
+ ***************/
443
+
444
+ #ifdef WITH_SSL
445
+ static VALUE t_get_cipher_name (VALUE self UNUSED, VALUE signature)
446
+ {
447
+ const char *protocol = evma_get_cipher_name (NUM2BSIG (signature));
448
+ if (protocol)
449
+ return rb_str_new2 (protocol);
450
+
451
+ return Qnil;
452
+ }
453
+ #else
454
+ static VALUE t_get_cipher_name (VALUE self UNUSED, VALUE signature UNUSED)
455
+ {
456
+ return Qnil;
457
+ }
458
+ #endif
459
+
460
+ /***************
461
+ t_get_cipher_protocol
462
+ ***************/
463
+
464
+ #ifdef WITH_SSL
465
+ static VALUE t_get_cipher_protocol (VALUE self UNUSED, VALUE signature)
466
+ {
467
+ const char *cipher = evma_get_cipher_protocol (NUM2BSIG (signature));
468
+ if (cipher)
469
+ return rb_str_new2 (cipher);
470
+
471
+ return Qnil;
472
+ }
473
+ #else
474
+ static VALUE t_get_cipher_protocol (VALUE self UNUSED, VALUE signature UNUSED)
475
+ {
476
+ return Qnil;
477
+ }
478
+ #endif
479
+
480
+ /***************
481
+ t_get_sni_hostname
482
+ ***************/
483
+
484
+ #ifdef WITH_SSL
485
+ static VALUE t_get_sni_hostname (VALUE self UNUSED, VALUE signature)
486
+ {
487
+ const char *sni_hostname = evma_get_sni_hostname (NUM2BSIG (signature));
488
+ if (sni_hostname)
489
+ return rb_str_new2 (sni_hostname);
490
+
491
+ return Qnil;
492
+ }
493
+ #else
494
+ static VALUE t_get_sni_hostname (VALUE self UNUSED, VALUE signature UNUSED)
495
+ {
496
+ return Qnil;
497
+ }
498
+ #endif
499
+
500
+ /**************
501
+ t_get_peername
502
+ **************/
503
+
504
+ static VALUE t_get_peername (VALUE self UNUSED, VALUE signature)
505
+ {
506
+ char buf[1024];
507
+ socklen_t len = sizeof buf;
508
+ try {
509
+ if (evma_get_peername (NUM2BSIG (signature), (struct sockaddr*)buf, &len)) {
510
+ return rb_str_new (buf, len);
511
+ }
512
+ } catch (std::runtime_error e) {
513
+ rb_raise (rb_eRuntimeError, "%s", e.what());
514
+ }
515
+
516
+ return Qnil;
517
+ }
518
+
519
+ /**************
520
+ t_get_sockname
521
+ **************/
522
+
523
+ static VALUE t_get_sockname (VALUE self UNUSED, VALUE signature)
524
+ {
525
+ char buf[1024];
526
+ socklen_t len = sizeof buf;
527
+ try {
528
+ if (evma_get_sockname (NUM2BSIG (signature), (struct sockaddr*)buf, &len)) {
529
+ return rb_str_new (buf, len);
530
+ }
531
+ } catch (std::runtime_error e) {
532
+ rb_raise (rb_eRuntimeError, "%s", e.what());
533
+ }
534
+
535
+ return Qnil;
536
+ }
537
+
538
+ /********************
539
+ t_get_subprocess_pid
540
+ ********************/
541
+
542
+ static VALUE t_get_subprocess_pid (VALUE self UNUSED, VALUE signature)
543
+ {
544
+ pid_t pid;
545
+ if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
546
+ return INT2NUM (pid);
547
+ }
548
+
549
+ return Qnil;
550
+ }
551
+
552
+ /***********************
553
+ t_get_subprocess_status
554
+ ***********************/
555
+
556
+ static VALUE t_get_subprocess_status (VALUE self UNUSED, VALUE signature)
557
+ {
558
+ VALUE proc_status = Qnil;
559
+
560
+ int status;
561
+ pid_t pid;
562
+
563
+ if (evma_get_subprocess_status (NUM2BSIG (signature), &status)) {
564
+ if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
565
+
566
+ #ifdef IS_RUBY_3_OR_LATER
567
+ struct rb_process_status *data = NULL;
568
+
569
+ /* Defined to match static definition from MRI Ruby 3.0 process.c
570
+ *
571
+ * Older C++ compilers before GCC 8 don't allow static initialization of a
572
+ * struct without every field specified, so the definition here is at runtime
573
+ */
574
+ static rb_data_type_t rb_process_status_type;
575
+ rb_process_status_type.wrap_struct_name = "Process::Status";
576
+ rb_process_status_type.function.dfree = RUBY_DEFAULT_FREE;
577
+ rb_process_status_type.flags = RUBY_TYPED_FREE_IMMEDIATELY;
578
+
579
+ proc_status = TypedData_Make_Struct(rb_cProcessStatus, struct rb_process_status, &rb_process_status_type, data);
580
+ data->pid = pid;
581
+ data->status = status;
582
+ #else
583
+ proc_status = rb_obj_alloc(rb_cProcessStatus);
584
+ /* MRI Ruby uses hidden instance vars */
585
+ rb_ivar_set(proc_status, rb_intern_const("status"), INT2FIX(status));
586
+ rb_ivar_set(proc_status, rb_intern_const("pid"), INT2FIX(pid));
587
+ #endif
588
+
589
+ #ifdef RUBINIUS
590
+ /* Rubinius uses standard instance vars */
591
+ rb_iv_set(proc_status, "@pid", INT2FIX(pid));
592
+ if (WIFEXITED(status)) {
593
+ rb_iv_set(proc_status, "@status", INT2FIX(WEXITSTATUS(status)));
594
+ } else if (WIFSIGNALED(status)) {
595
+ rb_iv_set(proc_status, "@termsig", INT2FIX(WTERMSIG(status)));
596
+ } else if (WIFSTOPPED(status)) {
597
+ rb_iv_set(proc_status, "@stopsig", INT2FIX(WSTOPSIG(status)));
598
+ }
599
+ #endif
600
+ }
601
+ }
602
+ rb_obj_freeze(proc_status);
603
+ return proc_status;
604
+ }
605
+
606
+ /**********************
607
+ t_get_connection_count
608
+ **********************/
609
+
610
+ static VALUE t_get_connection_count (VALUE self UNUSED)
611
+ {
612
+ return INT2NUM(evma_get_connection_count());
613
+ }
614
+
615
+ /*****************************
616
+ t_get_comm_inactivity_timeout
617
+ *****************************/
618
+
619
+ static VALUE t_get_comm_inactivity_timeout (VALUE self UNUSED, VALUE signature)
620
+ {
621
+ return rb_float_new(evma_get_comm_inactivity_timeout(NUM2BSIG (signature)));
622
+ }
623
+
624
+ /*****************************
625
+ t_set_comm_inactivity_timeout
626
+ *****************************/
627
+
628
+ static VALUE t_set_comm_inactivity_timeout (VALUE self UNUSED, VALUE signature, VALUE timeout)
629
+ {
630
+ float ti = RFLOAT_VALUE(timeout);
631
+ if (evma_set_comm_inactivity_timeout(NUM2BSIG(signature), ti)) {
632
+ return Qtrue;
633
+ }
634
+ return Qfalse;
635
+ }
636
+
637
+ /*****************************
638
+ t_get_pending_connect_timeout
639
+ *****************************/
640
+
641
+ static VALUE t_get_pending_connect_timeout (VALUE self UNUSED, VALUE signature)
642
+ {
643
+ return rb_float_new(evma_get_pending_connect_timeout(NUM2BSIG (signature)));
644
+ }
645
+
646
+ /*****************************
647
+ t_set_pending_connect_timeout
648
+ *****************************/
649
+
650
+ static VALUE t_set_pending_connect_timeout (VALUE self UNUSED, VALUE signature, VALUE timeout)
651
+ {
652
+ float ti = RFLOAT_VALUE(timeout);
653
+ if (evma_set_pending_connect_timeout(NUM2BSIG(signature), ti)) {
654
+ return Qtrue;
655
+ }
656
+ return Qfalse;
657
+ }
658
+
659
+ /***************
660
+ t_send_datagram
661
+ ***************/
662
+
663
+ static VALUE t_send_datagram (VALUE self UNUSED, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
664
+ {
665
+ int b = evma_send_datagram (NUM2BSIG (signature), StringValuePtr (data), FIX2INT (data_length), StringValueCStr(address), FIX2INT(port));
666
+ if (b < 0)
667
+ rb_raise (EM_eConnectionError, "%s", "error in sending datagram"); // FIXME: this could be more specific.
668
+ return INT2NUM (b);
669
+ }
670
+
671
+
672
+ /******************
673
+ t_close_connection
674
+ ******************/
675
+
676
+ static VALUE t_close_connection (VALUE self UNUSED, VALUE signature, VALUE after_writing)
677
+ {
678
+ evma_close_connection (NUM2BSIG (signature), ((after_writing == Qtrue) ? 1 : 0));
679
+ return Qnil;
680
+ }
681
+
682
+ /********************************
683
+ t_report_connection_error_status
684
+ ********************************/
685
+
686
+ static VALUE t_report_connection_error_status (VALUE self UNUSED, VALUE signature)
687
+ {
688
+ int b = evma_report_connection_error_status (NUM2BSIG (signature));
689
+ return INT2NUM (b);
690
+ }
691
+
692
+
693
+
694
+ /****************
695
+ t_connect_server
696
+ ****************/
697
+
698
+ static VALUE t_connect_server (VALUE self UNUSED, VALUE server, VALUE port)
699
+ {
700
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
701
+ // Specifically, if the value of port comes in as a string rather than an integer,
702
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
703
+
704
+ try {
705
+ const uintptr_t f = evma_connect_to_server (NULL, 0, StringValueCStr(server), NUM2INT(port));
706
+ if (!f)
707
+ rb_raise (EM_eConnectionError, "%s", "no connection");
708
+ return BSIG2NUM (f);
709
+ } catch (std::runtime_error e) {
710
+ rb_raise (EM_eConnectionError, "%s", e.what());
711
+ }
712
+ return Qnil;
713
+ }
714
+
715
+ /*********************
716
+ t_bind_connect_server
717
+ *********************/
718
+
719
+ static VALUE t_bind_connect_server (VALUE self UNUSED, VALUE bind_addr, VALUE bind_port, VALUE server, VALUE port)
720
+ {
721
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
722
+ // Specifically, if the value of port comes in as a string rather than an integer,
723
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
724
+
725
+ try {
726
+ const uintptr_t f = evma_connect_to_server (StringValueCStr(bind_addr), NUM2INT(bind_port), StringValueCStr(server), NUM2INT(port));
727
+ if (!f)
728
+ rb_raise (EM_eConnectionError, "%s", "no connection");
729
+ return BSIG2NUM (f);
730
+ } catch (std::runtime_error e) {
731
+ rb_raise (EM_eConnectionError, "%s", e.what());
732
+ }
733
+ return Qnil;
734
+ }
735
+
736
+ /*********************
737
+ t_connect_unix_server
738
+ *********************/
739
+
740
+ static VALUE t_connect_unix_server (VALUE self UNUSED, VALUE serversocket)
741
+ {
742
+ const uintptr_t f = evma_connect_to_unix_server (StringValueCStr(serversocket));
743
+ if (!f)
744
+ rb_raise (rb_eRuntimeError, "%s", "no connection");
745
+ return BSIG2NUM (f);
746
+ }
747
+
748
+ /***********
749
+ t_attach_fd
750
+ ***********/
751
+
752
+ static VALUE t_attach_fd (VALUE self UNUSED, VALUE file_descriptor, VALUE watch_mode)
753
+ {
754
+ const uintptr_t f = evma_attach_fd (NUM2INT(file_descriptor), watch_mode == Qtrue);
755
+ if (!f)
756
+ rb_raise (rb_eRuntimeError, "%s", "no connection");
757
+ return BSIG2NUM (f);
758
+ }
759
+
760
+ /***********
761
+ t_detach_fd
762
+ ***********/
763
+
764
+ static VALUE t_detach_fd (VALUE self UNUSED, VALUE signature)
765
+ {
766
+ return INT2NUM(evma_detach_fd (NUM2BSIG (signature)));
767
+ }
768
+
769
+ /*********************
770
+ t_get_file_descriptor
771
+ *********************/
772
+ static VALUE t_get_file_descriptor (VALUE self UNUSED, VALUE signature)
773
+ {
774
+ return INT2NUM(evma_get_file_descriptor (NUM2BSIG (signature)));
775
+ }
776
+
777
+ /**************
778
+ t_get_sock_opt
779
+ **************/
780
+
781
+ static VALUE t_get_sock_opt (VALUE self UNUSED, VALUE signature, VALUE lev, VALUE optname)
782
+ {
783
+ int fd = evma_get_file_descriptor (NUM2BSIG (signature));
784
+ int level = NUM2INT(lev), option = NUM2INT(optname);
785
+ socklen_t len = 128;
786
+ char buf[128];
787
+
788
+ if (getsockopt(fd, level, option, buf, &len) < 0)
789
+ rb_sys_fail("getsockopt");
790
+
791
+ return rb_str_new(buf, len);
792
+ }
793
+
794
+ /**************
795
+ t_set_sock_opt
796
+ **************/
797
+
798
+ static VALUE t_set_sock_opt (VALUE self UNUSED, VALUE signature, VALUE lev, VALUE optname, VALUE optval)
799
+ {
800
+ int fd = evma_get_file_descriptor (NUM2BSIG (signature));
801
+ int level = NUM2INT(lev), option = NUM2INT(optname);
802
+ int i;
803
+ const void *v;
804
+ socklen_t len;
805
+
806
+ switch (TYPE(optval)) {
807
+ case T_FIXNUM:
808
+ i = FIX2INT(optval);
809
+ goto numval;
810
+ case T_FALSE:
811
+ i = 0;
812
+ goto numval;
813
+ case T_TRUE:
814
+ i = 1;
815
+ numval:
816
+ v = (void*)&i; len = sizeof(i);
817
+ break;
818
+ default:
819
+ StringValue(optval);
820
+ v = RSTRING_PTR(optval);
821
+ len = RSTRING_LENINT(optval);
822
+ break;
823
+ }
824
+
825
+
826
+ if (setsockopt(fd, level, option, (char *)v, len) < 0)
827
+ rb_sys_fail("setsockopt");
828
+
829
+ return INT2FIX(0);
830
+ }
831
+
832
+ /********************
833
+ t_is_notify_readable
834
+ ********************/
835
+
836
+ static VALUE t_is_notify_readable (VALUE self UNUSED, VALUE signature)
837
+ {
838
+ return evma_is_notify_readable(NUM2BSIG (signature)) ? Qtrue : Qfalse;
839
+ }
840
+
841
+ /*********************
842
+ t_set_notify_readable
843
+ *********************/
844
+
845
+ static VALUE t_set_notify_readable (VALUE self UNUSED, VALUE signature, VALUE mode)
846
+ {
847
+ evma_set_notify_readable(NUM2BSIG(signature), mode == Qtrue);
848
+ return Qnil;
849
+ }
850
+
851
+ /********************
852
+ t_is_notify_readable
853
+ ********************/
854
+
855
+ static VALUE t_is_notify_writable (VALUE self UNUSED, VALUE signature)
856
+ {
857
+ return evma_is_notify_writable(NUM2BSIG (signature)) ? Qtrue : Qfalse;
858
+ }
859
+
860
+ /*********************
861
+ t_set_notify_writable
862
+ *********************/
863
+
864
+ static VALUE t_set_notify_writable (VALUE self UNUSED, VALUE signature, VALUE mode)
865
+ {
866
+ evma_set_notify_writable(NUM2BSIG (signature), mode == Qtrue);
867
+ return Qnil;
868
+ }
869
+
870
+ /*******
871
+ t_pause
872
+ *******/
873
+
874
+ static VALUE t_pause (VALUE self UNUSED, VALUE signature)
875
+ {
876
+ return evma_pause(NUM2BSIG (signature)) ? Qtrue : Qfalse;
877
+ }
878
+
879
+ /********
880
+ t_resume
881
+ ********/
882
+
883
+ static VALUE t_resume (VALUE self UNUSED, VALUE signature)
884
+ {
885
+ return evma_resume(NUM2BSIG (signature)) ? Qtrue : Qfalse;
886
+ }
887
+
888
+ /**********
889
+ t_paused_p
890
+ **********/
891
+
892
+ static VALUE t_paused_p (VALUE self UNUSED, VALUE signature)
893
+ {
894
+ return evma_is_paused(NUM2BSIG (signature)) ? Qtrue : Qfalse;
895
+ }
896
+
897
+ /*********************
898
+ t_num_close_scheduled
899
+ *********************/
900
+
901
+ static VALUE t_num_close_scheduled (VALUE self UNUSED)
902
+ {
903
+ return INT2FIX(evma_num_close_scheduled());
904
+ }
905
+
906
+ /*****************
907
+ t_open_udp_socket
908
+ *****************/
909
+
910
+ static VALUE t_open_udp_socket (VALUE self UNUSED, VALUE server, VALUE port)
911
+ {
912
+ const uintptr_t f = evma_open_datagram_socket (StringValueCStr(server), FIX2INT(port));
913
+ if (!f)
914
+ rb_raise (rb_eRuntimeError, "%s", "no datagram socket");
915
+ return BSIG2NUM(f);
916
+ }
917
+
918
+
919
+
920
+ /*****************
921
+ t_release_machine
922
+ *****************/
923
+
924
+ static VALUE t_release_machine (VALUE self UNUSED)
925
+ {
926
+ evma_release_library();
927
+ return Qnil;
928
+ }
929
+
930
+
931
+ /******
932
+ t_stop
933
+ ******/
934
+
935
+ static VALUE t_stop (VALUE self UNUSED)
936
+ {
937
+ evma_stop_machine();
938
+ return Qnil;
939
+ }
940
+
941
+ /******************
942
+ t_signal_loopbreak
943
+ ******************/
944
+
945
+ static VALUE t_signal_loopbreak (VALUE self UNUSED)
946
+ {
947
+ evma_signal_loopbreak();
948
+ return Qnil;
949
+ }
950
+
951
+ /**************
952
+ t_library_type
953
+ **************/
954
+
955
+ static VALUE t_library_type (VALUE self UNUSED)
956
+ {
957
+ return rb_eval_string (":extension");
958
+ }
959
+
960
+
961
+
962
+ /*******************
963
+ t_set_timer_quantum
964
+ *******************/
965
+
966
+ static VALUE t_set_timer_quantum (VALUE self UNUSED, VALUE interval)
967
+ {
968
+ evma_set_timer_quantum (FIX2INT (interval));
969
+ return Qnil;
970
+ }
971
+
972
+ /********************
973
+ t_get_max_timer_count
974
+ ********************/
975
+
976
+ static VALUE t_get_max_timer_count (VALUE self UNUSED)
977
+ {
978
+ return INT2FIX (evma_get_max_timer_count());
979
+ }
980
+
981
+ /********************
982
+ t_set_max_timer_count
983
+ ********************/
984
+
985
+ static VALUE t_set_max_timer_count (VALUE self UNUSED, VALUE ct)
986
+ {
987
+ evma_set_max_timer_count (FIX2INT (ct));
988
+ return Qnil;
989
+ }
990
+
991
+ /********************
992
+ t_get/set_simultaneous_accept_count
993
+ ********************/
994
+
995
+ static VALUE t_get_simultaneous_accept_count (VALUE self UNUSED)
996
+ {
997
+ return INT2FIX (evma_get_simultaneous_accept_count());
998
+ }
999
+
1000
+ static VALUE t_set_simultaneous_accept_count (VALUE self UNUSED, VALUE ct)
1001
+ {
1002
+ evma_set_simultaneous_accept_count (FIX2INT (ct));
1003
+ return Qnil;
1004
+ }
1005
+
1006
+ /***************
1007
+ t_setuid_string
1008
+ ***************/
1009
+
1010
+ static VALUE t_setuid_string (VALUE self UNUSED, VALUE username)
1011
+ {
1012
+ evma_setuid_string (StringValueCStr (username));
1013
+ return Qnil;
1014
+ }
1015
+
1016
+
1017
+
1018
+ /**************
1019
+ t_invoke_popen
1020
+ **************/
1021
+
1022
+ static VALUE t_invoke_popen (VALUE self UNUSED, VALUE cmd)
1023
+ {
1024
+ #ifdef OS_WIN32
1025
+ rb_raise (EM_eUnsupported, "popen is not available on this platform");
1026
+ #endif
1027
+
1028
+ int len = RARRAY_LEN(cmd);
1029
+ if (len >= 2048)
1030
+ rb_raise (rb_eRuntimeError, "%s", "too many arguments to popen");
1031
+ char *strings [2048];
1032
+ for (int i=0; i < len; i++) {
1033
+ VALUE ix = INT2FIX (i);
1034
+ VALUE s = rb_ary_aref (1, &ix, cmd);
1035
+ strings[i] = StringValueCStr (s);
1036
+ }
1037
+ strings[len] = NULL;
1038
+
1039
+ uintptr_t f = 0;
1040
+ try {
1041
+ f = evma_popen (strings);
1042
+ } catch (std::runtime_error e) {
1043
+ rb_raise (rb_eRuntimeError, "%s", e.what());
1044
+ }
1045
+ if (!f) {
1046
+ char *err = strerror (errno);
1047
+ char buf[100];
1048
+ memset (buf, 0, sizeof(buf));
1049
+ snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
1050
+ rb_raise (rb_eRuntimeError, "%s", buf);
1051
+ }
1052
+ return BSIG2NUM (f);
1053
+ }
1054
+
1055
+
1056
+ /***************
1057
+ t_read_keyboard
1058
+ ***************/
1059
+
1060
+ static VALUE t_read_keyboard (VALUE self UNUSED)
1061
+ {
1062
+ const uintptr_t f = evma_open_keyboard();
1063
+ if (!f)
1064
+ rb_raise (rb_eRuntimeError, "%s", "no keyboard reader");
1065
+ return BSIG2NUM (f);
1066
+ }
1067
+
1068
+
1069
+ /****************
1070
+ t_watch_filename
1071
+ ****************/
1072
+
1073
+ static VALUE t_watch_filename (VALUE self UNUSED, VALUE fname)
1074
+ {
1075
+ try {
1076
+ return BSIG2NUM(evma_watch_filename(StringValueCStr(fname)));
1077
+ } catch (std::runtime_error e) {
1078
+ rb_raise (EM_eUnsupported, "%s", e.what());
1079
+ }
1080
+ return Qnil;
1081
+ }
1082
+
1083
+
1084
+ /******************
1085
+ t_unwatch_filename
1086
+ ******************/
1087
+
1088
+ static VALUE t_unwatch_filename (VALUE self UNUSED, VALUE sig)
1089
+ {
1090
+ try {
1091
+ evma_unwatch_filename(NUM2BSIG (sig));
1092
+ } catch (std::runtime_error e) {
1093
+ rb_raise (EM_eInvalidSignature, "%s", e.what());
1094
+ }
1095
+
1096
+ return Qnil;
1097
+ }
1098
+
1099
+
1100
+ /***********
1101
+ t_watch_pid
1102
+ ***********/
1103
+
1104
+ static VALUE t_watch_pid (VALUE self UNUSED, VALUE pid)
1105
+ {
1106
+ try {
1107
+ return BSIG2NUM(evma_watch_pid(NUM2INT(pid)));
1108
+ } catch (std::runtime_error e) {
1109
+ rb_raise (EM_eUnsupported, "%s", e.what());
1110
+ }
1111
+ return Qnil;
1112
+ }
1113
+
1114
+
1115
+ /*************
1116
+ t_unwatch_pid
1117
+ *************/
1118
+
1119
+ static VALUE t_unwatch_pid (VALUE self UNUSED, VALUE sig)
1120
+ {
1121
+ evma_unwatch_pid(NUM2BSIG (sig));
1122
+ return Qnil;
1123
+ }
1124
+
1125
+
1126
+ /*************
1127
+ t_watch_only_p
1128
+ *************/
1129
+
1130
+ static VALUE t_watch_only_p (VALUE self UNUSED, VALUE signature)
1131
+ {
1132
+ return evma_is_watch_only(NUM2BSIG (signature)) ? Qtrue : Qfalse;
1133
+ }
1134
+
1135
+
1136
+ /**********
1137
+ t__epoll_p
1138
+ **********/
1139
+
1140
+ static VALUE t__epoll_p (VALUE self UNUSED)
1141
+ {
1142
+ #ifdef HAVE_EPOLL
1143
+ return Qtrue;
1144
+ #else
1145
+ return Qfalse;
1146
+ #endif
1147
+ }
1148
+
1149
+ /********
1150
+ t__epoll
1151
+ ********/
1152
+
1153
+ static VALUE t__epoll (VALUE self UNUSED)
1154
+ {
1155
+ if (t__epoll_p(self) == Qfalse)
1156
+ return Qfalse;
1157
+
1158
+ evma_set_epoll (1);
1159
+ return Qtrue;
1160
+ }
1161
+
1162
+ /***********
1163
+ t__epoll_set
1164
+ ***********/
1165
+
1166
+ static VALUE t__epoll_set (VALUE self, VALUE val)
1167
+ {
1168
+ if (t__epoll_p(self) == Qfalse && val == Qtrue)
1169
+ rb_raise (EM_eUnsupported, "%s", "epoll is not supported on this platform");
1170
+
1171
+ evma_set_epoll (val == Qtrue ? 1 : 0);
1172
+ return val;
1173
+ }
1174
+
1175
+
1176
+ /***********
1177
+ t__kqueue_p
1178
+ ***********/
1179
+
1180
+ static VALUE t__kqueue_p (VALUE self UNUSED)
1181
+ {
1182
+ #ifdef HAVE_KQUEUE
1183
+ return Qtrue;
1184
+ #else
1185
+ return Qfalse;
1186
+ #endif
1187
+ }
1188
+
1189
+ /*********
1190
+ t__kqueue
1191
+ *********/
1192
+
1193
+ static VALUE t__kqueue (VALUE self UNUSED)
1194
+ {
1195
+ if (t__kqueue_p(self) == Qfalse)
1196
+ return Qfalse;
1197
+
1198
+ evma_set_kqueue (1);
1199
+ return Qtrue;
1200
+ }
1201
+
1202
+ /*************
1203
+ t__kqueue_set
1204
+ *************/
1205
+
1206
+ static VALUE t__kqueue_set (VALUE self, VALUE val)
1207
+ {
1208
+ if (t__kqueue_p(self) == Qfalse && val == Qtrue)
1209
+ rb_raise (EM_eUnsupported, "%s", "kqueue is not supported on this platform");
1210
+
1211
+ evma_set_kqueue (val == Qtrue ? 1 : 0);
1212
+ return val;
1213
+ }
1214
+
1215
+
1216
+ /********
1217
+ t__ssl_p
1218
+ ********/
1219
+
1220
+ static VALUE t__ssl_p (VALUE self UNUSED)
1221
+ {
1222
+ #ifdef WITH_SSL
1223
+ return Qtrue;
1224
+ #else
1225
+ return Qfalse;
1226
+ #endif
1227
+ }
1228
+
1229
+ /********
1230
+ t_stopping
1231
+ ********/
1232
+
1233
+ static VALUE t_stopping ()
1234
+ {
1235
+ if (evma_stopping()) {
1236
+ return Qtrue;
1237
+ } else {
1238
+ return Qfalse;
1239
+ }
1240
+ }
1241
+
1242
+
1243
+ /****************
1244
+ t_send_file_data
1245
+ ****************/
1246
+
1247
+ static VALUE t_send_file_data (VALUE self UNUSED, VALUE signature, VALUE filename)
1248
+ {
1249
+
1250
+ /* The current implementation of evma_send_file_data_to_connection enforces a strict
1251
+ * upper limit on the file size it will transmit (currently 32K). The function returns
1252
+ * zero on success, -1 if the requested file exceeds its size limit, and a positive
1253
+ * number for other errors.
1254
+ * TODO: Positive return values are actually errno's, which is probably the wrong way to
1255
+ * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
1256
+ */
1257
+
1258
+ int b = evma_send_file_data_to_connection (NUM2BSIG (signature), StringValueCStr(filename));
1259
+ if (b == -1)
1260
+ rb_raise(rb_eRuntimeError, "%s", "File too large. send_file_data() supports files under 32k.");
1261
+ if (b > 0) {
1262
+ char *err = strerror (b);
1263
+ char buf[1024];
1264
+ memset (buf, 0, sizeof(buf));
1265
+ snprintf (buf, sizeof(buf)-1, ": %s %s", StringValueCStr(filename),(err?err:"???"));
1266
+
1267
+ rb_raise (rb_eIOError, "%s", buf);
1268
+ }
1269
+
1270
+ return INT2NUM (0);
1271
+ }
1272
+
1273
+
1274
+ /*******************
1275
+ t_set_rlimit_nofile
1276
+ *******************/
1277
+
1278
+ static VALUE t_set_rlimit_nofile (VALUE self UNUSED, VALUE arg)
1279
+ {
1280
+ int arg_int = (NIL_P(arg)) ? -1 : NUM2INT (arg);
1281
+ return INT2NUM (evma_set_rlimit_nofile (arg_int));
1282
+ }
1283
+
1284
+ /***************************
1285
+ conn_get_outbound_data_size
1286
+ ***************************/
1287
+
1288
+ static VALUE conn_get_outbound_data_size (VALUE self)
1289
+ {
1290
+ VALUE sig = rb_ivar_get (self, Intern_at_signature);
1291
+ return INT2NUM (evma_get_outbound_data_size (NUM2BSIG (sig)));
1292
+ }
1293
+
1294
+
1295
+ /******************************
1296
+ conn_associate_callback_target
1297
+ ******************************/
1298
+
1299
+ static VALUE conn_associate_callback_target (VALUE self UNUSED, VALUE sig UNUSED)
1300
+ {
1301
+ // No-op for the time being.
1302
+ return Qnil;
1303
+ }
1304
+
1305
+
1306
+ /******************
1307
+ t_enable_keepalive
1308
+ ******************/
1309
+
1310
+ static VALUE t_enable_keepalive (int argc, VALUE *argv, VALUE self)
1311
+ {
1312
+ VALUE idle, intvl, cnt;
1313
+ rb_scan_args(argc, argv, "03", &idle, &intvl, &cnt);
1314
+
1315
+ // In ed.cpp, skip 0 values before calling setsockopt
1316
+ int i_idle = NIL_P(idle) ? 0 : NUM2INT(idle);
1317
+ int i_intvl = NIL_P(intvl) ? 0 : NUM2INT(intvl);
1318
+ int i_cnt = NIL_P(cnt) ? 0 : NUM2INT(cnt);
1319
+
1320
+ VALUE sig = rb_ivar_get (self, Intern_at_signature);
1321
+ try {
1322
+ return INT2NUM (evma_enable_keepalive(NUM2ULONG(sig), i_idle, i_intvl, i_cnt));
1323
+ } catch (std::runtime_error e) {
1324
+ rb_raise (rb_eRuntimeError, "%s", e.what());
1325
+ }
1326
+ }
1327
+
1328
+ /******************
1329
+ t_disable_keepalive
1330
+ ******************/
1331
+
1332
+ static VALUE t_disable_keepalive (VALUE self)
1333
+ {
1334
+ VALUE sig = rb_ivar_get (self, Intern_at_signature);
1335
+ try {
1336
+ return INT2NUM (evma_disable_keepalive(NUM2ULONG(sig)));
1337
+ } catch (std::runtime_error e) {
1338
+ rb_raise (rb_eRuntimeError, "%s", e.what());
1339
+ }
1340
+ }
1341
+
1342
+ /***************
1343
+ t_get_loop_time
1344
+ ****************/
1345
+
1346
+ static VALUE t_get_loop_time (VALUE self UNUSED)
1347
+ {
1348
+ uint64_t current_time = evma_get_current_loop_time();
1349
+ if (current_time == 0) {
1350
+ return Qnil;
1351
+ }
1352
+
1353
+ // Generally the industry has moved to 64-bit time_t, this is just in case we're 32-bit time_t.
1354
+ if (sizeof(time_t) < 8 && current_time > INT_MAX) {
1355
+ return rb_funcall(rb_cTime, Intern_at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000));
1356
+ } else {
1357
+ return rb_time_new(current_time / 1000000, current_time % 1000000);
1358
+ }
1359
+ }
1360
+
1361
+
1362
+ /*************
1363
+ t_start_proxy
1364
+ **************/
1365
+
1366
+ static VALUE t_start_proxy (VALUE self UNUSED, VALUE from, VALUE to, VALUE bufsize, VALUE length)
1367
+ {
1368
+ try {
1369
+ evma_start_proxy(NUM2BSIG (from), NUM2BSIG (to), NUM2ULONG(bufsize), NUM2ULONG(length));
1370
+ } catch (std::runtime_error e) {
1371
+ rb_raise (EM_eConnectionError, "%s", e.what());
1372
+ }
1373
+ return Qnil;
1374
+ }
1375
+
1376
+
1377
+ /************
1378
+ t_stop_proxy
1379
+ *************/
1380
+
1381
+ static VALUE t_stop_proxy (VALUE self UNUSED, VALUE from)
1382
+ {
1383
+ try{
1384
+ evma_stop_proxy(NUM2BSIG (from));
1385
+ } catch (std::runtime_error e) {
1386
+ rb_raise (EM_eConnectionError, "%s", e.what());
1387
+ }
1388
+ return Qnil;
1389
+ }
1390
+
1391
+ /***************
1392
+ t_proxied_bytes
1393
+ ****************/
1394
+
1395
+ static VALUE t_proxied_bytes (VALUE self UNUSED, VALUE from)
1396
+ {
1397
+ try{
1398
+ return BSIG2NUM(evma_proxied_bytes(NUM2BSIG (from)));
1399
+ } catch (std::runtime_error e) {
1400
+ rb_raise (EM_eConnectionError, "%s", e.what());
1401
+ }
1402
+ return Qnil;
1403
+ }
1404
+
1405
+ /***************
1406
+ t_get_idle_time
1407
+ ****************/
1408
+
1409
+ static VALUE t_get_idle_time (VALUE self UNUSED, VALUE from)
1410
+ {
1411
+ try{
1412
+ uint64_t current_time = evma_get_current_loop_time();
1413
+ uint64_t time = evma_get_last_activity_time(NUM2BSIG (from));
1414
+ if (current_time != 0 && time != 0) {
1415
+ if (time >= current_time)
1416
+ return BSIG2NUM(0);
1417
+ else {
1418
+ uint64_t diff = current_time - time;
1419
+ float seconds = diff / (1000.0*1000.0);
1420
+ return rb_float_new(seconds);
1421
+ }
1422
+ return Qnil;
1423
+ }
1424
+ } catch (std::runtime_error e) {
1425
+ rb_raise (EM_eConnectionError, "%s", e.what());
1426
+ }
1427
+ return Qnil;
1428
+ }
1429
+
1430
+ /************************
1431
+ t_get_heartbeat_interval
1432
+ *************************/
1433
+
1434
+ static VALUE t_get_heartbeat_interval (VALUE self UNUSED)
1435
+ {
1436
+ return rb_float_new(evma_get_heartbeat_interval());
1437
+ }
1438
+
1439
+
1440
+ /************************
1441
+ t_set_heartbeat_interval
1442
+ *************************/
1443
+
1444
+ static VALUE t_set_heartbeat_interval (VALUE self UNUSED, VALUE interval)
1445
+ {
1446
+ float iv = RFLOAT_VALUE(interval);
1447
+ if (evma_set_heartbeat_interval(iv))
1448
+ return Qtrue;
1449
+ return Qfalse;
1450
+ }
1451
+
1452
+
1453
+ /*********************
1454
+ Init_rubyeventmachine
1455
+ *********************/
1456
+
1457
+ extern "C" void Init_rubyeventmachine()
1458
+ {
1459
+ // Lookup Process::Status for get_subprocess_status
1460
+ VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
1461
+ rb_cProcessStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
1462
+
1463
+ // Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
1464
+ Intern_at_signature = rb_intern ("@signature");
1465
+ Intern_at_timers = rb_intern ("@timers");
1466
+ Intern_at_conns = rb_intern ("@conns");
1467
+ Intern_at_error_handler = rb_intern("@error_handler");
1468
+
1469
+ Intern_event_callback = rb_intern ("event_callback");
1470
+ Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
1471
+ Intern_delete = rb_intern ("delete");
1472
+ Intern_call = rb_intern ("call");
1473
+ Intern_at = rb_intern("at");
1474
+ Intern_receive_data = rb_intern ("receive_data");
1475
+ Intern_ssl_handshake_completed = rb_intern ("ssl_handshake_completed");
1476
+ Intern_ssl_verify_peer = rb_intern ("ssl_verify_peer");
1477
+ Intern_notify_readable = rb_intern ("notify_readable");
1478
+ Intern_notify_writable = rb_intern ("notify_writable");
1479
+ Intern_proxy_target_unbound = rb_intern ("proxy_target_unbound");
1480
+ Intern_proxy_completed = rb_intern ("proxy_completed");
1481
+ Intern_connection_completed = rb_intern ("connection_completed");
1482
+
1483
+ // INCOMPLETE, we need to define class Connections inside module EventMachine
1484
+ // run_machine and run_machine_without_threads are now identical.
1485
+ // Must deprecate the without_threads variant.
1486
+ EmModule = rb_define_module ("EventMachine");
1487
+ EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);
1488
+
1489
+ rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eRuntimeError);
1490
+ EM_eConnectionError = rb_define_class_under (EmModule, "ConnectionError", rb_eRuntimeError);
1491
+ EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
1492
+ EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
1493
+ EM_eUnsupported = rb_define_class_under (EmModule, "Unsupported", rb_eRuntimeError);
1494
+ EM_eInvalidSignature = rb_define_class_under (EmModule, "InvalidSignature", rb_eRuntimeError);
1495
+ EM_eInvalidPrivateKey = rb_define_class_under (EmModule, "InvalidPrivateKey", rb_eRuntimeError);
1496
+
1497
+ rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
1498
+ rb_define_module_function (EmModule, "run_machine_once", (VALUE(*)(...))t_run_machine_once, 0);
1499
+ rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine, 0);
1500
+ rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine, 0);
1501
+ rb_define_module_function (EmModule, "get_timer_count", (VALUE(*)(...))t_get_timer_count, 0);
1502
+ rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
1503
+ rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
1504
+ rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
1505
+ rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
1506
+ rb_define_module_function (EmModule, "attach_sd", (VALUE(*)(...))t_attach_sd, 1);
1507
+ rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 13);
1508
+ rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
1509
+ rb_define_module_function (EmModule, "get_peer_cert", (VALUE(*)(...))t_get_peer_cert, 1);
1510
+ rb_define_module_function (EmModule, "get_cipher_bits", (VALUE(*)(...))t_get_cipher_bits, 1);
1511
+ rb_define_module_function (EmModule, "get_cipher_name", (VALUE(*)(...))t_get_cipher_name, 1);
1512
+ rb_define_module_function (EmModule, "get_cipher_protocol", (VALUE(*)(...))t_get_cipher_protocol, 1);
1513
+ rb_define_module_function (EmModule, "get_sni_hostname", (VALUE(*)(...))t_get_sni_hostname, 1);
1514
+ rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
1515
+ rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
1516
+ rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
1517
+ rb_define_module_function (EmModule, "report_connection_error_status", (VALUE(*)(...))t_report_connection_error_status, 1);
1518
+ rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
1519
+ rb_define_module_function (EmModule, "bind_connect_server", (VALUE(*)(...))t_bind_connect_server, 4);
1520
+ rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);
1521
+
1522
+ rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 2);
1523
+ rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
1524
+ rb_define_module_function (EmModule, "get_file_descriptor", (VALUE (*)(...))t_get_file_descriptor, 1);
1525
+ rb_define_module_function (EmModule, "get_sock_opt", (VALUE (*)(...))t_get_sock_opt, 3);
1526
+ rb_define_module_function (EmModule, "set_sock_opt", (VALUE (*)(...))t_set_sock_opt, 4);
1527
+ rb_define_module_function (EmModule, "set_notify_readable", (VALUE (*)(...))t_set_notify_readable, 2);
1528
+ rb_define_module_function (EmModule, "set_notify_writable", (VALUE (*)(...))t_set_notify_writable, 2);
1529
+ rb_define_module_function (EmModule, "is_notify_readable", (VALUE (*)(...))t_is_notify_readable, 1);
1530
+ rb_define_module_function (EmModule, "is_notify_writable", (VALUE (*)(...))t_is_notify_writable, 1);
1531
+
1532
+ rb_define_module_function (EmModule, "pause_connection", (VALUE (*)(...))t_pause, 1);
1533
+ rb_define_module_function (EmModule, "resume_connection", (VALUE (*)(...))t_resume, 1);
1534
+ rb_define_module_function (EmModule, "connection_paused?", (VALUE (*)(...))t_paused_p, 1);
1535
+ rb_define_module_function (EmModule, "num_close_scheduled", (VALUE (*)(...))t_num_close_scheduled, 0);
1536
+
1537
+ rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 4);
1538
+ rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
1539
+ rb_define_module_function (EmModule, "get_proxied_bytes", (VALUE (*)(...))t_proxied_bytes, 1);
1540
+
1541
+ rb_define_module_function (EmModule, "watch_filename", (VALUE (*)(...))t_watch_filename, 1);
1542
+ rb_define_module_function (EmModule, "unwatch_filename", (VALUE (*)(...))t_unwatch_filename, 1);
1543
+
1544
+ rb_define_module_function (EmModule, "watch_pid", (VALUE (*)(...))t_watch_pid, 1);
1545
+ rb_define_module_function (EmModule, "unwatch_pid", (VALUE (*)(...))t_unwatch_pid, 1);
1546
+ rb_define_module_function (EmModule, "watch_only?", (VALUE (*)(...))t_watch_only_p, 1);
1547
+
1548
+ rb_define_module_function (EmModule, "current_time", (VALUE(*)(...))t_get_loop_time, 0);
1549
+
1550
+ rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
1551
+ rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
1552
+ rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
1553
+ rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
1554
+ rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
1555
+ rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
1556
+ rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
1557
+ rb_define_module_function (EmModule, "get_max_timer_count", (VALUE(*)(...))t_get_max_timer_count, 0);
1558
+ rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
1559
+ rb_define_module_function (EmModule, "get_simultaneous_accept_count", (VALUE(*)(...))t_get_simultaneous_accept_count, 0);
1560
+ rb_define_module_function (EmModule, "set_simultaneous_accept_count", (VALUE(*)(...))t_set_simultaneous_accept_count, 1);
1561
+ rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
1562
+ rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
1563
+ rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
1564
+ rb_define_module_function (EmModule, "get_heartbeat_interval", (VALUE(*)(...))t_get_heartbeat_interval, 0);
1565
+ rb_define_module_function (EmModule, "set_heartbeat_interval", (VALUE(*)(...))t_set_heartbeat_interval, 1);
1566
+ rb_define_module_function (EmModule, "get_idle_time", (VALUE(*)(...))t_get_idle_time, 1);
1567
+
1568
+ rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
1569
+ rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
1570
+ rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
1571
+ rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
1572
+ rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
1573
+ rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
1574
+ rb_define_module_function (EmModule, "get_pending_connect_timeout", (VALUE(*)(...))t_get_pending_connect_timeout, 1);
1575
+ rb_define_module_function (EmModule, "set_pending_connect_timeout", (VALUE(*)(...))t_set_pending_connect_timeout, 2);
1576
+ rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
1577
+ rb_define_module_function (EmModule, "get_connection_count", (VALUE(*)(...))t_get_connection_count, 0);
1578
+
1579
+ rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
1580
+ rb_define_module_function (EmModule, "epoll=", (VALUE(*)(...))t__epoll_set, 1);
1581
+ rb_define_module_function (EmModule, "epoll?", (VALUE(*)(...))t__epoll_p, 0);
1582
+
1583
+ rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
1584
+ rb_define_module_function (EmModule, "kqueue=", (VALUE(*)(...))t__kqueue_set, 1);
1585
+ rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);
1586
+
1587
+ rb_define_module_function (EmModule, "ssl?", (VALUE(*)(...))t__ssl_p, 0);
1588
+ rb_define_module_function(EmModule, "stopping?",(VALUE(*)(...))t_stopping, 0);
1589
+
1590
+ rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
1591
+ rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
1592
+ rb_define_method (EmConnection, "enable_keepalive", (VALUE(*)(...))t_enable_keepalive, -1);
1593
+ rb_define_method (EmConnection, "disable_keepalive", (VALUE(*)(...))t_disable_keepalive, 0);
1594
+
1595
+ // Connection states
1596
+ rb_define_const (EmModule, "TimerFired", INT2NUM(EM_TIMER_FIRED ));
1597
+ rb_define_const (EmModule, "ConnectionData", INT2NUM(EM_CONNECTION_READ ));
1598
+ rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(EM_CONNECTION_UNBOUND ));
1599
+ rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(EM_CONNECTION_ACCEPTED ));
1600
+ rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(EM_CONNECTION_COMPLETED ));
1601
+ rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(EM_LOOPBREAK_SIGNAL ));
1602
+ rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(EM_CONNECTION_NOTIFY_READABLE));
1603
+ rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(EM_CONNECTION_NOTIFY_WRITABLE));
1604
+ rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(EM_SSL_HANDSHAKE_COMPLETED ));
1605
+ rb_define_const (EmModule, "SslVerify", INT2NUM(EM_SSL_VERIFY ));
1606
+ // EM_PROXY_TARGET_UNBOUND = 110,
1607
+ // EM_PROXY_COMPLETED = 111
1608
+
1609
+ // SSL Protocols
1610
+ rb_define_const (EmModule, "EM_PROTO_SSLv2", INT2NUM(EM_PROTO_SSLv2 ));
1611
+ rb_define_const (EmModule, "EM_PROTO_SSLv3", INT2NUM(EM_PROTO_SSLv3 ));
1612
+ rb_define_const (EmModule, "EM_PROTO_TLSv1", INT2NUM(EM_PROTO_TLSv1 ));
1613
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_1", INT2NUM(EM_PROTO_TLSv1_1));
1614
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_2", INT2NUM(EM_PROTO_TLSv1_2));
1615
+ #ifdef TLS1_3_VERSION
1616
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_3", INT2NUM(EM_PROTO_TLSv1_3));
1617
+ #endif
1618
+
1619
+ #ifdef OPENSSL_NO_SSL3
1620
+ /* True if SSL3 is not available */
1621
+ rb_define_const (EmModule, "OPENSSL_NO_SSL3", Qtrue);
1622
+ rb_define_const (EmModule, "OPENSSL_NO_SSL2", Qtrue);
1623
+ #else
1624
+ rb_define_const (EmModule, "OPENSSL_NO_SSL3", Qfalse);
1625
+ #ifdef OPENSSL_NO_SSL2
1626
+ rb_define_const (EmModule, "OPENSSL_NO_SSL2", Qtrue);
1627
+ #else
1628
+ rb_define_const (EmModule, "OPENSSL_NO_SSL2", Qfalse);
1629
+ #endif
1630
+ #endif
1631
+
1632
+ // OpenSSL Build / Runtime/Load versions
1633
+
1634
+ /* Version of OpenSSL that EventMachine was compiled with */
1635
+ rb_define_const(EmModule, "OPENSSL_VERSION", rb_str_new2(OPENSSL_VERSION_TEXT));
1636
+
1637
+ #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000
1638
+ /* Version of OpenSSL that EventMachine loaded with */
1639
+ rb_define_const(EmModule, "OPENSSL_LIBRARY_VERSION", rb_str_new2(OpenSSL_version(OPENSSL_VERSION)));
1640
+ #else
1641
+ rb_define_const(EmModule, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
1642
+ #endif
1643
+ }