MattHulse-eventmachine 0.0.1

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