brianmario-eventmachine 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/COPYING +60 -0
  2. data/DEFERRABLES +138 -0
  3. data/EPOLL +141 -0
  4. data/GNU +281 -0
  5. data/KEYBOARD +38 -0
  6. data/LEGAL +25 -0
  7. data/LIGHTWEIGHT_CONCURRENCY +72 -0
  8. data/PURE_RUBY +77 -0
  9. data/README +74 -0
  10. data/RELEASE_NOTES +96 -0
  11. data/SMTP +9 -0
  12. data/SPAWNED_PROCESSES +93 -0
  13. data/TODO +10 -0
  14. data/eventmachine.gemspec +15 -0
  15. data/ext/binder.cpp +126 -0
  16. data/ext/binder.h +48 -0
  17. data/ext/cmain.cpp +553 -0
  18. data/ext/cplusplus.cpp +172 -0
  19. data/ext/ed.cpp +1473 -0
  20. data/ext/ed.h +361 -0
  21. data/ext/em.cpp +1890 -0
  22. data/ext/em.h +170 -0
  23. data/ext/emwin.cpp +300 -0
  24. data/ext/emwin.h +94 -0
  25. data/ext/epoll.cpp +26 -0
  26. data/ext/epoll.h +25 -0
  27. data/ext/eventmachine.h +90 -0
  28. data/ext/eventmachine_cpp.h +94 -0
  29. data/ext/extconf.rb +203 -0
  30. data/ext/files.cpp +94 -0
  31. data/ext/files.h +65 -0
  32. data/ext/kb.cpp +368 -0
  33. data/ext/page.cpp +107 -0
  34. data/ext/page.h +51 -0
  35. data/ext/pipe.cpp +327 -0
  36. data/ext/project.h +119 -0
  37. data/ext/rubymain.cpp +678 -0
  38. data/ext/sigs.cpp +89 -0
  39. data/ext/sigs.h +32 -0
  40. data/ext/ssl.cpp +408 -0
  41. data/ext/ssl.h +86 -0
  42. data/lib/em/deferrable.rb +208 -0
  43. data/lib/em/eventable.rb +39 -0
  44. data/lib/em/future.rb +62 -0
  45. data/lib/em/messages.rb +66 -0
  46. data/lib/em/processes.rb +68 -0
  47. data/lib/em/spawnable.rb +88 -0
  48. data/lib/em/streamer.rb +112 -0
  49. data/lib/eventmachine.rb +1756 -0
  50. data/lib/eventmachine_version.rb +31 -0
  51. data/lib/evma.rb +32 -0
  52. data/lib/evma/callback.rb +32 -0
  53. data/lib/evma/container.rb +75 -0
  54. data/lib/evma/factory.rb +77 -0
  55. data/lib/evma/protocol.rb +87 -0
  56. data/lib/evma/reactor.rb +48 -0
  57. data/lib/jeventmachine.rb +132 -0
  58. data/lib/pr_eventmachine.rb +1011 -0
  59. data/lib/protocols/buftok.rb +127 -0
  60. data/lib/protocols/header_and_content.rb +129 -0
  61. data/lib/protocols/httpcli2.rb +784 -0
  62. data/lib/protocols/httpclient.rb +264 -0
  63. data/lib/protocols/line_and_text.rb +122 -0
  64. data/lib/protocols/linetext2.rb +163 -0
  65. data/lib/protocols/postgres.rb +261 -0
  66. data/lib/protocols/saslauth.rb +179 -0
  67. data/lib/protocols/smtpclient.rb +308 -0
  68. data/lib/protocols/smtpserver.rb +543 -0
  69. data/lib/protocols/stomp.rb +130 -0
  70. data/lib/protocols/tcptest.rb +57 -0
  71. data/setup.rb +1585 -0
  72. metadata +126 -0
@@ -0,0 +1,119 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: project.h
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
+
21
+ #ifndef __Project__H_
22
+ #define __Project__H_
23
+
24
+
25
+ #ifdef OS_WIN32
26
+ #pragma warning(disable:4786)
27
+ #endif
28
+
29
+ #include <iostream>
30
+ #include <map>
31
+ #include <set>
32
+ #include <vector>
33
+ #include <deque>
34
+ #include <string>
35
+ #include <sstream>
36
+ #include <stdexcept>
37
+
38
+
39
+ #ifdef OS_UNIX
40
+ #include <signal.h>
41
+ #include <netdb.h>
42
+ #include <time.h>
43
+ #include <sys/time.h>
44
+ #include <sys/types.h>
45
+ #include <sys/stat.h>
46
+ #include <sys/socket.h>
47
+ #include <sys/un.h>
48
+ #include <sys/resource.h>
49
+ #include <sys/wait.h>
50
+ #include <assert.h>
51
+ #include <unistd.h>
52
+ #include <fcntl.h>
53
+ #include <errno.h>
54
+ #include <netinet/in.h>
55
+ #include <netinet/tcp.h>
56
+ #include <arpa/inet.h>
57
+ #include <pwd.h>
58
+ typedef int SOCKET;
59
+ #define closesocket close
60
+ #define INVALID_SOCKET -1
61
+ #define SOCKET_ERROR -1
62
+ #ifdef OS_SOLARIS8
63
+ #include <strings.h>
64
+ #include <sys/un.h>
65
+ #ifndef AF_LOCAL
66
+ #define AF_LOCAL AF_UNIX
67
+ #endif
68
+ // INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
69
+ #ifndef INADDR_NONE
70
+ #define INADDR_NONE ((unsigned long)-1)
71
+ #endif
72
+ #endif
73
+ #endif
74
+
75
+
76
+ #ifdef OS_WIN32
77
+ #define WIN32_LEAN_AND_MEAN
78
+ #include <windows.h>
79
+ #include <winsock2.h>
80
+ #include <ws2tcpip.h>
81
+ #include <rpc.h>
82
+ #include <fcntl.h>
83
+ #include <assert.h>
84
+ typedef int socklen_t;
85
+ typedef int pid_t;
86
+ #endif
87
+
88
+
89
+ using namespace std;
90
+
91
+ #ifdef WITH_SSL
92
+ #include <openssl/ssl.h>
93
+ #include <openssl/err.h>
94
+ #endif
95
+
96
+ #ifdef HAVE_EPOLL
97
+ #include <sys/epoll.h>
98
+ #endif
99
+
100
+ #ifdef HAVE_KQUEUE
101
+ #include <sys/event.h>
102
+ #include <sys/queue.h>
103
+ #endif
104
+
105
+ #include "binder.h"
106
+ #include "em.h"
107
+ #include "epoll.h"
108
+ #include "sigs.h"
109
+ #include "ed.h"
110
+ #include "files.h"
111
+ #include "page.h"
112
+ #include "ssl.h"
113
+ #include "eventmachine.h"
114
+ #include "eventmachine_cpp.h"
115
+
116
+
117
+
118
+
119
+ #endif // __Project__H_
@@ -0,0 +1,678 @@
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 Intern_at_signature;
34
+ static VALUE Intern_at_timers;
35
+ static VALUE Intern_at_conns;
36
+ static VALUE Intern_event_callback;
37
+ static VALUE Intern_run_deferred_callbacks;
38
+ static VALUE Intern_delete;
39
+ static VALUE Intern_call;
40
+ static VALUE Intern_receive_data;
41
+
42
+ static VALUE Intern_notify_readable;
43
+ static VALUE Intern_notify_writable;
44
+
45
+ /****************
46
+ t_event_callback
47
+ ****************/
48
+
49
+ static void event_callback (const char *a1, int a2, const char *a3, int a4)
50
+ {
51
+ if (a2 == EM_CONNECTION_READ) {
52
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
53
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
54
+ if (q == Qnil)
55
+ rb_raise (rb_eRuntimeError, "no connection");
56
+ rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4));
57
+ }
58
+ else if (a2 == EM_CONNECTION_NOTIFY_READABLE) {
59
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
60
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
61
+ if (q == Qnil)
62
+ rb_raise (rb_eRuntimeError, "no connection");
63
+ rb_funcall (q, Intern_notify_readable, 0);
64
+ }
65
+ else if (a2 == EM_CONNECTION_NOTIFY_WRITABLE) {
66
+ VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
67
+ VALUE q = rb_hash_aref (t, rb_str_new2(a1));
68
+ if (q == Qnil)
69
+ rb_raise (rb_eRuntimeError, "no connection");
70
+ rb_funcall (q, Intern_notify_writable, 0);
71
+ }
72
+ else if (a2 == EM_LOOPBREAK_SIGNAL) {
73
+ rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
74
+ }
75
+ else if (a2 == EM_TIMER_FIRED) {
76
+ VALUE t = rb_ivar_get (EmModule, Intern_at_timers);
77
+ VALUE q = rb_funcall (t, Intern_delete, 1, rb_str_new(a3, a4));
78
+ if (q == Qnil)
79
+ rb_raise (rb_eRuntimeError, "no timer");
80
+ rb_funcall (q, Intern_call, 0);
81
+ }
82
+ else
83
+ rb_funcall (EmModule, Intern_event_callback, 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
84
+ }
85
+
86
+
87
+
88
+ /**************************
89
+ t_initialize_event_machine
90
+ **************************/
91
+
92
+ static VALUE t_initialize_event_machine (VALUE self)
93
+ {
94
+ evma_initialize_library (event_callback);
95
+ return Qnil;
96
+ }
97
+
98
+
99
+
100
+ /*****************************
101
+ t_run_machine_without_threads
102
+ *****************************/
103
+
104
+ static VALUE t_run_machine_without_threads (VALUE self)
105
+ {
106
+ evma_run_machine();
107
+ return Qnil;
108
+ }
109
+
110
+
111
+ /*******************
112
+ t_add_oneshot_timer
113
+ *******************/
114
+
115
+ static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
116
+ {
117
+ const char *f = evma_install_oneshot_timer (FIX2INT (interval));
118
+ if (!f || !*f)
119
+ rb_raise (rb_eRuntimeError, "no timer");
120
+ return rb_str_new2 (f);
121
+ }
122
+
123
+
124
+ /**************
125
+ t_start_server
126
+ **************/
127
+
128
+ static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
129
+ {
130
+ const char *f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
131
+ if (!f || !*f)
132
+ rb_raise (rb_eRuntimeError, "no acceptor");
133
+ return rb_str_new2 (f);
134
+ }
135
+
136
+ /*************
137
+ t_stop_server
138
+ *************/
139
+
140
+ static VALUE t_stop_server (VALUE self, VALUE signature)
141
+ {
142
+ evma_stop_tcp_server (StringValuePtr (signature));
143
+ return Qnil;
144
+ }
145
+
146
+
147
+ /*******************
148
+ t_start_unix_server
149
+ *******************/
150
+
151
+ static VALUE t_start_unix_server (VALUE self, VALUE filename)
152
+ {
153
+ const char *f = evma_create_unix_domain_server (StringValuePtr(filename));
154
+ if (!f || !*f)
155
+ rb_raise (rb_eRuntimeError, "no unix-domain acceptor");
156
+ return rb_str_new2 (f);
157
+ }
158
+
159
+
160
+
161
+ /***********
162
+ t_send_data
163
+ ***********/
164
+
165
+ static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_length)
166
+ {
167
+ int b = evma_send_data_to_connection (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length));
168
+ return INT2NUM (b);
169
+ }
170
+
171
+
172
+ /***********
173
+ t_start_tls
174
+ ***********/
175
+
176
+ static VALUE t_start_tls (VALUE self, VALUE signature)
177
+ {
178
+ evma_start_tls (StringValuePtr (signature));
179
+ return Qnil;
180
+ }
181
+
182
+ /***************
183
+ t_set_tls_parms
184
+ ***************/
185
+
186
+ static VALUE t_set_tls_parms (VALUE self, VALUE signature, VALUE privkeyfile, VALUE certchainfile)
187
+ {
188
+ /* set_tls_parms takes a series of positional arguments for specifying such things
189
+ * as private keys and certificate chains.
190
+ * It's expected that the parameter list will grow as we add more supported features.
191
+ * ALL of these parameters are optional, and can be specified as empty or NULL strings.
192
+ */
193
+ evma_set_tls_parms (StringValuePtr (signature), StringValuePtr (privkeyfile), StringValuePtr (certchainfile) );
194
+ return Qnil;
195
+ }
196
+
197
+ /**************
198
+ t_get_peername
199
+ **************/
200
+
201
+ static VALUE t_get_peername (VALUE self, VALUE signature)
202
+ {
203
+ struct sockaddr s;
204
+ if (evma_get_peername (StringValuePtr (signature), &s)) {
205
+ return rb_str_new ((const char*)&s, sizeof(s));
206
+ }
207
+
208
+ return Qnil;
209
+ }
210
+
211
+ /**************
212
+ t_get_sockname
213
+ **************/
214
+
215
+ static VALUE t_get_sockname (VALUE self, VALUE signature)
216
+ {
217
+ struct sockaddr s;
218
+ if (evma_get_sockname (StringValuePtr (signature), &s)) {
219
+ return rb_str_new ((const char*)&s, sizeof(s));
220
+ }
221
+
222
+ return Qnil;
223
+ }
224
+
225
+ /********************
226
+ t_get_subprocess_pid
227
+ ********************/
228
+
229
+ static VALUE t_get_subprocess_pid (VALUE self, VALUE signature)
230
+ {
231
+ pid_t pid;
232
+ if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
233
+ return INT2NUM (pid);
234
+ }
235
+
236
+ return Qnil;
237
+ }
238
+
239
+ /***********************
240
+ t_get_subprocess_status
241
+ ***********************/
242
+
243
+ static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
244
+ {
245
+ int status;
246
+ if (evma_get_subprocess_status (StringValuePtr (signature), &status)) {
247
+ return INT2NUM (status);
248
+ }
249
+
250
+ return Qnil;
251
+ }
252
+
253
+ /*****************************
254
+ t_get_comm_inactivity_timeout
255
+ *****************************/
256
+
257
+ static VALUE t_get_comm_inactivity_timeout (VALUE self, VALUE signature)
258
+ {
259
+ int timeout;
260
+ if (evma_get_comm_inactivity_timeout (StringValuePtr (signature), &timeout))
261
+ return INT2FIX (timeout);
262
+ return Qnil;
263
+ }
264
+
265
+ /*****************************
266
+ t_set_comm_inactivity_timeout
267
+ *****************************/
268
+
269
+ static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
270
+ {
271
+ int ti = FIX2INT (timeout);
272
+ if (evma_set_comm_inactivity_timeout (StringValuePtr (signature), &ti));
273
+ return Qtrue;
274
+ return Qnil;
275
+ }
276
+
277
+
278
+ /***************
279
+ t_send_datagram
280
+ ***************/
281
+
282
+ static VALUE t_send_datagram (VALUE self, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
283
+ {
284
+ int b = evma_send_datagram (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length), StringValuePtr(address), FIX2INT(port));
285
+ return INT2NUM (b);
286
+ }
287
+
288
+
289
+ /******************
290
+ t_close_connection
291
+ ******************/
292
+
293
+ static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writing)
294
+ {
295
+ evma_close_connection (StringValuePtr (signature), ((after_writing == Qtrue) ? 1 : 0));
296
+ return Qnil;
297
+ }
298
+
299
+ /********************************
300
+ t_report_connection_error_status
301
+ ********************************/
302
+
303
+ static VALUE t_report_connection_error_status (VALUE self, VALUE signature)
304
+ {
305
+ int b = evma_report_connection_error_status (StringValuePtr (signature));
306
+ return INT2NUM (b);
307
+ }
308
+
309
+
310
+
311
+ /****************
312
+ t_connect_server
313
+ ****************/
314
+
315
+ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
316
+ {
317
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
318
+ // Specifically, if the value of port comes in as a string rather than an integer,
319
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
320
+
321
+ const char *f = evma_connect_to_server (StringValuePtr(server), NUM2INT(port));
322
+ if (!f || !*f)
323
+ rb_raise (rb_eRuntimeError, "no connection");
324
+ return rb_str_new2 (f);
325
+ }
326
+
327
+ /*********************
328
+ t_connect_unix_server
329
+ *********************/
330
+
331
+ static VALUE t_connect_unix_server (VALUE self, VALUE serversocket)
332
+ {
333
+ const char *f = evma_connect_to_unix_server (StringValuePtr(serversocket));
334
+ if (!f || !*f)
335
+ rb_raise (rb_eRuntimeError, "no connection");
336
+ return rb_str_new2 (f);
337
+ }
338
+
339
+ /***********
340
+ t_attach_fd
341
+ ***********/
342
+
343
+ static VALUE t_attach_fd (VALUE self, VALUE file_descriptor, VALUE read_mode, VALUE write_mode)
344
+ {
345
+ const char *f = evma_attach_fd (NUM2INT(file_descriptor), (read_mode == Qtrue) ? 1 : 0, (write_mode == Qtrue) ? 1 : 0);
346
+ if (!f || !*f)
347
+ rb_raise (rb_eRuntimeError, "no connection");
348
+ return rb_str_new2 (f);
349
+ }
350
+
351
+ /***********
352
+ t_detach_fd
353
+ ***********/
354
+
355
+ static VALUE t_detach_fd (VALUE self, VALUE signature)
356
+ {
357
+ return INT2NUM(evma_detach_fd (StringValuePtr(signature)));
358
+ }
359
+
360
+ /*****************
361
+ t_open_udp_socket
362
+ *****************/
363
+
364
+ static VALUE t_open_udp_socket (VALUE self, VALUE server, VALUE port)
365
+ {
366
+ const char *f = evma_open_datagram_socket (StringValuePtr(server), FIX2INT(port));
367
+ if (!f || !*f)
368
+ rb_raise (rb_eRuntimeError, "no datagram socket");
369
+ return rb_str_new2 (f);
370
+ }
371
+
372
+
373
+
374
+ /*****************
375
+ t_release_machine
376
+ *****************/
377
+
378
+ static VALUE t_release_machine (VALUE self)
379
+ {
380
+ evma_release_library();
381
+ return Qnil;
382
+ }
383
+
384
+
385
+ /******
386
+ t_stop
387
+ ******/
388
+
389
+ static VALUE t_stop (VALUE self)
390
+ {
391
+ evma_stop_machine();
392
+ return Qnil;
393
+ }
394
+
395
+ /******************
396
+ t_signal_loopbreak
397
+ ******************/
398
+
399
+ static VALUE t_signal_loopbreak (VALUE self)
400
+ {
401
+ evma_signal_loopbreak();
402
+ return Qnil;
403
+ }
404
+
405
+ /**************
406
+ t_library_type
407
+ **************/
408
+
409
+ static VALUE t_library_type (VALUE self)
410
+ {
411
+ return rb_eval_string (":extension");
412
+ }
413
+
414
+
415
+
416
+ /*******************
417
+ t_set_timer_quantum
418
+ *******************/
419
+
420
+ static VALUE t_set_timer_quantum (VALUE self, VALUE interval)
421
+ {
422
+ evma_set_timer_quantum (FIX2INT (interval));
423
+ return Qnil;
424
+ }
425
+
426
+ /********************
427
+ t_set_max_timer_count
428
+ ********************/
429
+
430
+ static VALUE t_set_max_timer_count (VALUE self, VALUE ct)
431
+ {
432
+ evma_set_max_timer_count (FIX2INT (ct));
433
+ return Qnil;
434
+ }
435
+
436
+ /***************
437
+ t_setuid_string
438
+ ***************/
439
+
440
+ static VALUE t_setuid_string (VALUE self, VALUE username)
441
+ {
442
+ evma_setuid_string (StringValuePtr (username));
443
+ return Qnil;
444
+ }
445
+
446
+
447
+
448
+ /*************
449
+ t__write_file
450
+ *************/
451
+
452
+ static VALUE t__write_file (VALUE self, VALUE filename)
453
+ {
454
+ const char *f = evma__write_file (StringValuePtr (filename));
455
+ if (!f || !*f)
456
+ rb_raise (rb_eRuntimeError, "file not opened");
457
+ return rb_str_new2 (f);
458
+ }
459
+
460
+ /**************
461
+ t_invoke_popen
462
+ **************/
463
+
464
+ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
465
+ {
466
+ int len = RARRAY (cmd)->len;
467
+ if (len > 98)
468
+ rb_raise (rb_eRuntimeError, "too many arguments to popen");
469
+ char *strings [100];
470
+ for (int i=0; i < len; i++) {
471
+ VALUE ix = INT2FIX (i);
472
+ VALUE s = rb_ary_aref (1, &ix, cmd);
473
+ strings[i] = StringValuePtr (s);
474
+ }
475
+ strings[len] = NULL;
476
+
477
+ const char *f = evma_popen (strings);
478
+ if (!f || !*f) {
479
+ char *err = strerror (errno);
480
+ char buf[100];
481
+ memset (buf, 0, sizeof(buf));
482
+ snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
483
+ rb_raise (rb_eRuntimeError, buf);
484
+ }
485
+ return rb_str_new2 (f);
486
+ }
487
+
488
+
489
+ /***************
490
+ t_read_keyboard
491
+ ***************/
492
+
493
+ static VALUE t_read_keyboard (VALUE self)
494
+ {
495
+ const char *f = evma_open_keyboard();
496
+ if (!f || !*f)
497
+ rb_raise (rb_eRuntimeError, "no keyboard reader");
498
+ return rb_str_new2 (f);
499
+ }
500
+
501
+
502
+ /********
503
+ t__epoll
504
+ ********/
505
+
506
+ static VALUE t__epoll (VALUE self)
507
+ {
508
+ // Temporary.
509
+ evma__epoll();
510
+ return Qnil;
511
+ }
512
+
513
+ /*********
514
+ t__kqueue
515
+ *********/
516
+
517
+ static VALUE t__kqueue (VALUE self)
518
+ {
519
+ // Temporary.
520
+ evma__kqueue();
521
+ return Qnil;
522
+ }
523
+
524
+
525
+ /****************
526
+ t_send_file_data
527
+ ****************/
528
+
529
+ static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
530
+ {
531
+
532
+ /* The current implementation of evma_send_file_data_to_connection enforces a strict
533
+ * upper limit on the file size it will transmit (currently 32K). The function returns
534
+ * zero on success, -1 if the requested file exceeds its size limit, and a positive
535
+ * number for other errors.
536
+ * TODO: Positive return values are actually errno's, which is probably the wrong way to
537
+ * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
538
+ */
539
+
540
+ int b = evma_send_file_data_to_connection (StringValuePtr(signature), StringValuePtr(filename));
541
+ if (b == -1)
542
+ rb_raise(rb_eRuntimeError, "File too large. send_file_data() supports files under 32k.");
543
+ if (b > 0) {
544
+ char *err = strerror (b);
545
+ char buf[1024];
546
+ memset (buf, 0, sizeof(buf));
547
+ snprintf (buf, sizeof(buf)-1, ": %s %s", StringValuePtr(filename),(err?err:"???"));
548
+
549
+ rb_raise (rb_eIOError, buf);
550
+ }
551
+
552
+ return INT2NUM (0);
553
+ }
554
+
555
+
556
+ /*******************
557
+ t_set_rlimit_nofile
558
+ *******************/
559
+
560
+ static VALUE t_set_rlimit_nofile (VALUE self, VALUE arg)
561
+ {
562
+ arg = (NIL_P(arg)) ? -1 : NUM2INT (arg);
563
+ return INT2NUM (evma_set_rlimit_nofile (arg));
564
+ }
565
+
566
+ /***************************
567
+ conn_get_outbound_data_size
568
+ ***************************/
569
+
570
+ static VALUE conn_get_outbound_data_size (VALUE self)
571
+ {
572
+ VALUE sig = rb_ivar_get (self, Intern_at_signature);
573
+ return INT2NUM (evma_get_outbound_data_size (StringValuePtr(sig)));
574
+ }
575
+
576
+
577
+ /******************************
578
+ conn_associate_callback_target
579
+ ******************************/
580
+
581
+ static VALUE conn_associate_callback_target (VALUE self, VALUE sig)
582
+ {
583
+ // No-op for the time being.
584
+ return Qnil;
585
+ }
586
+
587
+
588
+ /*********************
589
+ Init_rubyeventmachine
590
+ *********************/
591
+
592
+ extern "C" void Init_rubyeventmachine()
593
+ {
594
+ // Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
595
+ Intern_at_signature = rb_intern ("@signature");
596
+ Intern_at_timers = rb_intern ("@timers");
597
+ Intern_at_conns = rb_intern ("@conns");
598
+
599
+ Intern_event_callback = rb_intern ("event_callback");
600
+ Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
601
+ Intern_delete = rb_intern ("delete");
602
+ Intern_call = rb_intern ("call");
603
+ Intern_receive_data = rb_intern ("receive_data");
604
+
605
+ Intern_notify_readable = rb_intern ("notify_readable");
606
+ Intern_notify_writable = rb_intern ("notify_writable");
607
+
608
+ // INCOMPLETE, we need to define class Connections inside module EventMachine
609
+ // run_machine and run_machine_without_threads are now identical.
610
+ // Must deprecate the without_threads variant.
611
+ EmModule = rb_define_module ("EventMachine");
612
+ EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);
613
+
614
+ rb_define_class_under (EmModule, "ConnectionNotBound", rb_eException);
615
+ rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eException);
616
+ rb_define_class_under (EmModule, "UnknownTimerFired", rb_eException);
617
+
618
+ rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
619
+ rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
620
+ rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine_without_threads, 0);
621
+ rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
622
+ rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
623
+ rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
624
+ rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
625
+ rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 3);
626
+ rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
627
+ rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
628
+ rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
629
+ rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
630
+ rb_define_module_function (EmModule, "report_connection_error_status", (VALUE(*)(...))t_report_connection_error_status, 1);
631
+ rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
632
+ rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);
633
+
634
+ rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 3);
635
+ rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
636
+
637
+ rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
638
+ rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
639
+ rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
640
+ rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
641
+ rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
642
+ rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
643
+ rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
644
+ rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
645
+ rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
646
+ rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
647
+ rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
648
+
649
+ // Provisional:
650
+ rb_define_module_function (EmModule, "_write_file", (VALUE(*)(...))t__write_file, 1);
651
+
652
+ rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
653
+ rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
654
+ rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
655
+ rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
656
+ rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
657
+ rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
658
+ rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
659
+
660
+ // Temporary:
661
+ rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
662
+ rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
663
+
664
+ rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
665
+ rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
666
+
667
+ rb_define_const (EmModule, "TimerFired", INT2NUM(100));
668
+ rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
669
+ rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(102));
670
+ rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(103));
671
+ rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(104));
672
+ rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(105));
673
+
674
+ rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(106));
675
+ rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(107));
676
+
677
+ }
678
+