eventmachine 0.12.0-i386-mswin32

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