eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60

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 (116) hide show
  1. data/{docs/README → README} +21 -13
  2. data/Rakefile +14 -4
  3. data/docs/DEFERRABLES +0 -5
  4. data/docs/INSTALL +2 -4
  5. data/docs/LEGAL +1 -1
  6. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
  7. data/docs/PURE_RUBY +0 -2
  8. data/docs/RELEASE_NOTES +0 -2
  9. data/docs/SMTP +0 -7
  10. data/docs/SPAWNED_PROCESSES +0 -4
  11. data/docs/TODO +0 -2
  12. data/eventmachine.gemspec +41 -32
  13. data/examples/ex_channel.rb +43 -0
  14. data/examples/ex_queue.rb +2 -0
  15. data/examples/helper.rb +2 -0
  16. data/ext/cmain.cpp +685 -586
  17. data/ext/cplusplus.cpp +15 -6
  18. data/ext/ed.cpp +1732 -1522
  19. data/ext/ed.h +407 -380
  20. data/ext/em.cpp +2263 -1937
  21. data/ext/em.h +223 -186
  22. data/ext/eventmachine.h +111 -98
  23. data/ext/eventmachine_cpp.h +1 -0
  24. data/ext/extconf.rb +4 -0
  25. data/ext/kb.cpp +81 -82
  26. data/ext/pipe.cpp +349 -351
  27. data/ext/project.h +21 -0
  28. data/ext/rubymain.cpp +1047 -847
  29. data/ext/ssl.cpp +38 -1
  30. data/ext/ssl.h +5 -1
  31. data/java/src/com/rubyeventmachine/Application.java +7 -3
  32. data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
  33. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
  34. data/lib/{protocols → em}/buftok.rb +16 -5
  35. data/lib/em/callback.rb +26 -0
  36. data/lib/em/channel.rb +57 -0
  37. data/lib/em/connection.rb +505 -0
  38. data/lib/em/deferrable.rb +144 -165
  39. data/lib/em/file_watch.rb +54 -0
  40. data/lib/em/future.rb +24 -25
  41. data/lib/em/messages.rb +1 -1
  42. data/lib/em/process_watch.rb +44 -0
  43. data/lib/em/processes.rb +119 -113
  44. data/lib/em/protocols.rb +35 -0
  45. data/lib/em/protocols/header_and_content.rb +138 -0
  46. data/lib/em/protocols/httpclient.rb +263 -0
  47. data/lib/em/protocols/httpclient2.rb +582 -0
  48. data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
  49. data/lib/em/protocols/linetext2.rb +160 -0
  50. data/lib/{protocols → em/protocols}/memcache.rb +37 -7
  51. data/lib/em/protocols/object_protocol.rb +39 -0
  52. data/lib/em/protocols/postgres3.rb +247 -0
  53. data/lib/em/protocols/saslauth.rb +175 -0
  54. data/lib/em/protocols/smtpclient.rb +331 -0
  55. data/lib/em/protocols/smtpserver.rb +547 -0
  56. data/lib/em/protocols/stomp.rb +200 -0
  57. data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
  58. data/lib/em/queue.rb +61 -0
  59. data/lib/em/spawnable.rb +53 -56
  60. data/lib/em/streamer.rb +92 -74
  61. data/lib/em/timers.rb +55 -0
  62. data/lib/em/version.rb +3 -0
  63. data/lib/eventmachine.rb +1636 -1926
  64. data/lib/evma.rb +1 -1
  65. data/lib/jeventmachine.rb +106 -101
  66. data/lib/pr_eventmachine.rb +47 -36
  67. data/tasks/project.rake +2 -1
  68. data/tests/client.crt +31 -0
  69. data/tests/client.key +51 -0
  70. data/tests/test_attach.rb +18 -0
  71. data/tests/test_basic.rb +285 -231
  72. data/tests/test_channel.rb +63 -0
  73. data/tests/test_connection_count.rb +2 -2
  74. data/tests/test_epoll.rb +162 -163
  75. data/tests/test_errors.rb +36 -36
  76. data/tests/test_exc.rb +22 -25
  77. data/tests/test_file_watch.rb +49 -0
  78. data/tests/test_futures.rb +77 -93
  79. data/tests/test_hc.rb +2 -2
  80. data/tests/test_httpclient.rb +55 -52
  81. data/tests/test_httpclient2.rb +153 -155
  82. data/tests/test_inactivity_timeout.rb +30 -0
  83. data/tests/test_kb.rb +8 -9
  84. data/tests/test_ltp2.rb +274 -277
  85. data/tests/test_next_tick.rb +135 -109
  86. data/tests/test_object_protocol.rb +37 -0
  87. data/tests/test_process_watch.rb +48 -0
  88. data/tests/test_processes.rb +128 -95
  89. data/tests/test_proxy_connection.rb +92 -0
  90. data/tests/test_pure.rb +1 -5
  91. data/tests/test_queue.rb +44 -0
  92. data/tests/test_running.rb +9 -14
  93. data/tests/test_sasl.rb +32 -34
  94. data/tests/test_send_file.rb +175 -176
  95. data/tests/test_servers.rb +37 -41
  96. data/tests/test_smtpserver.rb +47 -55
  97. data/tests/test_spawn.rb +284 -291
  98. data/tests/test_ssl_args.rb +1 -1
  99. data/tests/test_ssl_methods.rb +1 -1
  100. data/tests/test_ssl_verify.rb +82 -0
  101. data/tests/test_timers.rb +81 -88
  102. data/tests/test_ud.rb +0 -7
  103. data/tests/testem.rb +1 -1
  104. metadata +52 -36
  105. data/lib/em/eventable.rb +0 -39
  106. data/lib/eventmachine_version.rb +0 -31
  107. data/lib/protocols/header_and_content.rb +0 -129
  108. data/lib/protocols/httpcli2.rb +0 -803
  109. data/lib/protocols/httpclient.rb +0 -270
  110. data/lib/protocols/linetext2.rb +0 -161
  111. data/lib/protocols/postgres.rb +0 -261
  112. data/lib/protocols/saslauth.rb +0 -179
  113. data/lib/protocols/smtpclient.rb +0 -308
  114. data/lib/protocols/smtpserver.rb +0 -556
  115. data/lib/protocols/stomp.rb +0 -153
  116. data/tests/test_eventables.rb +0 -77
data/ext/project.h CHANGED
@@ -102,6 +102,27 @@ using namespace std;
102
102
  #include <sys/queue.h>
103
103
  #endif
104
104
 
105
+ #ifdef HAVE_INOTIFY
106
+ #include <sys/inotify.h>
107
+ #endif
108
+
109
+ #ifdef HAVE_OLD_INOTIFY
110
+ #include <sys/syscall.h>
111
+ #include <linux/inotify.h>
112
+ static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
113
+ static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
114
+ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
115
+ #define HAVE_INOTIFY 1
116
+ #endif
117
+
118
+ #ifdef HAVE_INOTIFY
119
+ #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
120
+ #endif
121
+
122
+ #ifdef HAVE_WRITEV
123
+ #include <sys/uio.h>
124
+ #endif
125
+
105
126
  #include "binder.h"
106
127
  #include "em.h"
107
128
  #include "epoll.h"
data/ext/rubymain.cpp CHANGED
@@ -1,847 +1,1047 @@
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
-
25
-
26
- /*******
27
- Statics
28
- *******/
29
-
30
- static VALUE EmModule;
31
- static VALUE EmConnection;
32
-
33
- static VALUE EM_eUnknownTimerFired;
34
- static VALUE EM_eConnectionNotBound;
35
-
36
- static VALUE Intern_at_signature;
37
- static VALUE Intern_at_timers;
38
- static VALUE Intern_at_conns;
39
- static VALUE Intern_at_error_handler;
40
- static VALUE Intern_event_callback;
41
- static VALUE Intern_run_deferred_callbacks;
42
- static VALUE Intern_delete;
43
- static VALUE Intern_call;
44
- static VALUE Intern_receive_data;
45
- static VALUE Intern_ssl_handshake_completed;
46
- static VALUE Intern_notify_readable;
47
- static VALUE Intern_notify_writable;
48
-
49
- static VALUE rb_cProcStatus;
50
-
51
- struct em_event {
52
- const char *a1;
53
- int a2;
54
- const char *a3;
55
- int a4;
56
- };
57
-
58
- /****************
59
- t_event_callback
60
- ****************/
61
-
62
- static void event_callback (struct em_event* e)
63
- {
64
- const char *a1 = e->a1;
65
- int a2 = e->a2;
66
- const char *a3 = e->a3;
67
- int a4 = e->a4;
68
-
69
- if (a2 == EM_CONNECTION_READ) {
70
- VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
71
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
72
- if (q == Qnil)
73
- rb_raise (EM_eConnectionNotBound, "received %d bytes of data for unknown signature: %s", a4, a1);
74
- rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4));
75
- }
76
- else if (a2 == EM_CONNECTION_NOTIFY_READABLE) {
77
- VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
78
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
79
- if (q == Qnil)
80
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
81
- rb_funcall (q, Intern_notify_readable, 0);
82
- }
83
- else if (a2 == EM_CONNECTION_NOTIFY_WRITABLE) {
84
- VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
85
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
86
- if (q == Qnil)
87
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
88
- rb_funcall (q, Intern_notify_writable, 0);
89
- }
90
- else if (a2 == EM_LOOPBREAK_SIGNAL) {
91
- rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
92
- }
93
- else if (a2 == EM_TIMER_FIRED) {
94
- VALUE t = rb_ivar_get (EmModule, Intern_at_timers);
95
- VALUE q = rb_funcall (t, Intern_delete, 1, rb_str_new(a3, a4));
96
- if (q == Qnil)
97
- rb_raise (EM_eUnknownTimerFired, "no such timer: %s", a1);
98
- rb_funcall (q, Intern_call, 0);
99
- }
100
- else if (a2 == EM_SSL_HANDSHAKE_COMPLETED) {
101
- VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
102
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
103
- if (q == Qnil)
104
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
105
- rb_funcall (q, Intern_ssl_handshake_completed, 0);
106
- }
107
- else
108
- rb_funcall (EmModule, Intern_event_callback, 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
109
- }
110
-
111
- /*******************
112
- event_error_handler
113
- *******************/
114
-
115
- static void event_error_handler(VALUE unused, VALUE err)
116
- {
117
- VALUE error_handler = rb_ivar_get(EmModule, Intern_at_error_handler);
118
- rb_funcall (error_handler, Intern_call, 1, err);
119
- }
120
-
121
- /**********************
122
- event_callback_wrapper
123
- **********************/
124
-
125
- static void event_callback_wrapper (const char *a1, int a2, const char *a3, int a4)
126
- {
127
- struct em_event e;
128
- e.a1 = a1;
129
- e.a2 = a2;
130
- e.a3 = a3;
131
- e.a4 = a4;
132
-
133
- if (!rb_ivar_defined(EmModule, Intern_at_error_handler))
134
- event_callback(&e);
135
- else
136
- rb_rescue((VALUE (*)(ANYARGS))event_callback, (VALUE)&e, (VALUE (*)(ANYARGS))event_error_handler, Qnil);
137
- }
138
-
139
- /**************************
140
- t_initialize_event_machine
141
- **************************/
142
-
143
- static VALUE t_initialize_event_machine (VALUE self)
144
- {
145
- evma_initialize_library (event_callback_wrapper);
146
- return Qnil;
147
- }
148
-
149
-
150
-
151
- /*****************************
152
- t_run_machine_without_threads
153
- *****************************/
154
-
155
- static VALUE t_run_machine_without_threads (VALUE self)
156
- {
157
- evma_run_machine();
158
- return Qnil;
159
- }
160
-
161
-
162
- /*******************
163
- t_add_oneshot_timer
164
- *******************/
165
-
166
- static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
167
- {
168
- const char *f = evma_install_oneshot_timer (FIX2INT (interval));
169
- if (!f || !*f)
170
- rb_raise (rb_eRuntimeError, "no timer");
171
- return rb_str_new2 (f);
172
- }
173
-
174
-
175
- /**************
176
- t_start_server
177
- **************/
178
-
179
- static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
180
- {
181
- const char *f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
182
- if (!f || !*f)
183
- rb_raise (rb_eRuntimeError, "no acceptor");
184
- return rb_str_new2 (f);
185
- }
186
-
187
- /*************
188
- t_stop_server
189
- *************/
190
-
191
- static VALUE t_stop_server (VALUE self, VALUE signature)
192
- {
193
- evma_stop_tcp_server (StringValuePtr (signature));
194
- return Qnil;
195
- }
196
-
197
-
198
- /*******************
199
- t_start_unix_server
200
- *******************/
201
-
202
- static VALUE t_start_unix_server (VALUE self, VALUE filename)
203
- {
204
- const char *f = evma_create_unix_domain_server (StringValuePtr(filename));
205
- if (!f || !*f)
206
- rb_raise (rb_eRuntimeError, "no unix-domain acceptor");
207
- return rb_str_new2 (f);
208
- }
209
-
210
-
211
-
212
- /***********
213
- t_send_data
214
- ***********/
215
-
216
- static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_length)
217
- {
218
- int b = evma_send_data_to_connection (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length));
219
- return INT2NUM (b);
220
- }
221
-
222
-
223
- /***********
224
- t_start_tls
225
- ***********/
226
-
227
- static VALUE t_start_tls (VALUE self, VALUE signature)
228
- {
229
- evma_start_tls (StringValuePtr (signature));
230
- return Qnil;
231
- }
232
-
233
- /***************
234
- t_set_tls_parms
235
- ***************/
236
-
237
- static VALUE t_set_tls_parms (VALUE self, VALUE signature, VALUE privkeyfile, VALUE certchainfile)
238
- {
239
- /* set_tls_parms takes a series of positional arguments for specifying such things
240
- * as private keys and certificate chains.
241
- * It's expected that the parameter list will grow as we add more supported features.
242
- * ALL of these parameters are optional, and can be specified as empty or NULL strings.
243
- */
244
- evma_set_tls_parms (StringValuePtr (signature), StringValuePtr (privkeyfile), StringValuePtr (certchainfile) );
245
- return Qnil;
246
- }
247
-
248
- /***********
249
- t_get_peer_cert
250
- ***********/
251
-
252
- static VALUE t_get_peer_cert (VALUE self, VALUE signature)
253
- {
254
- VALUE ret = Qnil;
255
-
256
- #ifdef WITH_SSL
257
- X509 *cert = NULL;
258
- BUF_MEM *buf;
259
- BIO *out;
260
-
261
- cert = evma_get_peer_cert (StringValuePtr (signature));
262
-
263
- if (cert != NULL) {
264
- out = BIO_new(BIO_s_mem());
265
- PEM_write_bio_X509(out, cert);
266
- BIO_get_mem_ptr(out, &buf);
267
- ret = rb_str_new(buf->data, buf->length);
268
- X509_free(cert);
269
- BUF_MEM_free(buf);
270
- }
271
- #endif
272
-
273
- return ret;
274
- }
275
-
276
- /**************
277
- t_get_peername
278
- **************/
279
-
280
- static VALUE t_get_peername (VALUE self, VALUE signature)
281
- {
282
- struct sockaddr s;
283
- if (evma_get_peername (StringValuePtr (signature), &s)) {
284
- return rb_str_new ((const char*)&s, sizeof(s));
285
- }
286
-
287
- return Qnil;
288
- }
289
-
290
- /**************
291
- t_get_sockname
292
- **************/
293
-
294
- static VALUE t_get_sockname (VALUE self, VALUE signature)
295
- {
296
- struct sockaddr s;
297
- if (evma_get_sockname (StringValuePtr (signature), &s)) {
298
- return rb_str_new ((const char*)&s, sizeof(s));
299
- }
300
-
301
- return Qnil;
302
- }
303
-
304
- /********************
305
- t_get_subprocess_pid
306
- ********************/
307
-
308
- static VALUE t_get_subprocess_pid (VALUE self, VALUE signature)
309
- {
310
- pid_t pid;
311
- if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
312
- return INT2NUM (pid);
313
- }
314
-
315
- return Qnil;
316
- }
317
-
318
- /***********************
319
- t_get_subprocess_status
320
- ***********************/
321
-
322
- static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
323
- {
324
- VALUE proc_status = Qnil;
325
-
326
- int status;
327
- pid_t pid;
328
-
329
- if (evma_get_subprocess_status (StringValuePtr (signature), &status)) {
330
- if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
331
- proc_status = rb_obj_alloc(rb_cProcStatus);
332
- rb_iv_set(proc_status, "status", INT2FIX(status));
333
- rb_iv_set(proc_status, "pid", INT2FIX(pid));
334
- }
335
- }
336
-
337
- return proc_status;
338
- }
339
-
340
- /**********************
341
- t_get_connection_count
342
- **********************/
343
-
344
- static VALUE t_get_connection_count (VALUE self)
345
- {
346
- return INT2NUM(evma_get_connection_count());
347
- }
348
-
349
- /*****************************
350
- t_get_comm_inactivity_timeout
351
- *****************************/
352
-
353
- static VALUE t_get_comm_inactivity_timeout (VALUE self, VALUE signature)
354
- {
355
- int timeout;
356
- if (evma_get_comm_inactivity_timeout (StringValuePtr (signature), &timeout))
357
- return INT2FIX (timeout);
358
- return Qnil;
359
- }
360
-
361
- /*****************************
362
- t_set_comm_inactivity_timeout
363
- *****************************/
364
-
365
- static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
366
- {
367
- int ti = FIX2INT (timeout);
368
- if (evma_set_comm_inactivity_timeout (StringValuePtr (signature), &ti));
369
- return Qtrue;
370
- return Qnil;
371
- }
372
-
373
-
374
- /***************
375
- t_send_datagram
376
- ***************/
377
-
378
- static VALUE t_send_datagram (VALUE self, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
379
- {
380
- int b = evma_send_datagram (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length), StringValuePtr(address), FIX2INT(port));
381
- return INT2NUM (b);
382
- }
383
-
384
-
385
- /******************
386
- t_close_connection
387
- ******************/
388
-
389
- static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writing)
390
- {
391
- evma_close_connection (StringValuePtr (signature), ((after_writing == Qtrue) ? 1 : 0));
392
- return Qnil;
393
- }
394
-
395
- /********************************
396
- t_report_connection_error_status
397
- ********************************/
398
-
399
- static VALUE t_report_connection_error_status (VALUE self, VALUE signature)
400
- {
401
- int b = evma_report_connection_error_status (StringValuePtr (signature));
402
- return INT2NUM (b);
403
- }
404
-
405
-
406
-
407
- /****************
408
- t_connect_server
409
- ****************/
410
-
411
- static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
412
- {
413
- // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
414
- // Specifically, if the value of port comes in as a string rather than an integer,
415
- // NUM2INT will throw a type error, but FIX2INT will generate garbage.
416
-
417
- const char *f = evma_connect_to_server (StringValuePtr(server), NUM2INT(port));
418
- if (!f || !*f)
419
- rb_raise (rb_eRuntimeError, "no connection");
420
- return rb_str_new2 (f);
421
- }
422
-
423
- /*********************
424
- t_connect_unix_server
425
- *********************/
426
-
427
- static VALUE t_connect_unix_server (VALUE self, VALUE serversocket)
428
- {
429
- const char *f = evma_connect_to_unix_server (StringValuePtr(serversocket));
430
- if (!f || !*f)
431
- rb_raise (rb_eRuntimeError, "no connection");
432
- return rb_str_new2 (f);
433
- }
434
-
435
- /***********
436
- t_attach_fd
437
- ***********/
438
-
439
- static VALUE t_attach_fd (VALUE self, VALUE file_descriptor, VALUE read_mode, VALUE write_mode)
440
- {
441
- const char *f = evma_attach_fd (NUM2INT(file_descriptor), (read_mode == Qtrue) ? 1 : 0, (write_mode == Qtrue) ? 1 : 0);
442
- if (!f || !*f)
443
- rb_raise (rb_eRuntimeError, "no connection");
444
- return rb_str_new2 (f);
445
- }
446
-
447
- /***********
448
- t_detach_fd
449
- ***********/
450
-
451
- static VALUE t_detach_fd (VALUE self, VALUE signature)
452
- {
453
- return INT2NUM(evma_detach_fd (StringValuePtr(signature)));
454
- }
455
-
456
- /*****************
457
- t_open_udp_socket
458
- *****************/
459
-
460
- static VALUE t_open_udp_socket (VALUE self, VALUE server, VALUE port)
461
- {
462
- const char *f = evma_open_datagram_socket (StringValuePtr(server), FIX2INT(port));
463
- if (!f || !*f)
464
- rb_raise (rb_eRuntimeError, "no datagram socket");
465
- return rb_str_new2 (f);
466
- }
467
-
468
-
469
-
470
- /*****************
471
- t_release_machine
472
- *****************/
473
-
474
- static VALUE t_release_machine (VALUE self)
475
- {
476
- evma_release_library();
477
- return Qnil;
478
- }
479
-
480
-
481
- /******
482
- t_stop
483
- ******/
484
-
485
- static VALUE t_stop (VALUE self)
486
- {
487
- evma_stop_machine();
488
- return Qnil;
489
- }
490
-
491
- /******************
492
- t_signal_loopbreak
493
- ******************/
494
-
495
- static VALUE t_signal_loopbreak (VALUE self)
496
- {
497
- evma_signal_loopbreak();
498
- return Qnil;
499
- }
500
-
501
- /**************
502
- t_library_type
503
- **************/
504
-
505
- static VALUE t_library_type (VALUE self)
506
- {
507
- return rb_eval_string (":extension");
508
- }
509
-
510
-
511
-
512
- /*******************
513
- t_set_timer_quantum
514
- *******************/
515
-
516
- static VALUE t_set_timer_quantum (VALUE self, VALUE interval)
517
- {
518
- evma_set_timer_quantum (FIX2INT (interval));
519
- return Qnil;
520
- }
521
-
522
- /********************
523
- t_get_max_timer_count
524
- ********************/
525
-
526
- static VALUE t_get_max_timer_count (VALUE self)
527
- {
528
- return INT2FIX (evma_get_max_timer_count());
529
- }
530
-
531
- /********************
532
- t_set_max_timer_count
533
- ********************/
534
-
535
- static VALUE t_set_max_timer_count (VALUE self, VALUE ct)
536
- {
537
- evma_set_max_timer_count (FIX2INT (ct));
538
- return Qnil;
539
- }
540
-
541
- /***************
542
- t_setuid_string
543
- ***************/
544
-
545
- static VALUE t_setuid_string (VALUE self, VALUE username)
546
- {
547
- evma_setuid_string (StringValuePtr (username));
548
- return Qnil;
549
- }
550
-
551
-
552
-
553
- /*************
554
- t__write_file
555
- *************/
556
-
557
- static VALUE t__write_file (VALUE self, VALUE filename)
558
- {
559
- const char *f = evma__write_file (StringValuePtr (filename));
560
- if (!f || !*f)
561
- rb_raise (rb_eRuntimeError, "file not opened");
562
- return rb_str_new2 (f);
563
- }
564
-
565
- /**************
566
- t_invoke_popen
567
- **************/
568
-
569
- static VALUE t_invoke_popen (VALUE self, VALUE cmd)
570
- {
571
- // 1.8.7+
572
- #ifdef RARRAY_LEN
573
- int len = RARRAY_LEN(cmd);
574
- #else
575
- int len = RARRAY (cmd)->len;
576
- #endif
577
- if (len > 98)
578
- rb_raise (rb_eRuntimeError, "too many arguments to popen");
579
- char *strings [100];
580
- for (int i=0; i < len; i++) {
581
- VALUE ix = INT2FIX (i);
582
- VALUE s = rb_ary_aref (1, &ix, cmd);
583
- strings[i] = StringValuePtr (s);
584
- }
585
- strings[len] = NULL;
586
-
587
- const char *f = evma_popen (strings);
588
- if (!f || !*f) {
589
- char *err = strerror (errno);
590
- char buf[100];
591
- memset (buf, 0, sizeof(buf));
592
- snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
593
- rb_raise (rb_eRuntimeError, buf);
594
- }
595
- return rb_str_new2 (f);
596
- }
597
-
598
-
599
- /***************
600
- t_read_keyboard
601
- ***************/
602
-
603
- static VALUE t_read_keyboard (VALUE self)
604
- {
605
- const char *f = evma_open_keyboard();
606
- if (!f || !*f)
607
- rb_raise (rb_eRuntimeError, "no keyboard reader");
608
- return rb_str_new2 (f);
609
- }
610
-
611
-
612
- /********
613
- t__epoll
614
- ********/
615
-
616
- static VALUE t__epoll (VALUE self)
617
- {
618
- // Temporary.
619
- evma__epoll();
620
- return Qnil;
621
- }
622
-
623
- /**********
624
- t__epoll_p
625
- **********/
626
-
627
- static VALUE t__epoll_p (VALUE self)
628
- {
629
- #ifdef HAVE_EPOLL
630
- return Qtrue;
631
- #else
632
- return Qfalse;
633
- #endif
634
- }
635
-
636
-
637
- /*********
638
- t__kqueue
639
- *********/
640
-
641
- static VALUE t__kqueue (VALUE self)
642
- {
643
- // Temporary.
644
- evma__kqueue();
645
- return Qnil;
646
- }
647
-
648
- /***********
649
- t__kqueue_p
650
- ***********/
651
-
652
- static VALUE t__kqueue_p (VALUE self)
653
- {
654
- #ifdef HAVE_KQUEUE
655
- return Qtrue;
656
- #else
657
- return Qfalse;
658
- #endif
659
- }
660
-
661
-
662
- /****************
663
- t_send_file_data
664
- ****************/
665
-
666
- static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
667
- {
668
-
669
- /* The current implementation of evma_send_file_data_to_connection enforces a strict
670
- * upper limit on the file size it will transmit (currently 32K). The function returns
671
- * zero on success, -1 if the requested file exceeds its size limit, and a positive
672
- * number for other errors.
673
- * TODO: Positive return values are actually errno's, which is probably the wrong way to
674
- * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
675
- */
676
-
677
- int b = evma_send_file_data_to_connection (StringValuePtr(signature), StringValuePtr(filename));
678
- if (b == -1)
679
- rb_raise(rb_eRuntimeError, "File too large. send_file_data() supports files under 32k.");
680
- if (b > 0) {
681
- char *err = strerror (b);
682
- char buf[1024];
683
- memset (buf, 0, sizeof(buf));
684
- snprintf (buf, sizeof(buf)-1, ": %s %s", StringValuePtr(filename),(err?err:"???"));
685
-
686
- rb_raise (rb_eIOError, buf);
687
- }
688
-
689
- return INT2NUM (0);
690
- }
691
-
692
-
693
- /*******************
694
- t_set_rlimit_nofile
695
- *******************/
696
-
697
- static VALUE t_set_rlimit_nofile (VALUE self, VALUE arg)
698
- {
699
- arg = (NIL_P(arg)) ? -1 : NUM2INT (arg);
700
- return INT2NUM (evma_set_rlimit_nofile (arg));
701
- }
702
-
703
- /***************************
704
- conn_get_outbound_data_size
705
- ***************************/
706
-
707
- static VALUE conn_get_outbound_data_size (VALUE self)
708
- {
709
- VALUE sig = rb_ivar_get (self, Intern_at_signature);
710
- return INT2NUM (evma_get_outbound_data_size (StringValuePtr(sig)));
711
- }
712
-
713
-
714
- /******************************
715
- conn_associate_callback_target
716
- ******************************/
717
-
718
- static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
719
- {
720
- // No-op for the time being.
721
- return Qnil;
722
- }
723
-
724
-
725
- /***************
726
- t_get_loop_time
727
- ****************/
728
-
729
- static VALUE t_get_loop_time (VALUE self)
730
- {
731
- VALUE cTime = rb_path2class("Time");
732
- if (gCurrentLoopTime != 0) {
733
- return rb_funcall(cTime,
734
- rb_intern("at"),
735
- 1,
736
- INT2NUM(gCurrentLoopTime));
737
- }
738
- return Qnil;
739
- }
740
-
741
-
742
- /*********************
743
- Init_rubyeventmachine
744
- *********************/
745
-
746
- extern "C" void Init_rubyeventmachine()
747
- {
748
- // Lookup Process::Status for get_subprocess_status
749
- VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
750
- rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
751
-
752
- // Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
753
- Intern_at_signature = rb_intern ("@signature");
754
- Intern_at_timers = rb_intern ("@timers");
755
- Intern_at_conns = rb_intern ("@conns");
756
- Intern_at_error_handler = rb_intern("@error_handler");
757
-
758
- Intern_event_callback = rb_intern ("event_callback");
759
- Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
760
- Intern_delete = rb_intern ("delete");
761
- Intern_call = rb_intern ("call");
762
- Intern_receive_data = rb_intern ("receive_data");
763
- Intern_ssl_handshake_completed = rb_intern ("ssl_handshake_completed");
764
- Intern_notify_readable = rb_intern ("notify_readable");
765
- Intern_notify_writable = rb_intern ("notify_writable");
766
-
767
- // INCOMPLETE, we need to define class Connections inside module EventMachine
768
- // run_machine and run_machine_without_threads are now identical.
769
- // Must deprecate the without_threads variant.
770
- EmModule = rb_define_module ("EventMachine");
771
- EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);
772
-
773
- rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eException);
774
- EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
775
- EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
776
-
777
- rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
778
- rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
779
- rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine_without_threads, 0);
780
- rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
781
- rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
782
- rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
783
- rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
784
- rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 3);
785
- rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
786
- rb_define_module_function (EmModule, "get_peer_cert", (VALUE(*)(...))t_get_peer_cert, 1);
787
- rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
788
- rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
789
- rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
790
- rb_define_module_function (EmModule, "report_connection_error_status", (VALUE(*)(...))t_report_connection_error_status, 1);
791
- rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
792
- rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);
793
-
794
- rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 3);
795
- rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
796
-
797
- rb_define_module_function (EmModule, "current_time", (VALUE(*)(...))t_get_loop_time, 0);
798
-
799
- rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
800
- rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
801
- rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
802
- rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
803
- rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
804
- rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
805
- rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
806
- rb_define_module_function (EmModule, "get_max_timer_count", (VALUE(*)(...))t_get_max_timer_count, 0);
807
- rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
808
- rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
809
- rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
810
- rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
811
-
812
- // Provisional:
813
- rb_define_module_function (EmModule, "_write_file", (VALUE(*)(...))t__write_file, 1);
814
-
815
- rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
816
- rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
817
- rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
818
- rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
819
- rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
820
- rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
821
- rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
822
- rb_define_module_function (EmModule, "get_connection_count", (VALUE(*)(...))t_get_connection_count, 0);
823
-
824
- // Temporary:
825
- rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
826
- rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
827
-
828
- rb_define_module_function (EmModule, "epoll?", (VALUE(*)(...))t__epoll_p, 0);
829
- rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);
830
-
831
- rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
832
- rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
833
-
834
- rb_define_const (EmModule, "TimerFired", INT2NUM(100));
835
- rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
836
- rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(102));
837
- rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(103));
838
- rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(104));
839
- rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(105));
840
-
841
- rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(106));
842
- rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(107));
843
-
844
- rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(108));
845
-
846
- }
847
-
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
+ #ifndef RFLOAT_VALUE
25
+ #define RFLOAT_VALUE(arg) RFLOAT(arg)->value
26
+ #endif
27
+
28
+ /*******
29
+ Statics
30
+ *******/
31
+
32
+ static VALUE EmModule;
33
+ static VALUE EmConnection;
34
+
35
+ static VALUE EM_eUnknownTimerFired;
36
+ static VALUE EM_eConnectionNotBound;
37
+
38
+ static VALUE Intern_at_signature;
39
+ static VALUE Intern_at_timers;
40
+ static VALUE Intern_at_conns;
41
+ static VALUE Intern_at_error_handler;
42
+ static VALUE Intern_event_callback;
43
+ static VALUE Intern_run_deferred_callbacks;
44
+ static VALUE Intern_delete;
45
+ static VALUE Intern_call;
46
+ static VALUE Intern_receive_data;
47
+ static VALUE Intern_ssl_handshake_completed;
48
+ static VALUE Intern_ssl_verify_peer;
49
+ static VALUE Intern_notify_readable;
50
+ static VALUE Intern_notify_writable;
51
+ static VALUE Intern_proxy_target_unbound;
52
+
53
+ static VALUE rb_cProcStatus;
54
+
55
+ struct em_event {
56
+ const char *a1;
57
+ int a2;
58
+ const char *a3;
59
+ int a4;
60
+ };
61
+
62
+ /****************
63
+ t_event_callback
64
+ ****************/
65
+
66
+ static void event_callback (struct em_event* e)
67
+ {
68
+ const char *a1 = e->a1;
69
+ int a2 = e->a2;
70
+ const char *a3 = e->a3;
71
+ int a4 = e->a4;
72
+
73
+ if (a2 == EM_CONNECTION_READ) {
74
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
75
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
76
+ if (q == Qnil)
77
+ rb_raise (EM_eConnectionNotBound, "received %d bytes of data for unknown signature: %s", a4, a1);
78
+ rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4));
79
+ }
80
+ else if (a2 == EM_CONNECTION_NOTIFY_READABLE) {
81
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
82
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
83
+ if (q == Qnil)
84
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
85
+ rb_funcall (q, Intern_notify_readable, 0);
86
+ }
87
+ else if (a2 == EM_CONNECTION_NOTIFY_WRITABLE) {
88
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
89
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
90
+ if (q == Qnil)
91
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
92
+ rb_funcall (q, Intern_notify_writable, 0);
93
+ }
94
+ else if (a2 == EM_LOOPBREAK_SIGNAL) {
95
+ rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
96
+ }
97
+ else if (a2 == EM_TIMER_FIRED) {
98
+ VALUE t = rb_ivar_get (EmModule, Intern_at_timers);
99
+ VALUE q = rb_funcall (t, Intern_delete, 1, rb_str_new(a3, a4));
100
+ if (q == Qnil) {
101
+ rb_raise (EM_eUnknownTimerFired, "no such timer: %s", a1);
102
+ } else if (q == Qfalse) {
103
+ /* Timer Canceled */
104
+ } else {
105
+ rb_funcall (q, Intern_call, 0);
106
+ }
107
+ }
108
+ #ifdef WITH_SSL
109
+ else if (a2 == EM_SSL_HANDSHAKE_COMPLETED) {
110
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
111
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
112
+ if (q == Qnil)
113
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
114
+ rb_funcall (q, Intern_ssl_handshake_completed, 0);
115
+ }
116
+ else if (a2 == EM_SSL_VERIFY) {
117
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
118
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
119
+ if (q == Qnil)
120
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
121
+ VALUE r = rb_funcall (q, Intern_ssl_verify_peer, 1, rb_str_new(a3, a4));
122
+ if (RTEST(r))
123
+ evma_accept_ssl_peer (a1);
124
+ }
125
+ #endif
126
+ else if (a2 == EM_PROXY_TARGET_UNBOUND) {
127
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
128
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
129
+ if (q == Qnil)
130
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
131
+ rb_funcall (q, Intern_proxy_target_unbound, 0);
132
+ }
133
+ else
134
+ rb_funcall (EmModule, Intern_event_callback, 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
135
+ }
136
+
137
+ /*******************
138
+ event_error_handler
139
+ *******************/
140
+
141
+ static void event_error_handler(VALUE unused, VALUE err)
142
+ {
143
+ VALUE error_handler = rb_ivar_get(EmModule, Intern_at_error_handler);
144
+ rb_funcall (error_handler, Intern_call, 1, err);
145
+ }
146
+
147
+ /**********************
148
+ event_callback_wrapper
149
+ **********************/
150
+
151
+ static void event_callback_wrapper (const char *a1, int a2, const char *a3, int a4)
152
+ {
153
+ struct em_event e;
154
+ e.a1 = a1;
155
+ e.a2 = a2;
156
+ e.a3 = a3;
157
+ e.a4 = a4;
158
+
159
+ if (!rb_ivar_defined(EmModule, Intern_at_error_handler))
160
+ event_callback(&e);
161
+ else
162
+ rb_rescue((VALUE (*)(ANYARGS))event_callback, (VALUE)&e, (VALUE (*)(ANYARGS))event_error_handler, Qnil);
163
+ }
164
+
165
+ /**************************
166
+ t_initialize_event_machine
167
+ **************************/
168
+
169
+ static VALUE t_initialize_event_machine (VALUE self)
170
+ {
171
+ evma_initialize_library (event_callback_wrapper);
172
+ return Qnil;
173
+ }
174
+
175
+
176
+
177
+ /*****************************
178
+ t_run_machine_without_threads
179
+ *****************************/
180
+
181
+ static VALUE t_run_machine_without_threads (VALUE self)
182
+ {
183
+ evma_run_machine();
184
+ return Qnil;
185
+ }
186
+
187
+
188
+ /*******************
189
+ t_add_oneshot_timer
190
+ *******************/
191
+
192
+ static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
193
+ {
194
+ const char *f = evma_install_oneshot_timer (FIX2INT (interval));
195
+ if (!f || !*f)
196
+ rb_raise (rb_eRuntimeError, "no timer");
197
+ return rb_str_new2 (f);
198
+ }
199
+
200
+
201
+ /**************
202
+ t_start_server
203
+ **************/
204
+
205
+ static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
206
+ {
207
+ const char *f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
208
+ if (!f || !*f)
209
+ rb_raise (rb_eRuntimeError, "no acceptor");
210
+ return rb_str_new2 (f);
211
+ }
212
+
213
+ /*************
214
+ t_stop_server
215
+ *************/
216
+
217
+ static VALUE t_stop_server (VALUE self, VALUE signature)
218
+ {
219
+ evma_stop_tcp_server (StringValuePtr (signature));
220
+ return Qnil;
221
+ }
222
+
223
+
224
+ /*******************
225
+ t_start_unix_server
226
+ *******************/
227
+
228
+ static VALUE t_start_unix_server (VALUE self, VALUE filename)
229
+ {
230
+ const char *f = evma_create_unix_domain_server (StringValuePtr(filename));
231
+ if (!f || !*f)
232
+ rb_raise (rb_eRuntimeError, "no unix-domain acceptor");
233
+ return rb_str_new2 (f);
234
+ }
235
+
236
+
237
+
238
+ /***********
239
+ t_send_data
240
+ ***********/
241
+
242
+ static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_length)
243
+ {
244
+ int b = evma_send_data_to_connection (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length));
245
+ return INT2NUM (b);
246
+ }
247
+
248
+
249
+ /***********
250
+ t_start_tls
251
+ ***********/
252
+
253
+ static VALUE t_start_tls (VALUE self, VALUE signature)
254
+ {
255
+ evma_start_tls (StringValuePtr (signature));
256
+ return Qnil;
257
+ }
258
+
259
+ /***************
260
+ t_set_tls_parms
261
+ ***************/
262
+
263
+ static VALUE t_set_tls_parms (VALUE self, VALUE signature, VALUE privkeyfile, VALUE certchainfile, VALUE verify_peer)
264
+ {
265
+ /* set_tls_parms takes a series of positional arguments for specifying such things
266
+ * as private keys and certificate chains.
267
+ * It's expected that the parameter list will grow as we add more supported features.
268
+ * ALL of these parameters are optional, and can be specified as empty or NULL strings.
269
+ */
270
+ evma_set_tls_parms (StringValuePtr (signature), StringValuePtr (privkeyfile), StringValuePtr (certchainfile), (verify_peer == Qtrue ? 1 : 0));
271
+ return Qnil;
272
+ }
273
+
274
+ /***************
275
+ t_get_peer_cert
276
+ ***************/
277
+
278
+ static VALUE t_get_peer_cert (VALUE self, VALUE signature)
279
+ {
280
+ VALUE ret = Qnil;
281
+
282
+ #ifdef WITH_SSL
283
+ X509 *cert = NULL;
284
+ BUF_MEM *buf;
285
+ BIO *out;
286
+
287
+ cert = evma_get_peer_cert (StringValuePtr (signature));
288
+
289
+ if (cert != NULL) {
290
+ out = BIO_new(BIO_s_mem());
291
+ PEM_write_bio_X509(out, cert);
292
+ BIO_get_mem_ptr(out, &buf);
293
+ ret = rb_str_new(buf->data, buf->length);
294
+ X509_free(cert);
295
+ BUF_MEM_free(buf);
296
+ }
297
+ #endif
298
+
299
+ return ret;
300
+ }
301
+
302
+ /**************
303
+ t_get_peername
304
+ **************/
305
+
306
+ static VALUE t_get_peername (VALUE self, VALUE signature)
307
+ {
308
+ struct sockaddr s;
309
+ if (evma_get_peername (StringValuePtr (signature), &s)) {
310
+ return rb_str_new ((const char*)&s, sizeof(s));
311
+ }
312
+
313
+ return Qnil;
314
+ }
315
+
316
+ /**************
317
+ t_get_sockname
318
+ **************/
319
+
320
+ static VALUE t_get_sockname (VALUE self, VALUE signature)
321
+ {
322
+ struct sockaddr s;
323
+ if (evma_get_sockname (StringValuePtr (signature), &s)) {
324
+ return rb_str_new ((const char*)&s, sizeof(s));
325
+ }
326
+
327
+ return Qnil;
328
+ }
329
+
330
+ /********************
331
+ t_get_subprocess_pid
332
+ ********************/
333
+
334
+ static VALUE t_get_subprocess_pid (VALUE self, VALUE signature)
335
+ {
336
+ pid_t pid;
337
+ if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
338
+ return INT2NUM (pid);
339
+ }
340
+
341
+ return Qnil;
342
+ }
343
+
344
+ /***********************
345
+ t_get_subprocess_status
346
+ ***********************/
347
+
348
+ static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
349
+ {
350
+ VALUE proc_status = Qnil;
351
+
352
+ int status;
353
+ pid_t pid;
354
+
355
+ if (evma_get_subprocess_status (StringValuePtr (signature), &status)) {
356
+ if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
357
+ proc_status = rb_obj_alloc(rb_cProcStatus);
358
+ rb_iv_set(proc_status, "status", INT2FIX(status));
359
+ rb_iv_set(proc_status, "pid", INT2FIX(pid));
360
+ }
361
+ }
362
+
363
+ return proc_status;
364
+ }
365
+
366
+ /**********************
367
+ t_get_connection_count
368
+ **********************/
369
+
370
+ static VALUE t_get_connection_count (VALUE self)
371
+ {
372
+ return INT2NUM(evma_get_connection_count());
373
+ }
374
+
375
+ /*****************************
376
+ t_get_comm_inactivity_timeout
377
+ *****************************/
378
+
379
+ static VALUE t_get_comm_inactivity_timeout (VALUE self, VALUE signature)
380
+ {
381
+ return rb_float_new(evma_get_comm_inactivity_timeout(StringValuePtr(signature)));
382
+ }
383
+
384
+ /*****************************
385
+ t_set_comm_inactivity_timeout
386
+ *****************************/
387
+
388
+ static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
389
+ {
390
+ float ti = RFLOAT_VALUE(timeout);
391
+ if (evma_set_comm_inactivity_timeout (StringValuePtr (signature), ti));
392
+ return Qtrue;
393
+ return Qfalse;
394
+ }
395
+
396
+
397
+ /***************
398
+ t_send_datagram
399
+ ***************/
400
+
401
+ static VALUE t_send_datagram (VALUE self, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
402
+ {
403
+ int b = evma_send_datagram (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length), StringValuePtr(address), FIX2INT(port));
404
+ return INT2NUM (b);
405
+ }
406
+
407
+
408
+ /******************
409
+ t_close_connection
410
+ ******************/
411
+
412
+ static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writing)
413
+ {
414
+ evma_close_connection (StringValuePtr (signature), ((after_writing == Qtrue) ? 1 : 0));
415
+ return Qnil;
416
+ }
417
+
418
+ /********************************
419
+ t_report_connection_error_status
420
+ ********************************/
421
+
422
+ static VALUE t_report_connection_error_status (VALUE self, VALUE signature)
423
+ {
424
+ int b = evma_report_connection_error_status (StringValuePtr (signature));
425
+ return INT2NUM (b);
426
+ }
427
+
428
+
429
+
430
+ /****************
431
+ t_connect_server
432
+ ****************/
433
+
434
+ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
435
+ {
436
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
437
+ // Specifically, if the value of port comes in as a string rather than an integer,
438
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
439
+
440
+ const char *f = evma_connect_to_server (NULL, 0, StringValuePtr(server), NUM2INT(port));
441
+ if (!f || !*f)
442
+ rb_raise (rb_eRuntimeError, "no connection");
443
+ return rb_str_new2 (f);
444
+ }
445
+
446
+ /*********************
447
+ t_bind_connect_server
448
+ *********************/
449
+
450
+ static VALUE t_bind_connect_server (VALUE self, VALUE bind_addr, VALUE bind_port, VALUE server, VALUE port)
451
+ {
452
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
453
+ // Specifically, if the value of port comes in as a string rather than an integer,
454
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
455
+
456
+ const char *f;
457
+ try {
458
+ f = evma_connect_to_server (StringValuePtr(bind_addr), NUM2INT(bind_port), StringValuePtr(server), NUM2INT(port));
459
+ if (!f || !*f)
460
+ rb_raise (rb_eRuntimeError, "no connection");
461
+ } catch (std::runtime_error e) {
462
+ rb_sys_fail(e.what());
463
+ }
464
+ return rb_str_new2 (f);
465
+ }
466
+
467
+ /*********************
468
+ t_connect_unix_server
469
+ *********************/
470
+
471
+ static VALUE t_connect_unix_server (VALUE self, VALUE serversocket)
472
+ {
473
+ const char *f = evma_connect_to_unix_server (StringValuePtr(serversocket));
474
+ if (!f || !*f)
475
+ rb_raise (rb_eRuntimeError, "no connection");
476
+ return rb_str_new2 (f);
477
+ }
478
+
479
+ /***********
480
+ t_attach_fd
481
+ ***********/
482
+
483
+ static VALUE t_attach_fd (VALUE self, VALUE file_descriptor, VALUE read_mode, VALUE write_mode)
484
+ {
485
+ const char *f = evma_attach_fd (NUM2INT(file_descriptor), (read_mode == Qtrue) ? 1 : 0, (write_mode == Qtrue) ? 1 : 0);
486
+ if (!f || !*f)
487
+ rb_raise (rb_eRuntimeError, "no connection");
488
+ return rb_str_new2 (f);
489
+ }
490
+
491
+ /***********
492
+ t_detach_fd
493
+ ***********/
494
+
495
+ static VALUE t_detach_fd (VALUE self, VALUE signature)
496
+ {
497
+ return INT2NUM(evma_detach_fd (StringValuePtr(signature)));
498
+ }
499
+
500
+ /*****************
501
+ t_open_udp_socket
502
+ *****************/
503
+
504
+ static VALUE t_open_udp_socket (VALUE self, VALUE server, VALUE port)
505
+ {
506
+ const char *f = evma_open_datagram_socket (StringValuePtr(server), FIX2INT(port));
507
+ if (!f || !*f)
508
+ rb_raise (rb_eRuntimeError, "no datagram socket");
509
+ return rb_str_new2 (f);
510
+ }
511
+
512
+
513
+
514
+ /*****************
515
+ t_release_machine
516
+ *****************/
517
+
518
+ static VALUE t_release_machine (VALUE self)
519
+ {
520
+ evma_release_library();
521
+ return Qnil;
522
+ }
523
+
524
+
525
+ /******
526
+ t_stop
527
+ ******/
528
+
529
+ static VALUE t_stop (VALUE self)
530
+ {
531
+ evma_stop_machine();
532
+ return Qnil;
533
+ }
534
+
535
+ /******************
536
+ t_signal_loopbreak
537
+ ******************/
538
+
539
+ static VALUE t_signal_loopbreak (VALUE self)
540
+ {
541
+ evma_signal_loopbreak();
542
+ return Qnil;
543
+ }
544
+
545
+ /**************
546
+ t_library_type
547
+ **************/
548
+
549
+ static VALUE t_library_type (VALUE self)
550
+ {
551
+ return rb_eval_string (":extension");
552
+ }
553
+
554
+
555
+
556
+ /*******************
557
+ t_set_timer_quantum
558
+ *******************/
559
+
560
+ static VALUE t_set_timer_quantum (VALUE self, VALUE interval)
561
+ {
562
+ evma_set_timer_quantum (FIX2INT (interval));
563
+ return Qnil;
564
+ }
565
+
566
+ /********************
567
+ t_get_max_timer_count
568
+ ********************/
569
+
570
+ static VALUE t_get_max_timer_count (VALUE self)
571
+ {
572
+ return INT2FIX (evma_get_max_timer_count());
573
+ }
574
+
575
+ /********************
576
+ t_set_max_timer_count
577
+ ********************/
578
+
579
+ static VALUE t_set_max_timer_count (VALUE self, VALUE ct)
580
+ {
581
+ evma_set_max_timer_count (FIX2INT (ct));
582
+ return Qnil;
583
+ }
584
+
585
+ /***************
586
+ t_setuid_string
587
+ ***************/
588
+
589
+ static VALUE t_setuid_string (VALUE self, VALUE username)
590
+ {
591
+ evma_setuid_string (StringValuePtr (username));
592
+ return Qnil;
593
+ }
594
+
595
+
596
+
597
+ /*************
598
+ t__write_file
599
+ *************/
600
+
601
+ static VALUE t__write_file (VALUE self, VALUE filename)
602
+ {
603
+ const char *f = evma__write_file (StringValuePtr (filename));
604
+ if (!f || !*f)
605
+ rb_raise (rb_eRuntimeError, "file not opened");
606
+ return rb_str_new2 (f);
607
+ }
608
+
609
+ /**************
610
+ t_invoke_popen
611
+ **************/
612
+
613
+ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
614
+ {
615
+ // 1.8.7+
616
+ #ifdef RARRAY_LEN
617
+ int len = RARRAY_LEN(cmd);
618
+ #else
619
+ int len = RARRAY (cmd)->len;
620
+ #endif
621
+ if (len > 98)
622
+ rb_raise (rb_eRuntimeError, "too many arguments to popen");
623
+ char *strings [100];
624
+ for (int i=0; i < len; i++) {
625
+ VALUE ix = INT2FIX (i);
626
+ VALUE s = rb_ary_aref (1, &ix, cmd);
627
+ strings[i] = StringValuePtr (s);
628
+ }
629
+ strings[len] = NULL;
630
+
631
+ const char *f = evma_popen (strings);
632
+ if (!f || !*f) {
633
+ char *err = strerror (errno);
634
+ char buf[100];
635
+ memset (buf, 0, sizeof(buf));
636
+ snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
637
+ rb_raise (rb_eRuntimeError, buf);
638
+ }
639
+ return rb_str_new2 (f);
640
+ }
641
+
642
+
643
+ /***************
644
+ t_read_keyboard
645
+ ***************/
646
+
647
+ static VALUE t_read_keyboard (VALUE self)
648
+ {
649
+ const char *f = evma_open_keyboard();
650
+ if (!f || !*f)
651
+ rb_raise (rb_eRuntimeError, "no keyboard reader");
652
+ return rb_str_new2 (f);
653
+ }
654
+
655
+
656
+ /****************
657
+ t_watch_filename
658
+ ****************/
659
+
660
+ static VALUE t_watch_filename (VALUE self, VALUE fname)
661
+ {
662
+ try {
663
+ return rb_str_new2(evma_watch_filename(StringValuePtr(fname)));
664
+ } catch (std::runtime_error e) {
665
+ rb_sys_fail(e.what());
666
+ }
667
+ }
668
+
669
+
670
+ /******************
671
+ t_unwatch_filename
672
+ ******************/
673
+
674
+ static VALUE t_unwatch_filename (VALUE self, VALUE sig)
675
+ {
676
+ evma_unwatch_filename(StringValuePtr(sig));
677
+ return Qnil;
678
+ }
679
+
680
+
681
+ /***********
682
+ t_watch_pid
683
+ ***********/
684
+
685
+ static VALUE t_watch_pid (VALUE self, VALUE pid)
686
+ {
687
+ try {
688
+ return rb_str_new2(evma_watch_pid(NUM2INT(pid)));
689
+ } catch (std::runtime_error e) {
690
+ rb_sys_fail(e.what());
691
+ }
692
+ }
693
+
694
+
695
+ /*************
696
+ t_unwatch_pid
697
+ *************/
698
+
699
+ static VALUE t_unwatch_pid (VALUE self, VALUE sig)
700
+ {
701
+ evma_unwatch_pid(StringValuePtr(sig));
702
+ return Qnil;
703
+ }
704
+
705
+
706
+ /**********
707
+ t__epoll_p
708
+ **********/
709
+
710
+ static VALUE t__epoll_p (VALUE self)
711
+ {
712
+ #ifdef HAVE_EPOLL
713
+ return Qtrue;
714
+ #else
715
+ return Qfalse;
716
+ #endif
717
+ }
718
+
719
+ /********
720
+ t__epoll
721
+ ********/
722
+
723
+ static VALUE t__epoll (VALUE self)
724
+ {
725
+ if (t__epoll_p(self) == Qfalse)
726
+ return Qfalse;
727
+
728
+ evma_set_epoll (1);
729
+ return Qtrue;
730
+ }
731
+
732
+ /***********
733
+ t__epoll_set
734
+ ***********/
735
+
736
+ static VALUE t__epoll_set (VALUE self, VALUE val)
737
+ {
738
+ if (t__epoll_p(self) == Qfalse)
739
+ return Qfalse;
740
+
741
+ evma_set_epoll (val == Qtrue ? 1 : 0);
742
+ return val;
743
+ }
744
+
745
+
746
+ /***********
747
+ t__kqueue_p
748
+ ***********/
749
+
750
+ static VALUE t__kqueue_p (VALUE self)
751
+ {
752
+ #ifdef HAVE_KQUEUE
753
+ return Qtrue;
754
+ #else
755
+ return Qfalse;
756
+ #endif
757
+ }
758
+
759
+ /*********
760
+ t__kqueue
761
+ *********/
762
+
763
+ static VALUE t__kqueue (VALUE self)
764
+ {
765
+ if (t__kqueue_p(self) == Qfalse)
766
+ return Qfalse;
767
+
768
+ evma_set_kqueue (1);
769
+ return Qtrue;
770
+ }
771
+
772
+ /*************
773
+ t__kqueue_set
774
+ *************/
775
+
776
+ static VALUE t__kqueue_set (VALUE self, VALUE val)
777
+ {
778
+ if (t__kqueue_p(self) == Qfalse)
779
+ return Qfalse;
780
+
781
+ evma_set_kqueue (val == Qtrue ? 1 : 0);
782
+ return val;
783
+ }
784
+
785
+
786
+ /********
787
+ t__ssl_p
788
+ ********/
789
+
790
+ static VALUE t__ssl_p (VALUE self)
791
+ {
792
+ #ifdef WITH_SSL
793
+ return Qtrue;
794
+ #else
795
+ return Qfalse;
796
+ #endif
797
+ }
798
+
799
+
800
+ /****************
801
+ t_send_file_data
802
+ ****************/
803
+
804
+ static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
805
+ {
806
+
807
+ /* The current implementation of evma_send_file_data_to_connection enforces a strict
808
+ * upper limit on the file size it will transmit (currently 32K). The function returns
809
+ * zero on success, -1 if the requested file exceeds its size limit, and a positive
810
+ * number for other errors.
811
+ * TODO: Positive return values are actually errno's, which is probably the wrong way to
812
+ * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
813
+ */
814
+
815
+ int b = evma_send_file_data_to_connection (StringValuePtr(signature), StringValuePtr(filename));
816
+ if (b == -1)
817
+ rb_raise(rb_eRuntimeError, "File too large. send_file_data() supports files under 32k.");
818
+ if (b > 0) {
819
+ char *err = strerror (b);
820
+ char buf[1024];
821
+ memset (buf, 0, sizeof(buf));
822
+ snprintf (buf, sizeof(buf)-1, ": %s %s", StringValuePtr(filename),(err?err:"???"));
823
+
824
+ rb_raise (rb_eIOError, buf);
825
+ }
826
+
827
+ return INT2NUM (0);
828
+ }
829
+
830
+
831
+ /*******************
832
+ t_set_rlimit_nofile
833
+ *******************/
834
+
835
+ static VALUE t_set_rlimit_nofile (VALUE self, VALUE arg)
836
+ {
837
+ arg = (NIL_P(arg)) ? -1 : NUM2INT (arg);
838
+ return INT2NUM (evma_set_rlimit_nofile (arg));
839
+ }
840
+
841
+ /***************************
842
+ conn_get_outbound_data_size
843
+ ***************************/
844
+
845
+ static VALUE conn_get_outbound_data_size (VALUE self)
846
+ {
847
+ VALUE sig = rb_ivar_get (self, Intern_at_signature);
848
+ return INT2NUM (evma_get_outbound_data_size (StringValuePtr(sig)));
849
+ }
850
+
851
+
852
+ /******************************
853
+ conn_associate_callback_target
854
+ ******************************/
855
+
856
+ static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
857
+ {
858
+ // No-op for the time being.
859
+ return Qnil;
860
+ }
861
+
862
+
863
+ /***************
864
+ t_get_loop_time
865
+ ****************/
866
+
867
+ static VALUE t_get_loop_time (VALUE self)
868
+ {
869
+ VALUE cTime = rb_path2class("Time");
870
+ if (gCurrentLoopTime != 0) {
871
+ return rb_funcall(cTime,
872
+ rb_intern("at"),
873
+ 1,
874
+ INT2NUM(gCurrentLoopTime));
875
+ }
876
+ return Qnil;
877
+ }
878
+
879
+
880
+ /*************
881
+ t_start_proxy
882
+ **************/
883
+
884
+ static VALUE t_start_proxy (VALUE self, VALUE from, VALUE to)
885
+ {
886
+ evma_start_proxy(StringValuePtr(from), StringValuePtr(to));
887
+ return Qnil;
888
+ }
889
+
890
+
891
+ /************
892
+ t_stop_proxy
893
+ *************/
894
+
895
+ static VALUE t_stop_proxy (VALUE self, VALUE from)
896
+ {
897
+ evma_stop_proxy(StringValuePtr(from));
898
+ return Qnil;
899
+ }
900
+
901
+
902
+ /************************
903
+ t_get_heartbeat_interval
904
+ *************************/
905
+
906
+ static VALUE t_get_heartbeat_interval (VALUE self)
907
+ {
908
+ return rb_float_new(evma_get_heartbeat_interval());
909
+ }
910
+
911
+
912
+ /************************
913
+ t_set_heartbeat_interval
914
+ *************************/
915
+
916
+ static VALUE t_set_heartbeat_interval (VALUE self, VALUE interval)
917
+ {
918
+ float iv = RFLOAT_VALUE(interval);
919
+ if (evma_set_heartbeat_interval(iv))
920
+ return Qtrue;
921
+ return Qfalse;
922
+ }
923
+
924
+
925
+ /*********************
926
+ Init_rubyeventmachine
927
+ *********************/
928
+
929
+ extern "C" void Init_rubyeventmachine()
930
+ {
931
+ // Lookup Process::Status for get_subprocess_status
932
+ VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
933
+ rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
934
+
935
+ // Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
936
+ Intern_at_signature = rb_intern ("@signature");
937
+ Intern_at_timers = rb_intern ("@timers");
938
+ Intern_at_conns = rb_intern ("@conns");
939
+ Intern_at_error_handler = rb_intern("@error_handler");
940
+
941
+ Intern_event_callback = rb_intern ("event_callback");
942
+ Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
943
+ Intern_delete = rb_intern ("delete");
944
+ Intern_call = rb_intern ("call");
945
+ Intern_receive_data = rb_intern ("receive_data");
946
+ Intern_ssl_handshake_completed = rb_intern ("ssl_handshake_completed");
947
+ Intern_ssl_verify_peer = rb_intern ("ssl_verify_peer");
948
+ Intern_notify_readable = rb_intern ("notify_readable");
949
+ Intern_notify_writable = rb_intern ("notify_writable");
950
+ Intern_proxy_target_unbound = rb_intern ("proxy_target_unbound");
951
+
952
+ // INCOMPLETE, we need to define class Connections inside module EventMachine
953
+ // run_machine and run_machine_without_threads are now identical.
954
+ // Must deprecate the without_threads variant.
955
+ EmModule = rb_define_module ("EventMachine");
956
+ EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);
957
+
958
+ rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eException);
959
+ EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
960
+ EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
961
+
962
+ rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
963
+ rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
964
+ rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine_without_threads, 0);
965
+ rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
966
+ rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
967
+ rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
968
+ rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
969
+ rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 4);
970
+ rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
971
+ rb_define_module_function (EmModule, "get_peer_cert", (VALUE(*)(...))t_get_peer_cert, 1);
972
+ rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
973
+ rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
974
+ rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
975
+ rb_define_module_function (EmModule, "report_connection_error_status", (VALUE(*)(...))t_report_connection_error_status, 1);
976
+ rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
977
+ rb_define_module_function (EmModule, "bind_connect_server", (VALUE(*)(...))t_bind_connect_server, 4);
978
+ rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);
979
+
980
+ rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 3);
981
+ rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
982
+
983
+ rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 2);
984
+ rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
985
+
986
+ rb_define_module_function (EmModule, "watch_filename", (VALUE (*)(...))t_watch_filename, 1);
987
+ rb_define_module_function (EmModule, "unwatch_filename", (VALUE (*)(...))t_unwatch_filename, 1);
988
+
989
+ rb_define_module_function (EmModule, "watch_pid", (VALUE (*)(...))t_watch_pid, 1);
990
+ rb_define_module_function (EmModule, "unwatch_pid", (VALUE (*)(...))t_unwatch_pid, 1);
991
+
992
+ rb_define_module_function (EmModule, "current_time", (VALUE(*)(...))t_get_loop_time, 0);
993
+
994
+ rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
995
+ rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
996
+ rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
997
+ rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
998
+ rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
999
+ rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
1000
+ rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
1001
+ rb_define_module_function (EmModule, "get_max_timer_count", (VALUE(*)(...))t_get_max_timer_count, 0);
1002
+ rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
1003
+ rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
1004
+ rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
1005
+ rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
1006
+ rb_define_module_function (EmModule, "get_heartbeat_interval", (VALUE(*)(...))t_get_heartbeat_interval, 0);
1007
+ rb_define_module_function (EmModule, "set_heartbeat_interval", (VALUE(*)(...))t_set_heartbeat_interval, 1);
1008
+
1009
+ // Provisional:
1010
+ rb_define_module_function (EmModule, "_write_file", (VALUE(*)(...))t__write_file, 1);
1011
+
1012
+ rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
1013
+ rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
1014
+ rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
1015
+ rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
1016
+ rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
1017
+ rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
1018
+ rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
1019
+ rb_define_module_function (EmModule, "get_connection_count", (VALUE(*)(...))t_get_connection_count, 0);
1020
+
1021
+ rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
1022
+ rb_define_module_function (EmModule, "epoll=", (VALUE(*)(...))t__epoll_set, 1);
1023
+ rb_define_module_function (EmModule, "epoll?", (VALUE(*)(...))t__epoll_p, 0);
1024
+
1025
+ rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
1026
+ rb_define_module_function (EmModule, "kqueue=", (VALUE(*)(...))t__kqueue_set, 1);
1027
+ rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);
1028
+
1029
+ rb_define_module_function (EmModule, "ssl?", (VALUE(*)(...))t__ssl_p, 0);
1030
+
1031
+ rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
1032
+ rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
1033
+
1034
+ rb_define_const (EmModule, "TimerFired", INT2NUM(100));
1035
+ rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
1036
+ rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(102));
1037
+ rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(103));
1038
+ rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(104));
1039
+ rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(105));
1040
+
1041
+ rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(106));
1042
+ rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(107));
1043
+
1044
+ rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(108));
1045
+
1046
+ }
1047
+