smparkes-eventmachine 0.12.10

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