eventmachine 1.2.0.dev.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +105 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +108 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +46 -0
  35. data/ext/cmain.cpp +988 -0
  36. data/ext/ed.cpp +2111 -0
  37. data/ext/ed.h +442 -0
  38. data/ext/em.cpp +2379 -0
  39. data/ext/em.h +308 -0
  40. data/ext/eventmachine.h +143 -0
  41. data/ext/extconf.rb +270 -0
  42. data/ext/fastfilereader/extconf.rb +110 -0
  43. data/ext/fastfilereader/mapper.cpp +216 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +127 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +176 -0
  51. data/ext/rubymain.cpp +1504 -0
  52. data/ext/ssl.cpp +615 -0
  53. data/ext/ssl.h +103 -0
  54. data/java/.classpath +8 -0
  55. data/java/.project +17 -0
  56. data/java/src/com/rubyeventmachine/EmReactor.java +591 -0
  57. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  58. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  59. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  60. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  61. data/lib/2.0/fastfilereaderext.so +0 -0
  62. data/lib/2.0/rubyeventmachine.so +0 -0
  63. data/lib/2.1/fastfilereaderext.so +0 -0
  64. data/lib/2.1/rubyeventmachine.so +0 -0
  65. data/lib/2.2/fastfilereaderext.so +0 -0
  66. data/lib/2.2/rubyeventmachine.so +0 -0
  67. data/lib/2.3/fastfilereaderext.so +0 -0
  68. data/lib/2.3/rubyeventmachine.so +0 -0
  69. data/lib/em/buftok.rb +59 -0
  70. data/lib/em/callback.rb +58 -0
  71. data/lib/em/channel.rb +69 -0
  72. data/lib/em/completion.rb +304 -0
  73. data/lib/em/connection.rb +770 -0
  74. data/lib/em/deferrable.rb +210 -0
  75. data/lib/em/deferrable/pool.rb +2 -0
  76. data/lib/em/file_watch.rb +73 -0
  77. data/lib/em/future.rb +61 -0
  78. data/lib/em/iterator.rb +252 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/pool.rb +151 -0
  81. data/lib/em/process_watch.rb +45 -0
  82. data/lib/em/processes.rb +123 -0
  83. data/lib/em/protocols.rb +37 -0
  84. data/lib/em/protocols/header_and_content.rb +138 -0
  85. data/lib/em/protocols/httpclient.rb +299 -0
  86. data/lib/em/protocols/httpclient2.rb +600 -0
  87. data/lib/em/protocols/line_and_text.rb +125 -0
  88. data/lib/em/protocols/line_protocol.rb +29 -0
  89. data/lib/em/protocols/linetext2.rb +166 -0
  90. data/lib/em/protocols/memcache.rb +331 -0
  91. data/lib/em/protocols/object_protocol.rb +46 -0
  92. data/lib/em/protocols/postgres3.rb +246 -0
  93. data/lib/em/protocols/saslauth.rb +175 -0
  94. data/lib/em/protocols/smtpclient.rb +394 -0
  95. data/lib/em/protocols/smtpserver.rb +666 -0
  96. data/lib/em/protocols/socks4.rb +66 -0
  97. data/lib/em/protocols/stomp.rb +205 -0
  98. data/lib/em/protocols/tcptest.rb +54 -0
  99. data/lib/em/pure_ruby.rb +1022 -0
  100. data/lib/em/queue.rb +80 -0
  101. data/lib/em/resolver.rb +232 -0
  102. data/lib/em/spawnable.rb +84 -0
  103. data/lib/em/streamer.rb +118 -0
  104. data/lib/em/threaded_resource.rb +90 -0
  105. data/lib/em/tick_loop.rb +85 -0
  106. data/lib/em/timers.rb +61 -0
  107. data/lib/em/version.rb +3 -0
  108. data/lib/eventmachine.rb +1584 -0
  109. data/lib/fastfilereaderext.rb +2 -0
  110. data/lib/jeventmachine.rb +301 -0
  111. data/lib/rubyeventmachine.rb +2 -0
  112. data/rakelib/package.rake +120 -0
  113. data/rakelib/test.rake +8 -0
  114. data/tests/client.crt +31 -0
  115. data/tests/client.key +51 -0
  116. data/tests/dhparam.pem +13 -0
  117. data/tests/em_test_helper.rb +151 -0
  118. data/tests/test_attach.rb +151 -0
  119. data/tests/test_basic.rb +283 -0
  120. data/tests/test_channel.rb +75 -0
  121. data/tests/test_completion.rb +178 -0
  122. data/tests/test_connection_count.rb +54 -0
  123. data/tests/test_connection_write.rb +35 -0
  124. data/tests/test_defer.rb +35 -0
  125. data/tests/test_deferrable.rb +35 -0
  126. data/tests/test_epoll.rb +142 -0
  127. data/tests/test_error_handler.rb +38 -0
  128. data/tests/test_exc.rb +28 -0
  129. data/tests/test_file_watch.rb +66 -0
  130. data/tests/test_fork.rb +75 -0
  131. data/tests/test_futures.rb +170 -0
  132. data/tests/test_get_sock_opt.rb +37 -0
  133. data/tests/test_handler_check.rb +35 -0
  134. data/tests/test_hc.rb +155 -0
  135. data/tests/test_httpclient.rb +233 -0
  136. data/tests/test_httpclient2.rb +128 -0
  137. data/tests/test_idle_connection.rb +25 -0
  138. data/tests/test_inactivity_timeout.rb +54 -0
  139. data/tests/test_ipv4.rb +125 -0
  140. data/tests/test_ipv6.rb +131 -0
  141. data/tests/test_iterator.rb +115 -0
  142. data/tests/test_kb.rb +28 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +138 -0
  145. data/tests/test_ltp2.rb +308 -0
  146. data/tests/test_many_fds.rb +22 -0
  147. data/tests/test_next_tick.rb +104 -0
  148. data/tests/test_object_protocol.rb +36 -0
  149. data/tests/test_pause.rb +107 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +196 -0
  152. data/tests/test_process_watch.rb +50 -0
  153. data/tests/test_processes.rb +128 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +88 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +104 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +47 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +33 -0
  162. data/tests/test_set_sock_opt.rb +39 -0
  163. data/tests/test_shutdown_hooks.rb +23 -0
  164. data/tests/test_smtpclient.rb +75 -0
  165. data/tests/test_smtpserver.rb +57 -0
  166. data/tests/test_spawn.rb +293 -0
  167. data/tests/test_ssl_args.rb +78 -0
  168. data/tests/test_ssl_dhparam.rb +83 -0
  169. data/tests/test_ssl_ecdh_curve.rb +79 -0
  170. data/tests/test_ssl_extensions.rb +49 -0
  171. data/tests/test_ssl_methods.rb +65 -0
  172. data/tests/test_ssl_protocols.rb +246 -0
  173. data/tests/test_ssl_verify.rb +126 -0
  174. data/tests/test_stomp.rb +37 -0
  175. data/tests/test_system.rb +46 -0
  176. data/tests/test_threaded_resource.rb +61 -0
  177. data/tests/test_tick_loop.rb +59 -0
  178. data/tests/test_timers.rb +123 -0
  179. data/tests/test_ud.rb +8 -0
  180. data/tests/test_unbind_reason.rb +52 -0
  181. metadata +381 -0
@@ -0,0 +1,176 @@
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
+ #include <iostream>
26
+ #include <map>
27
+ #include <set>
28
+ #include <vector>
29
+ #include <deque>
30
+ #include <string>
31
+ #include <sstream>
32
+ #include <stdexcept>
33
+
34
+
35
+ #ifdef OS_UNIX
36
+ #include <signal.h>
37
+ #include <netdb.h>
38
+ #include <time.h>
39
+ #include <sys/time.h>
40
+ #include <sys/types.h>
41
+ #include <sys/stat.h>
42
+ #include <sys/socket.h>
43
+ #include <sys/un.h>
44
+ #include <sys/resource.h>
45
+ #include <sys/wait.h>
46
+ #include <assert.h>
47
+ #include <unistd.h>
48
+ #include <fcntl.h>
49
+ #include <errno.h>
50
+ #include <netinet/in.h>
51
+ #include <netinet/tcp.h>
52
+ #include <arpa/inet.h>
53
+ #include <pwd.h>
54
+ #include <string.h>
55
+ typedef int SOCKET;
56
+ #define INVALID_SOCKET -1
57
+ #define SOCKET_ERROR -1
58
+ #ifdef OS_SOLARIS8
59
+ #include <strings.h>
60
+ #include <sys/un.h>
61
+ #ifndef AF_LOCAL
62
+ #define AF_LOCAL AF_UNIX
63
+ #endif
64
+ // INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
65
+ #ifndef INADDR_NONE
66
+ #define INADDR_NONE ((unsigned long)-1)
67
+ #endif
68
+ #endif /* OS_SOLARIS8 */
69
+
70
+ #ifdef _AIX
71
+ #include <strings.h>
72
+ #ifndef AF_LOCAL
73
+ #define AF_LOCAL AF_UNIX
74
+ #endif
75
+ #endif /* _AIX */
76
+
77
+ #ifdef OS_DARWIN
78
+ #include <mach/mach.h>
79
+ #include <mach/mach_time.h>
80
+ #endif /* OS_DARWIN */
81
+
82
+ #endif /* OS_UNIX */
83
+
84
+ #ifdef OS_WIN32
85
+ // 21Sep09: windows limits select() to 64 sockets by default, we increase it to 1024 here (before including winsock2.h)
86
+ // 18Jun12: fd_setsize must be changed in the ruby binary (not in this extension). redefining it also causes segvs, see eventmachine/eventmachine#333
87
+ //#define FD_SETSIZE 1024
88
+
89
+ // WIN32_LEAN_AND_MEAN excludes APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.
90
+ #define WIN32_LEAN_AND_MEAN
91
+
92
+ #include <windows.h>
93
+ #include <winsock2.h>
94
+ #include <ws2tcpip.h>
95
+ #include <rpc.h>
96
+ #include <fcntl.h>
97
+ #include <assert.h>
98
+
99
+ // Older versions of MinGW in the Ruby Dev Kit do not provide the getaddrinfo hint flags
100
+ #ifndef AI_ADDRCONFIG
101
+ #define AI_ADDRCONFIG 0x0400
102
+ #endif
103
+
104
+ #ifndef AI_NUMERICSERV
105
+ #define AI_NUMERICSERV 0x0008
106
+ #endif
107
+
108
+ // Use the Win32 wrapper library that Ruby owns to be able to close sockets with the close() function
109
+ #define RUBY_EXPORT
110
+ #include <ruby/defines.h>
111
+ #include <ruby/win32.h>
112
+ #endif /* OS_WIN32 */
113
+
114
+ #if !defined(_MSC_VER) || _MSC_VER > 1500
115
+ #include <stdint.h>
116
+ #endif
117
+
118
+ using namespace std;
119
+
120
+ #ifdef WITH_SSL
121
+ #include <openssl/ssl.h>
122
+ #include <openssl/err.h>
123
+ #endif
124
+
125
+ #ifdef HAVE_EPOLL
126
+ #include <sys/epoll.h>
127
+ #endif
128
+
129
+ #ifdef HAVE_KQUEUE
130
+ #include <sys/event.h>
131
+ #include <sys/queue.h>
132
+ #endif
133
+
134
+ #ifdef HAVE_INOTIFY
135
+ #include <sys/inotify.h>
136
+ #endif
137
+
138
+ #ifdef HAVE_OLD_INOTIFY
139
+ #include <sys/syscall.h>
140
+ #include <linux/inotify.h>
141
+ static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
142
+ static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
143
+ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
144
+ #define HAVE_INOTIFY 1
145
+ #endif
146
+
147
+ #ifdef HAVE_INOTIFY
148
+ #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
149
+ #endif
150
+
151
+ #ifdef HAVE_WRITEV
152
+ #include <sys/uio.h>
153
+ #endif
154
+
155
+ #if __cplusplus
156
+ extern "C" {
157
+ #endif
158
+ typedef void (*EMCallback)(const unsigned long, int, const char*, const unsigned long);
159
+ #if __cplusplus
160
+ }
161
+ #endif
162
+
163
+ #if defined(__GNUC__) && (__GNUC__ >= 3)
164
+ #define UNUSED __attribute__ ((unused))
165
+ #else
166
+ #define UNUSED
167
+ #endif
168
+
169
+ #include "binder.h"
170
+ #include "em.h"
171
+ #include "ed.h"
172
+ #include "page.h"
173
+ #include "ssl.h"
174
+ #include "eventmachine.h"
175
+
176
+ #endif // __Project__H_
@@ -0,0 +1,1504 @@
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
+ /* Adapted from NUM2BSIG / BSIG2NUM in ext/fiddle/conversions.h,
29
+ * we'll call it a BSIG for Binding Signature here. */
30
+ #if SIZEOF_VOIDP == SIZEOF_LONG
31
+ # define BSIG2NUM(x) (ULONG2NUM((unsigned long)(x)))
32
+ # define NUM2BSIG(x) (NUM2ULONG(x))
33
+ # ifdef OS_WIN32
34
+ # define PRIFBSIG "I32u"
35
+ # else
36
+ # define PRIFBSIG "lu"
37
+ # endif
38
+ #else
39
+ # define BSIG2NUM(x) (ULL2NUM((unsigned long long)(x)))
40
+ # define NUM2BSIG(x) (NUM2ULL(x))
41
+ # ifdef OS_WIN32
42
+ # define PRIFBSIG "I64u"
43
+ # else
44
+ # define PRIFBSIG "llu"
45
+ # endif
46
+ #endif
47
+
48
+ /*******
49
+ Statics
50
+ *******/
51
+
52
+ static VALUE EmModule;
53
+ static VALUE EmConnection;
54
+ static VALUE EmConnsHash;
55
+ static VALUE EmTimersHash;
56
+
57
+ static VALUE EM_eConnectionError;
58
+ static VALUE EM_eUnknownTimerFired;
59
+ static VALUE EM_eConnectionNotBound;
60
+ static VALUE EM_eUnsupported;
61
+
62
+ static VALUE Intern_at_signature;
63
+ static VALUE Intern_at_timers;
64
+ static VALUE Intern_at_conns;
65
+ static VALUE Intern_at_error_handler;
66
+ static VALUE Intern_event_callback;
67
+ static VALUE Intern_run_deferred_callbacks;
68
+ static VALUE Intern_delete;
69
+ static VALUE Intern_call;
70
+ static VALUE Intern_at;
71
+ static VALUE Intern_receive_data;
72
+ static VALUE Intern_ssl_handshake_completed;
73
+ static VALUE Intern_ssl_verify_peer;
74
+ static VALUE Intern_notify_readable;
75
+ static VALUE Intern_notify_writable;
76
+ static VALUE Intern_proxy_target_unbound;
77
+ static VALUE Intern_proxy_completed;
78
+ static VALUE Intern_connection_completed;
79
+
80
+ static VALUE rb_cProcStatus;
81
+
82
+ struct em_event {
83
+ uintptr_t signature;
84
+ int event;
85
+ const char *data_str;
86
+ unsigned long data_num;
87
+ };
88
+
89
+ static inline VALUE ensure_conn(const uintptr_t signature)
90
+ {
91
+ VALUE conn = rb_hash_aref (EmConnsHash, BSIG2NUM (signature));
92
+ if (conn == Qnil)
93
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %" PRIFBSIG, signature);
94
+ return conn;
95
+ }
96
+
97
+
98
+ /****************
99
+ t_event_callback
100
+ ****************/
101
+
102
+ static inline void event_callback (struct em_event* e)
103
+ {
104
+ const uintptr_t signature = e->signature;
105
+ int event = e->event;
106
+ const char *data_str = e->data_str;
107
+ const unsigned long data_num = e->data_num;
108
+
109
+ switch (event) {
110
+ case EM_CONNECTION_READ:
111
+ {
112
+ VALUE conn = rb_hash_aref (EmConnsHash, BSIG2NUM (signature));
113
+ if (conn == Qnil)
114
+ rb_raise (EM_eConnectionNotBound, "received %lu bytes of data for unknown signature: %" PRIFBSIG, data_num, signature);
115
+ rb_funcall (conn, Intern_receive_data, 1, rb_str_new (data_str, data_num));
116
+ return;
117
+ }
118
+ case EM_CONNECTION_ACCEPTED:
119
+ {
120
+ rb_funcall (EmModule, Intern_event_callback, 3, BSIG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
121
+ return;
122
+ }
123
+ case EM_CONNECTION_UNBOUND:
124
+ {
125
+ rb_funcall (EmModule, Intern_event_callback, 3, BSIG2NUM(signature), INT2FIX(event), ULONG2NUM(data_num));
126
+ return;
127
+ }
128
+ case EM_CONNECTION_COMPLETED:
129
+ {
130
+ VALUE conn = ensure_conn(signature);
131
+ rb_funcall (conn, Intern_connection_completed, 0);
132
+ return;
133
+ }
134
+ case EM_CONNECTION_NOTIFY_READABLE:
135
+ {
136
+ VALUE conn = ensure_conn(signature);
137
+ rb_funcall (conn, Intern_notify_readable, 0);
138
+ return;
139
+ }
140
+ case EM_CONNECTION_NOTIFY_WRITABLE:
141
+ {
142
+ VALUE conn = ensure_conn(signature);
143
+ rb_funcall (conn, Intern_notify_writable, 0);
144
+ return;
145
+ }
146
+ case EM_LOOPBREAK_SIGNAL:
147
+ {
148
+ rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
149
+ return;
150
+ }
151
+ case EM_TIMER_FIRED:
152
+ {
153
+ VALUE timer = rb_funcall (EmTimersHash, Intern_delete, 1, ULONG2NUM (data_num));
154
+ if (timer == Qnil) {
155
+ rb_raise (EM_eUnknownTimerFired, "no such timer: %lu", data_num);
156
+ } else if (timer == Qfalse) {
157
+ /* Timer Canceled */
158
+ } else {
159
+ rb_funcall (timer, Intern_call, 0);
160
+ }
161
+ return;
162
+ }
163
+ #ifdef WITH_SSL
164
+ case EM_SSL_HANDSHAKE_COMPLETED:
165
+ {
166
+ VALUE conn = ensure_conn(signature);
167
+ rb_funcall (conn, Intern_ssl_handshake_completed, 0);
168
+ return;
169
+ }
170
+ case EM_SSL_VERIFY:
171
+ {
172
+ VALUE conn = ensure_conn(signature);
173
+ VALUE should_accept = rb_funcall (conn, Intern_ssl_verify_peer, 1, rb_str_new(data_str, data_num));
174
+ if (RTEST(should_accept))
175
+ evma_accept_ssl_peer (signature);
176
+ return;
177
+ }
178
+ #endif
179
+ case EM_PROXY_TARGET_UNBOUND:
180
+ {
181
+ VALUE conn = ensure_conn(signature);
182
+ rb_funcall (conn, Intern_proxy_target_unbound, 0);
183
+ return;
184
+ }
185
+ case EM_PROXY_COMPLETED:
186
+ {
187
+ VALUE conn = ensure_conn(signature);
188
+ rb_funcall (conn, Intern_proxy_completed, 0);
189
+ return;
190
+ }
191
+ }
192
+ }
193
+
194
+ /*******************
195
+ event_error_handler
196
+ *******************/
197
+
198
+ static void event_error_handler(VALUE self UNUSED, VALUE err)
199
+ {
200
+ VALUE error_handler = rb_ivar_get(EmModule, Intern_at_error_handler);
201
+ rb_funcall (error_handler, Intern_call, 1, err);
202
+ }
203
+
204
+ /**********************
205
+ event_callback_wrapper
206
+ **********************/
207
+
208
+ static void event_callback_wrapper (const uintptr_t signature, int event, const char *data_str, const unsigned long data_num)
209
+ {
210
+ struct em_event e;
211
+ e.signature = signature;
212
+ e.event = event;
213
+ e.data_str = data_str;
214
+ e.data_num = data_num;
215
+
216
+ if (!rb_ivar_defined(EmModule, Intern_at_error_handler))
217
+ event_callback(&e);
218
+ else
219
+ rb_rescue((VALUE (*)(ANYARGS))event_callback, (VALUE)&e, (VALUE (*)(ANYARGS))event_error_handler, Qnil);
220
+ }
221
+
222
+ /**************************
223
+ t_initialize_event_machine
224
+ **************************/
225
+
226
+ static VALUE t_initialize_event_machine (VALUE self UNUSED)
227
+ {
228
+ EmConnsHash = rb_ivar_get (EmModule, Intern_at_conns);
229
+ EmTimersHash = rb_ivar_get (EmModule, Intern_at_timers);
230
+ assert(EmConnsHash != Qnil);
231
+ assert(EmTimersHash != Qnil);
232
+ evma_initialize_library ((EMCallback)event_callback_wrapper);
233
+ return Qnil;
234
+ }
235
+
236
+
237
+ /******************
238
+ t_run_machine_once
239
+ ******************/
240
+
241
+ static VALUE t_run_machine_once (VALUE self UNUSED)
242
+ {
243
+ return evma_run_machine_once () ? Qtrue : Qfalse;
244
+ }
245
+
246
+
247
+ /*************
248
+ t_run_machine
249
+ *************/
250
+
251
+ static VALUE t_run_machine (VALUE self UNUSED)
252
+ {
253
+ evma_run_machine();
254
+ return Qnil;
255
+ }
256
+
257
+
258
+ /*******************
259
+ t_add_oneshot_timer
260
+ *******************/
261
+
262
+ static VALUE t_add_oneshot_timer (VALUE self UNUSED, VALUE interval)
263
+ {
264
+ const uintptr_t f = evma_install_oneshot_timer (FIX2INT (interval));
265
+ if (!f)
266
+ rb_raise (rb_eRuntimeError, "%s", "ran out of timers; use #set_max_timers to increase limit");
267
+ return BSIG2NUM (f);
268
+ }
269
+
270
+
271
+ /**************
272
+ t_start_server
273
+ **************/
274
+
275
+ static VALUE t_start_server (VALUE self UNUSED, VALUE server, VALUE port)
276
+ {
277
+ const uintptr_t f = evma_create_tcp_server (StringValueCStr(server), FIX2INT(port));
278
+ if (!f)
279
+ rb_raise (rb_eRuntimeError, "%s", "no acceptor (port is in use or requires root privileges)");
280
+ return BSIG2NUM (f);
281
+ }
282
+
283
+ /*************
284
+ t_stop_server
285
+ *************/
286
+
287
+ static VALUE t_stop_server (VALUE self UNUSED, VALUE signature)
288
+ {
289
+ evma_stop_tcp_server (NUM2BSIG (signature));
290
+ return Qnil;
291
+ }
292
+
293
+
294
+ /*******************
295
+ t_start_unix_server
296
+ *******************/
297
+
298
+ static VALUE t_start_unix_server (VALUE self UNUSED, VALUE filename)
299
+ {
300
+ const uintptr_t f = evma_create_unix_domain_server (StringValueCStr(filename));
301
+ if (!f)
302
+ rb_raise (rb_eRuntimeError, "%s", "no unix-domain acceptor");
303
+ return BSIG2NUM (f);
304
+ }
305
+
306
+ /********************
307
+ t_attach_sd
308
+ ********************/
309
+
310
+ static VALUE t_attach_sd(VALUE self UNUSED, VALUE sd)
311
+ {
312
+ const uintptr_t f = evma_attach_sd(FIX2INT(sd));
313
+ if (!f)
314
+ rb_raise (rb_eRuntimeError, "%s", "no socket descriptor acceptor");
315
+ return BSIG2NUM (f);
316
+ }
317
+
318
+
319
+ /***********
320
+ t_send_data
321
+ ***********/
322
+
323
+ static VALUE t_send_data (VALUE self UNUSED, VALUE signature, VALUE data, VALUE data_length)
324
+ {
325
+ int b = evma_send_data_to_connection (NUM2BSIG (signature), StringValuePtr (data), FIX2INT (data_length));
326
+ return INT2NUM (b);
327
+ }
328
+
329
+
330
+ /***********
331
+ t_start_tls
332
+ ***********/
333
+
334
+ static VALUE t_start_tls (VALUE self UNUSED, VALUE signature)
335
+ {
336
+ evma_start_tls (NUM2BSIG (signature));
337
+ return Qnil;
338
+ }
339
+
340
+ /***************
341
+ t_set_tls_parms
342
+ ***************/
343
+
344
+ static VALUE t_set_tls_parms (VALUE self UNUSED, VALUE signature, VALUE privkeyfile, VALUE certchainfile, VALUE verify_peer, VALUE fail_if_no_peer_cert, VALUE snihostname, VALUE cipherlist, VALUE ecdh_curve, VALUE dhparam, VALUE ssl_version)
345
+ {
346
+ /* set_tls_parms takes a series of positional arguments for specifying such things
347
+ * as private keys and certificate chains.
348
+ * It's expected that the parameter list will grow as we add more supported features.
349
+ * ALL of these parameters are optional, and can be specified as empty or NULL strings.
350
+ */
351
+ evma_set_tls_parms (NUM2BSIG (signature), StringValueCStr (privkeyfile), StringValueCStr (certchainfile), (verify_peer == Qtrue ? 1 : 0), (fail_if_no_peer_cert == Qtrue ? 1 : 0), StringValueCStr (snihostname), StringValueCStr (cipherlist), StringValueCStr (ecdh_curve), StringValueCStr (dhparam), NUM2INT (ssl_version));
352
+ return Qnil;
353
+ }
354
+
355
+ /***************
356
+ t_get_peer_cert
357
+ ***************/
358
+
359
+ #ifdef WITH_SSL
360
+ static VALUE t_get_peer_cert (VALUE self UNUSED, VALUE signature)
361
+ {
362
+ VALUE ret = Qnil;
363
+
364
+ X509 *cert = NULL;
365
+ BUF_MEM *buf;
366
+ BIO *out;
367
+
368
+ cert = evma_get_peer_cert (NUM2BSIG (signature));
369
+
370
+ if (cert != NULL) {
371
+ out = BIO_new(BIO_s_mem());
372
+ PEM_write_bio_X509(out, cert);
373
+ BIO_get_mem_ptr(out, &buf);
374
+ ret = rb_str_new(buf->data, buf->length);
375
+ X509_free(cert);
376
+ BIO_free(out);
377
+ }
378
+
379
+ return ret;
380
+ }
381
+ #else
382
+ static VALUE t_get_peer_cert (VALUE self UNUSED, VALUE signature UNUSED)
383
+ {
384
+ return Qnil;
385
+ }
386
+ #endif
387
+
388
+ /***************
389
+ t_get_cipher_bits
390
+ ***************/
391
+
392
+ #ifdef WITH_SSL
393
+ static VALUE t_get_cipher_bits (VALUE self UNUSED, VALUE signature)
394
+ {
395
+ int bits = evma_get_cipher_bits (NUM2BSIG (signature));
396
+ if (bits == -1)
397
+ return Qnil;
398
+ return INT2NUM (bits);
399
+ }
400
+ #else
401
+ static VALUE t_get_cipher_bits (VALUE self UNUSED, VALUE signature UNUSED)
402
+ {
403
+ return Qnil;
404
+ }
405
+ #endif
406
+
407
+ /***************
408
+ t_get_cipher_name
409
+ ***************/
410
+
411
+ #ifdef WITH_SSL
412
+ static VALUE t_get_cipher_name (VALUE self UNUSED, VALUE signature)
413
+ {
414
+ const char *protocol = evma_get_cipher_name (NUM2BSIG (signature));
415
+ if (protocol)
416
+ return rb_str_new2 (protocol);
417
+
418
+ return Qnil;
419
+ }
420
+ #else
421
+ static VALUE t_get_cipher_name (VALUE self UNUSED, VALUE signature UNUSED)
422
+ {
423
+ return Qnil;
424
+ }
425
+ #endif
426
+
427
+ /***************
428
+ t_get_cipher_protocol
429
+ ***************/
430
+
431
+ #ifdef WITH_SSL
432
+ static VALUE t_get_cipher_protocol (VALUE self UNUSED, VALUE signature)
433
+ {
434
+ const char *cipher = evma_get_cipher_protocol (NUM2BSIG (signature));
435
+ if (cipher)
436
+ return rb_str_new2 (cipher);
437
+
438
+ return Qnil;
439
+ }
440
+ #else
441
+ static VALUE t_get_cipher_protocol (VALUE self UNUSED, VALUE signature UNUSED)
442
+ {
443
+ return Qnil;
444
+ }
445
+ #endif
446
+
447
+ /***************
448
+ t_get_sni_hostname
449
+ ***************/
450
+
451
+ #ifdef WITH_SSL
452
+ static VALUE t_get_sni_hostname (VALUE self UNUSED, VALUE signature)
453
+ {
454
+ const char *sni_hostname = evma_get_sni_hostname (NUM2BSIG (signature));
455
+ if (sni_hostname)
456
+ return rb_str_new2 (sni_hostname);
457
+
458
+ return Qnil;
459
+ }
460
+ #else
461
+ static VALUE t_get_sni_hostname (VALUE self UNUSED, VALUE signature UNUSED)
462
+ {
463
+ return Qnil;
464
+ }
465
+ #endif
466
+
467
+ /**************
468
+ t_get_peername
469
+ **************/
470
+
471
+ static VALUE t_get_peername (VALUE self UNUSED, VALUE signature)
472
+ {
473
+ char buf[1024];
474
+ socklen_t len = sizeof buf;
475
+ if (evma_get_peername (NUM2BSIG (signature), (struct sockaddr*)buf, &len)) {
476
+ return rb_str_new (buf, len);
477
+ }
478
+
479
+ return Qnil;
480
+ }
481
+
482
+ /**************
483
+ t_get_sockname
484
+ **************/
485
+
486
+ static VALUE t_get_sockname (VALUE self UNUSED, VALUE signature)
487
+ {
488
+ char buf[1024];
489
+ socklen_t len = sizeof buf;
490
+ if (evma_get_sockname (NUM2BSIG (signature), (struct sockaddr*)buf, &len)) {
491
+ return rb_str_new (buf, len);
492
+ }
493
+
494
+ return Qnil;
495
+ }
496
+
497
+ /********************
498
+ t_get_subprocess_pid
499
+ ********************/
500
+
501
+ static VALUE t_get_subprocess_pid (VALUE self UNUSED, VALUE signature)
502
+ {
503
+ pid_t pid;
504
+ if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
505
+ return INT2NUM (pid);
506
+ }
507
+
508
+ return Qnil;
509
+ }
510
+
511
+ /***********************
512
+ t_get_subprocess_status
513
+ ***********************/
514
+
515
+ static VALUE t_get_subprocess_status (VALUE self UNUSED, VALUE signature)
516
+ {
517
+ VALUE proc_status = Qnil;
518
+
519
+ int status;
520
+ pid_t pid;
521
+
522
+ if (evma_get_subprocess_status (NUM2BSIG (signature), &status)) {
523
+ if (evma_get_subprocess_pid (NUM2BSIG (signature), &pid)) {
524
+ proc_status = rb_obj_alloc(rb_cProcStatus);
525
+
526
+ /* MRI Ruby uses hidden instance vars */
527
+ rb_iv_set(proc_status, "status", INT2FIX(status));
528
+ rb_iv_set(proc_status, "pid", INT2FIX(pid));
529
+
530
+ #ifdef RUBINIUS
531
+ /* Rubinius uses standard instance vars */
532
+ rb_iv_set(proc_status, "@pid", INT2FIX(pid));
533
+ if (WIFEXITED(status)) {
534
+ rb_iv_set(proc_status, "@status", INT2FIX(WEXITSTATUS(status)));
535
+ } else if (WIFSIGNALED(status)) {
536
+ rb_iv_set(proc_status, "@termsig", INT2FIX(WTERMSIG(status)));
537
+ } else if (WIFSTOPPED(status)){
538
+ rb_iv_set(proc_status, "@stopsig", INT2FIX(WSTOPSIG(status)));
539
+ }
540
+ #endif
541
+ }
542
+ }
543
+
544
+ return proc_status;
545
+ }
546
+
547
+ /**********************
548
+ t_get_connection_count
549
+ **********************/
550
+
551
+ static VALUE t_get_connection_count (VALUE self UNUSED)
552
+ {
553
+ return INT2NUM(evma_get_connection_count());
554
+ }
555
+
556
+ /*****************************
557
+ t_get_comm_inactivity_timeout
558
+ *****************************/
559
+
560
+ static VALUE t_get_comm_inactivity_timeout (VALUE self UNUSED, VALUE signature)
561
+ {
562
+ return rb_float_new(evma_get_comm_inactivity_timeout(NUM2BSIG (signature)));
563
+ }
564
+
565
+ /*****************************
566
+ t_set_comm_inactivity_timeout
567
+ *****************************/
568
+
569
+ static VALUE t_set_comm_inactivity_timeout (VALUE self UNUSED, VALUE signature, VALUE timeout)
570
+ {
571
+ float ti = RFLOAT_VALUE(timeout);
572
+ if (evma_set_comm_inactivity_timeout(NUM2BSIG(signature), ti)) {
573
+ return Qtrue;
574
+ }
575
+ return Qfalse;
576
+ }
577
+
578
+ /*****************************
579
+ t_get_pending_connect_timeout
580
+ *****************************/
581
+
582
+ static VALUE t_get_pending_connect_timeout (VALUE self UNUSED, VALUE signature)
583
+ {
584
+ return rb_float_new(evma_get_pending_connect_timeout(NUM2BSIG (signature)));
585
+ }
586
+
587
+ /*****************************
588
+ t_set_pending_connect_timeout
589
+ *****************************/
590
+
591
+ static VALUE t_set_pending_connect_timeout (VALUE self UNUSED, VALUE signature, VALUE timeout)
592
+ {
593
+ float ti = RFLOAT_VALUE(timeout);
594
+ if (evma_set_pending_connect_timeout(NUM2BSIG(signature), ti)) {
595
+ return Qtrue;
596
+ }
597
+ return Qfalse;
598
+ }
599
+
600
+ /***************
601
+ t_send_datagram
602
+ ***************/
603
+
604
+ static VALUE t_send_datagram (VALUE self UNUSED, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
605
+ {
606
+ int b = evma_send_datagram (NUM2BSIG (signature), StringValuePtr (data), FIX2INT (data_length), StringValueCStr(address), FIX2INT(port));
607
+ if (b < 0)
608
+ rb_raise (EM_eConnectionError, "%s", "error in sending datagram"); // FIXME: this could be more specific.
609
+ return INT2NUM (b);
610
+ }
611
+
612
+
613
+ /******************
614
+ t_close_connection
615
+ ******************/
616
+
617
+ static VALUE t_close_connection (VALUE self UNUSED, VALUE signature, VALUE after_writing)
618
+ {
619
+ evma_close_connection (NUM2BSIG (signature), ((after_writing == Qtrue) ? 1 : 0));
620
+ return Qnil;
621
+ }
622
+
623
+ /********************************
624
+ t_report_connection_error_status
625
+ ********************************/
626
+
627
+ static VALUE t_report_connection_error_status (VALUE self UNUSED, VALUE signature)
628
+ {
629
+ int b = evma_report_connection_error_status (NUM2BSIG (signature));
630
+ return INT2NUM (b);
631
+ }
632
+
633
+
634
+
635
+ /****************
636
+ t_connect_server
637
+ ****************/
638
+
639
+ static VALUE t_connect_server (VALUE self UNUSED, VALUE server, VALUE port)
640
+ {
641
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
642
+ // Specifically, if the value of port comes in as a string rather than an integer,
643
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
644
+
645
+ try {
646
+ const uintptr_t f = evma_connect_to_server (NULL, 0, StringValueCStr(server), NUM2INT(port));
647
+ if (!f)
648
+ rb_raise (EM_eConnectionError, "%s", "no connection");
649
+ return BSIG2NUM (f);
650
+ } catch (std::runtime_error e) {
651
+ rb_raise (EM_eConnectionError, "%s", e.what());
652
+ }
653
+ return Qnil;
654
+ }
655
+
656
+ /*********************
657
+ t_bind_connect_server
658
+ *********************/
659
+
660
+ static VALUE t_bind_connect_server (VALUE self UNUSED, VALUE bind_addr, VALUE bind_port, VALUE server, VALUE port)
661
+ {
662
+ // Avoid FIX2INT in this case, because it doesn't deal with type errors properly.
663
+ // Specifically, if the value of port comes in as a string rather than an integer,
664
+ // NUM2INT will throw a type error, but FIX2INT will generate garbage.
665
+
666
+ try {
667
+ const uintptr_t f = evma_connect_to_server (StringValueCStr(bind_addr), NUM2INT(bind_port), StringValueCStr(server), NUM2INT(port));
668
+ if (!f)
669
+ rb_raise (EM_eConnectionError, "%s", "no connection");
670
+ return BSIG2NUM (f);
671
+ } catch (std::runtime_error e) {
672
+ rb_raise (EM_eConnectionError, "%s", e.what());
673
+ }
674
+ return Qnil;
675
+ }
676
+
677
+ /*********************
678
+ t_connect_unix_server
679
+ *********************/
680
+
681
+ static VALUE t_connect_unix_server (VALUE self UNUSED, VALUE serversocket)
682
+ {
683
+ const uintptr_t f = evma_connect_to_unix_server (StringValueCStr(serversocket));
684
+ if (!f)
685
+ rb_raise (rb_eRuntimeError, "%s", "no connection");
686
+ return BSIG2NUM (f);
687
+ }
688
+
689
+ /***********
690
+ t_attach_fd
691
+ ***********/
692
+
693
+ static VALUE t_attach_fd (VALUE self UNUSED, VALUE file_descriptor, VALUE watch_mode)
694
+ {
695
+ const uintptr_t f = evma_attach_fd (NUM2INT(file_descriptor), watch_mode == Qtrue);
696
+ if (!f)
697
+ rb_raise (rb_eRuntimeError, "%s", "no connection");
698
+ return BSIG2NUM (f);
699
+ }
700
+
701
+ /***********
702
+ t_detach_fd
703
+ ***********/
704
+
705
+ static VALUE t_detach_fd (VALUE self UNUSED, VALUE signature)
706
+ {
707
+ return INT2NUM(evma_detach_fd (NUM2BSIG (signature)));
708
+ }
709
+
710
+ /*********************
711
+ t_get_file_descriptor
712
+ *********************/
713
+ static VALUE t_get_file_descriptor (VALUE self UNUSED, VALUE signature)
714
+ {
715
+ return INT2NUM(evma_get_file_descriptor (NUM2BSIG (signature)));
716
+ }
717
+
718
+ /**************
719
+ t_get_sock_opt
720
+ **************/
721
+
722
+ static VALUE t_get_sock_opt (VALUE self UNUSED, VALUE signature, VALUE lev, VALUE optname)
723
+ {
724
+ int fd = evma_get_file_descriptor (NUM2BSIG (signature));
725
+ int level = NUM2INT(lev), option = NUM2INT(optname);
726
+ socklen_t len = 128;
727
+ char buf[128];
728
+
729
+ if (getsockopt(fd, level, option, buf, &len) < 0)
730
+ rb_sys_fail("getsockopt");
731
+
732
+ return rb_str_new(buf, len);
733
+ }
734
+
735
+ /**************
736
+ t_set_sock_opt
737
+ **************/
738
+
739
+ static VALUE t_set_sock_opt (VALUE self UNUSED, VALUE signature, VALUE lev, VALUE optname, VALUE optval)
740
+ {
741
+ int fd = evma_get_file_descriptor (NUM2BSIG (signature));
742
+ int level = NUM2INT(lev), option = NUM2INT(optname);
743
+ int i;
744
+ const void *v;
745
+ socklen_t len;
746
+
747
+ switch (TYPE(optval)) {
748
+ case T_FIXNUM:
749
+ i = FIX2INT(optval);
750
+ goto numval;
751
+ case T_FALSE:
752
+ i = 0;
753
+ goto numval;
754
+ case T_TRUE:
755
+ i = 1;
756
+ numval:
757
+ v = (void*)&i; len = sizeof(i);
758
+ break;
759
+ default:
760
+ StringValue(optval);
761
+ v = RSTRING_PTR(optval);
762
+ len = RSTRING_LENINT(optval);
763
+ break;
764
+ }
765
+
766
+
767
+ if (setsockopt(fd, level, option, (char *)v, len) < 0)
768
+ rb_sys_fail("setsockopt");
769
+
770
+ return INT2FIX(0);
771
+ }
772
+
773
+ /********************
774
+ t_is_notify_readable
775
+ ********************/
776
+
777
+ static VALUE t_is_notify_readable (VALUE self UNUSED, VALUE signature)
778
+ {
779
+ return evma_is_notify_readable(NUM2BSIG (signature)) ? Qtrue : Qfalse;
780
+ }
781
+
782
+ /*********************
783
+ t_set_notify_readable
784
+ *********************/
785
+
786
+ static VALUE t_set_notify_readable (VALUE self UNUSED, VALUE signature, VALUE mode)
787
+ {
788
+ evma_set_notify_readable(NUM2BSIG(signature), mode == Qtrue);
789
+ return Qnil;
790
+ }
791
+
792
+ /********************
793
+ t_is_notify_readable
794
+ ********************/
795
+
796
+ static VALUE t_is_notify_writable (VALUE self UNUSED, VALUE signature)
797
+ {
798
+ return evma_is_notify_writable(NUM2BSIG (signature)) ? Qtrue : Qfalse;
799
+ }
800
+
801
+ /*********************
802
+ t_set_notify_writable
803
+ *********************/
804
+
805
+ static VALUE t_set_notify_writable (VALUE self UNUSED, VALUE signature, VALUE mode)
806
+ {
807
+ evma_set_notify_writable(NUM2BSIG (signature), mode == Qtrue);
808
+ return Qnil;
809
+ }
810
+
811
+ /*******
812
+ t_pause
813
+ *******/
814
+
815
+ static VALUE t_pause (VALUE self UNUSED, VALUE signature)
816
+ {
817
+ return evma_pause(NUM2BSIG (signature)) ? Qtrue : Qfalse;
818
+ }
819
+
820
+ /********
821
+ t_resume
822
+ ********/
823
+
824
+ static VALUE t_resume (VALUE self UNUSED, VALUE signature)
825
+ {
826
+ return evma_resume(NUM2BSIG (signature)) ? Qtrue : Qfalse;
827
+ }
828
+
829
+ /**********
830
+ t_paused_p
831
+ **********/
832
+
833
+ static VALUE t_paused_p (VALUE self UNUSED, VALUE signature)
834
+ {
835
+ return evma_is_paused(NUM2BSIG (signature)) ? Qtrue : Qfalse;
836
+ }
837
+
838
+ /*********************
839
+ t_num_close_scheduled
840
+ *********************/
841
+
842
+ static VALUE t_num_close_scheduled (VALUE self UNUSED)
843
+ {
844
+ return INT2FIX(evma_num_close_scheduled());
845
+ }
846
+
847
+ /*****************
848
+ t_open_udp_socket
849
+ *****************/
850
+
851
+ static VALUE t_open_udp_socket (VALUE self UNUSED, VALUE server, VALUE port)
852
+ {
853
+ const uintptr_t f = evma_open_datagram_socket (StringValueCStr(server), FIX2INT(port));
854
+ if (!f)
855
+ rb_raise (rb_eRuntimeError, "%s", "no datagram socket");
856
+ return BSIG2NUM(f);
857
+ }
858
+
859
+
860
+
861
+ /*****************
862
+ t_release_machine
863
+ *****************/
864
+
865
+ static VALUE t_release_machine (VALUE self UNUSED)
866
+ {
867
+ evma_release_library();
868
+ return Qnil;
869
+ }
870
+
871
+
872
+ /******
873
+ t_stop
874
+ ******/
875
+
876
+ static VALUE t_stop (VALUE self UNUSED)
877
+ {
878
+ evma_stop_machine();
879
+ return Qnil;
880
+ }
881
+
882
+ /******************
883
+ t_signal_loopbreak
884
+ ******************/
885
+
886
+ static VALUE t_signal_loopbreak (VALUE self UNUSED)
887
+ {
888
+ evma_signal_loopbreak();
889
+ return Qnil;
890
+ }
891
+
892
+ /**************
893
+ t_library_type
894
+ **************/
895
+
896
+ static VALUE t_library_type (VALUE self UNUSED)
897
+ {
898
+ return rb_eval_string (":extension");
899
+ }
900
+
901
+
902
+
903
+ /*******************
904
+ t_set_timer_quantum
905
+ *******************/
906
+
907
+ static VALUE t_set_timer_quantum (VALUE self UNUSED, VALUE interval)
908
+ {
909
+ evma_set_timer_quantum (FIX2INT (interval));
910
+ return Qnil;
911
+ }
912
+
913
+ /********************
914
+ t_get_max_timer_count
915
+ ********************/
916
+
917
+ static VALUE t_get_max_timer_count (VALUE self UNUSED)
918
+ {
919
+ return INT2FIX (evma_get_max_timer_count());
920
+ }
921
+
922
+ /********************
923
+ t_set_max_timer_count
924
+ ********************/
925
+
926
+ static VALUE t_set_max_timer_count (VALUE self UNUSED, VALUE ct)
927
+ {
928
+ evma_set_max_timer_count (FIX2INT (ct));
929
+ return Qnil;
930
+ }
931
+
932
+ /********************
933
+ t_get/set_simultaneous_accept_count
934
+ ********************/
935
+
936
+ static VALUE t_get_simultaneous_accept_count (VALUE self UNUSED)
937
+ {
938
+ return INT2FIX (evma_get_simultaneous_accept_count());
939
+ }
940
+
941
+ static VALUE t_set_simultaneous_accept_count (VALUE self UNUSED, VALUE ct)
942
+ {
943
+ evma_set_simultaneous_accept_count (FIX2INT (ct));
944
+ return Qnil;
945
+ }
946
+
947
+ /***************
948
+ t_setuid_string
949
+ ***************/
950
+
951
+ static VALUE t_setuid_string (VALUE self UNUSED, VALUE username)
952
+ {
953
+ evma_setuid_string (StringValueCStr (username));
954
+ return Qnil;
955
+ }
956
+
957
+
958
+
959
+ /**************
960
+ t_invoke_popen
961
+ **************/
962
+
963
+ static VALUE t_invoke_popen (VALUE self UNUSED, VALUE cmd)
964
+ {
965
+ #ifdef OS_WIN32
966
+ rb_raise (EM_eUnsupported, "popen is not available on this platform");
967
+ #endif
968
+
969
+ int len = RARRAY_LEN(cmd);
970
+ if (len >= 2048)
971
+ rb_raise (rb_eRuntimeError, "%s", "too many arguments to popen");
972
+ char *strings [2048];
973
+ for (int i=0; i < len; i++) {
974
+ VALUE ix = INT2FIX (i);
975
+ VALUE s = rb_ary_aref (1, &ix, cmd);
976
+ strings[i] = StringValueCStr (s);
977
+ }
978
+ strings[len] = NULL;
979
+
980
+ uintptr_t f = 0;
981
+ try {
982
+ f = evma_popen (strings);
983
+ } catch (std::runtime_error e) {
984
+ rb_raise (rb_eRuntimeError, "%s", e.what());
985
+ }
986
+ if (!f) {
987
+ char *err = strerror (errno);
988
+ char buf[100];
989
+ memset (buf, 0, sizeof(buf));
990
+ snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
991
+ rb_raise (rb_eRuntimeError, "%s", buf);
992
+ }
993
+ return BSIG2NUM (f);
994
+ }
995
+
996
+
997
+ /***************
998
+ t_read_keyboard
999
+ ***************/
1000
+
1001
+ static VALUE t_read_keyboard (VALUE self UNUSED)
1002
+ {
1003
+ const uintptr_t f = evma_open_keyboard();
1004
+ if (!f)
1005
+ rb_raise (rb_eRuntimeError, "%s", "no keyboard reader");
1006
+ return BSIG2NUM (f);
1007
+ }
1008
+
1009
+
1010
+ /****************
1011
+ t_watch_filename
1012
+ ****************/
1013
+
1014
+ static VALUE t_watch_filename (VALUE self UNUSED, VALUE fname)
1015
+ {
1016
+ try {
1017
+ return BSIG2NUM(evma_watch_filename(StringValueCStr(fname)));
1018
+ } catch (std::runtime_error e) {
1019
+ rb_raise (EM_eUnsupported, "%s", e.what());
1020
+ }
1021
+ return Qnil;
1022
+ }
1023
+
1024
+
1025
+ /******************
1026
+ t_unwatch_filename
1027
+ ******************/
1028
+
1029
+ static VALUE t_unwatch_filename (VALUE self UNUSED, VALUE sig)
1030
+ {
1031
+ evma_unwatch_filename(NUM2BSIG (sig));
1032
+ return Qnil;
1033
+ }
1034
+
1035
+
1036
+ /***********
1037
+ t_watch_pid
1038
+ ***********/
1039
+
1040
+ static VALUE t_watch_pid (VALUE self UNUSED, VALUE pid)
1041
+ {
1042
+ try {
1043
+ return BSIG2NUM(evma_watch_pid(NUM2INT(pid)));
1044
+ } catch (std::runtime_error e) {
1045
+ rb_raise (EM_eUnsupported, "%s", e.what());
1046
+ }
1047
+ return Qnil;
1048
+ }
1049
+
1050
+
1051
+ /*************
1052
+ t_unwatch_pid
1053
+ *************/
1054
+
1055
+ static VALUE t_unwatch_pid (VALUE self UNUSED, VALUE sig)
1056
+ {
1057
+ evma_unwatch_pid(NUM2BSIG (sig));
1058
+ return Qnil;
1059
+ }
1060
+
1061
+
1062
+ /**********
1063
+ t__epoll_p
1064
+ **********/
1065
+
1066
+ static VALUE t__epoll_p (VALUE self UNUSED)
1067
+ {
1068
+ #ifdef HAVE_EPOLL
1069
+ return Qtrue;
1070
+ #else
1071
+ return Qfalse;
1072
+ #endif
1073
+ }
1074
+
1075
+ /********
1076
+ t__epoll
1077
+ ********/
1078
+
1079
+ static VALUE t__epoll (VALUE self UNUSED)
1080
+ {
1081
+ if (t__epoll_p(self) == Qfalse)
1082
+ return Qfalse;
1083
+
1084
+ evma_set_epoll (1);
1085
+ return Qtrue;
1086
+ }
1087
+
1088
+ /***********
1089
+ t__epoll_set
1090
+ ***********/
1091
+
1092
+ static VALUE t__epoll_set (VALUE self, VALUE val)
1093
+ {
1094
+ if (t__epoll_p(self) == Qfalse && val == Qtrue)
1095
+ rb_raise (EM_eUnsupported, "%s", "epoll is not supported on this platform");
1096
+
1097
+ evma_set_epoll (val == Qtrue ? 1 : 0);
1098
+ return val;
1099
+ }
1100
+
1101
+
1102
+ /***********
1103
+ t__kqueue_p
1104
+ ***********/
1105
+
1106
+ static VALUE t__kqueue_p (VALUE self UNUSED)
1107
+ {
1108
+ #ifdef HAVE_KQUEUE
1109
+ return Qtrue;
1110
+ #else
1111
+ return Qfalse;
1112
+ #endif
1113
+ }
1114
+
1115
+ /*********
1116
+ t__kqueue
1117
+ *********/
1118
+
1119
+ static VALUE t__kqueue (VALUE self UNUSED)
1120
+ {
1121
+ if (t__kqueue_p(self) == Qfalse)
1122
+ return Qfalse;
1123
+
1124
+ evma_set_kqueue (1);
1125
+ return Qtrue;
1126
+ }
1127
+
1128
+ /*************
1129
+ t__kqueue_set
1130
+ *************/
1131
+
1132
+ static VALUE t__kqueue_set (VALUE self, VALUE val)
1133
+ {
1134
+ if (t__kqueue_p(self) == Qfalse && val == Qtrue)
1135
+ rb_raise (EM_eUnsupported, "%s", "kqueue is not supported on this platform");
1136
+
1137
+ evma_set_kqueue (val == Qtrue ? 1 : 0);
1138
+ return val;
1139
+ }
1140
+
1141
+
1142
+ /********
1143
+ t__ssl_p
1144
+ ********/
1145
+
1146
+ static VALUE t__ssl_p (VALUE self UNUSED)
1147
+ {
1148
+ #ifdef WITH_SSL
1149
+ return Qtrue;
1150
+ #else
1151
+ return Qfalse;
1152
+ #endif
1153
+ }
1154
+
1155
+ /********
1156
+ t_stopping
1157
+ ********/
1158
+
1159
+ static VALUE t_stopping ()
1160
+ {
1161
+ if (evma_stopping())
1162
+ {
1163
+ return Qtrue;
1164
+ }
1165
+ else
1166
+ {
1167
+ return Qfalse;
1168
+ }
1169
+
1170
+ }
1171
+
1172
+
1173
+ /****************
1174
+ t_send_file_data
1175
+ ****************/
1176
+
1177
+ static VALUE t_send_file_data (VALUE self UNUSED, VALUE signature, VALUE filename)
1178
+ {
1179
+
1180
+ /* The current implementation of evma_send_file_data_to_connection enforces a strict
1181
+ * upper limit on the file size it will transmit (currently 32K). The function returns
1182
+ * zero on success, -1 if the requested file exceeds its size limit, and a positive
1183
+ * number for other errors.
1184
+ * TODO: Positive return values are actually errno's, which is probably the wrong way to
1185
+ * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
1186
+ */
1187
+
1188
+ int b = evma_send_file_data_to_connection (NUM2BSIG (signature), StringValueCStr(filename));
1189
+ if (b == -1)
1190
+ rb_raise(rb_eRuntimeError, "%s", "File too large. send_file_data() supports files under 32k.");
1191
+ if (b > 0) {
1192
+ char *err = strerror (b);
1193
+ char buf[1024];
1194
+ memset (buf, 0, sizeof(buf));
1195
+ snprintf (buf, sizeof(buf)-1, ": %s %s", StringValueCStr(filename),(err?err:"???"));
1196
+
1197
+ rb_raise (rb_eIOError, "%s", buf);
1198
+ }
1199
+
1200
+ return INT2NUM (0);
1201
+ }
1202
+
1203
+
1204
+ /*******************
1205
+ t_set_rlimit_nofile
1206
+ *******************/
1207
+
1208
+ static VALUE t_set_rlimit_nofile (VALUE self UNUSED, VALUE arg)
1209
+ {
1210
+ arg = (NIL_P(arg)) ? -1 : NUM2INT (arg);
1211
+ return INT2NUM (evma_set_rlimit_nofile (arg));
1212
+ }
1213
+
1214
+ /***************************
1215
+ conn_get_outbound_data_size
1216
+ ***************************/
1217
+
1218
+ static VALUE conn_get_outbound_data_size (VALUE self)
1219
+ {
1220
+ VALUE sig = rb_ivar_get (self, Intern_at_signature);
1221
+ return INT2NUM (evma_get_outbound_data_size (NUM2BSIG (sig)));
1222
+ }
1223
+
1224
+
1225
+ /******************************
1226
+ conn_associate_callback_target
1227
+ ******************************/
1228
+
1229
+ static VALUE conn_associate_callback_target (VALUE self UNUSED, VALUE sig UNUSED)
1230
+ {
1231
+ // No-op for the time being.
1232
+ return Qnil;
1233
+ }
1234
+
1235
+
1236
+ /***************
1237
+ t_get_loop_time
1238
+ ****************/
1239
+
1240
+ static VALUE t_get_loop_time (VALUE self UNUSED)
1241
+ {
1242
+ uint64_t current_time = evma_get_current_loop_time();
1243
+ if (current_time == 0) {
1244
+ return Qnil;
1245
+ }
1246
+
1247
+ // Generally the industry has moved to 64-bit time_t, this is just in case we're 32-bit time_t.
1248
+ if (sizeof(time_t) < 8 && current_time > INT_MAX) {
1249
+ return rb_funcall(rb_cTime, Intern_at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000));
1250
+ } else {
1251
+ return rb_time_new(current_time / 1000000, current_time % 1000000);
1252
+ }
1253
+ }
1254
+
1255
+
1256
+ /*************
1257
+ t_start_proxy
1258
+ **************/
1259
+
1260
+ static VALUE t_start_proxy (VALUE self UNUSED, VALUE from, VALUE to, VALUE bufsize, VALUE length)
1261
+ {
1262
+ try {
1263
+ evma_start_proxy(NUM2BSIG (from), NUM2BSIG (to), NUM2ULONG(bufsize), NUM2ULONG(length));
1264
+ } catch (std::runtime_error e) {
1265
+ rb_raise (EM_eConnectionError, "%s", e.what());
1266
+ }
1267
+ return Qnil;
1268
+ }
1269
+
1270
+
1271
+ /************
1272
+ t_stop_proxy
1273
+ *************/
1274
+
1275
+ static VALUE t_stop_proxy (VALUE self UNUSED, VALUE from)
1276
+ {
1277
+ try{
1278
+ evma_stop_proxy(NUM2BSIG (from));
1279
+ } catch (std::runtime_error e) {
1280
+ rb_raise (EM_eConnectionError, "%s", e.what());
1281
+ }
1282
+ return Qnil;
1283
+ }
1284
+
1285
+ /***************
1286
+ t_proxied_bytes
1287
+ ****************/
1288
+
1289
+ static VALUE t_proxied_bytes (VALUE self UNUSED, VALUE from)
1290
+ {
1291
+ try{
1292
+ return BSIG2NUM(evma_proxied_bytes(NUM2BSIG (from)));
1293
+ } catch (std::runtime_error e) {
1294
+ rb_raise (EM_eConnectionError, "%s", e.what());
1295
+ }
1296
+ return Qnil;
1297
+ }
1298
+
1299
+ /***************
1300
+ t_get_idle_time
1301
+ ****************/
1302
+
1303
+ static VALUE t_get_idle_time (VALUE self UNUSED, VALUE from)
1304
+ {
1305
+ try{
1306
+ uint64_t current_time = evma_get_current_loop_time();
1307
+ uint64_t time = evma_get_last_activity_time(NUM2BSIG (from));
1308
+ if (current_time != 0 && time != 0) {
1309
+ if (time >= current_time)
1310
+ return BSIG2NUM(0);
1311
+ else {
1312
+ uint64_t diff = current_time - time;
1313
+ float seconds = diff / (1000.0*1000.0);
1314
+ return rb_float_new(seconds);
1315
+ }
1316
+ return Qnil;
1317
+ }
1318
+ } catch (std::runtime_error e) {
1319
+ rb_raise (EM_eConnectionError, "%s", e.what());
1320
+ }
1321
+ return Qnil;
1322
+ }
1323
+
1324
+ /************************
1325
+ t_get_heartbeat_interval
1326
+ *************************/
1327
+
1328
+ static VALUE t_get_heartbeat_interval (VALUE self UNUSED)
1329
+ {
1330
+ return rb_float_new(evma_get_heartbeat_interval());
1331
+ }
1332
+
1333
+
1334
+ /************************
1335
+ t_set_heartbeat_interval
1336
+ *************************/
1337
+
1338
+ static VALUE t_set_heartbeat_interval (VALUE self UNUSED, VALUE interval)
1339
+ {
1340
+ float iv = RFLOAT_VALUE(interval);
1341
+ if (evma_set_heartbeat_interval(iv))
1342
+ return Qtrue;
1343
+ return Qfalse;
1344
+ }
1345
+
1346
+
1347
+ /*********************
1348
+ Init_rubyeventmachine
1349
+ *********************/
1350
+
1351
+ extern "C" void Init_rubyeventmachine()
1352
+ {
1353
+ // Lookup Process::Status for get_subprocess_status
1354
+ VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
1355
+ rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));
1356
+
1357
+ // Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
1358
+ Intern_at_signature = rb_intern ("@signature");
1359
+ Intern_at_timers = rb_intern ("@timers");
1360
+ Intern_at_conns = rb_intern ("@conns");
1361
+ Intern_at_error_handler = rb_intern("@error_handler");
1362
+
1363
+ Intern_event_callback = rb_intern ("event_callback");
1364
+ Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
1365
+ Intern_delete = rb_intern ("delete");
1366
+ Intern_call = rb_intern ("call");
1367
+ Intern_at = rb_intern("at");
1368
+ Intern_receive_data = rb_intern ("receive_data");
1369
+ Intern_ssl_handshake_completed = rb_intern ("ssl_handshake_completed");
1370
+ Intern_ssl_verify_peer = rb_intern ("ssl_verify_peer");
1371
+ Intern_notify_readable = rb_intern ("notify_readable");
1372
+ Intern_notify_writable = rb_intern ("notify_writable");
1373
+ Intern_proxy_target_unbound = rb_intern ("proxy_target_unbound");
1374
+ Intern_proxy_completed = rb_intern ("proxy_completed");
1375
+ Intern_connection_completed = rb_intern ("connection_completed");
1376
+
1377
+ // INCOMPLETE, we need to define class Connections inside module EventMachine
1378
+ // run_machine and run_machine_without_threads are now identical.
1379
+ // Must deprecate the without_threads variant.
1380
+ EmModule = rb_define_module ("EventMachine");
1381
+ EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);
1382
+
1383
+ rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eRuntimeError);
1384
+ EM_eConnectionError = rb_define_class_under (EmModule, "ConnectionError", rb_eRuntimeError);
1385
+ EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
1386
+ EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
1387
+ EM_eUnsupported = rb_define_class_under (EmModule, "Unsupported", rb_eRuntimeError);
1388
+
1389
+ rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
1390
+ rb_define_module_function (EmModule, "run_machine_once", (VALUE(*)(...))t_run_machine_once, 0);
1391
+ rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine, 0);
1392
+ rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine, 0);
1393
+ rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
1394
+ rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
1395
+ rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
1396
+ rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
1397
+ rb_define_module_function (EmModule, "attach_sd", (VALUE(*)(...))t_attach_sd, 1);
1398
+ rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 10);
1399
+ rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
1400
+ rb_define_module_function (EmModule, "get_peer_cert", (VALUE(*)(...))t_get_peer_cert, 1);
1401
+ rb_define_module_function (EmModule, "get_cipher_bits", (VALUE(*)(...))t_get_cipher_bits, 1);
1402
+ rb_define_module_function (EmModule, "get_cipher_name", (VALUE(*)(...))t_get_cipher_name, 1);
1403
+ rb_define_module_function (EmModule, "get_cipher_protocol", (VALUE(*)(...))t_get_cipher_protocol, 1);
1404
+ rb_define_module_function (EmModule, "get_sni_hostname", (VALUE(*)(...))t_get_sni_hostname, 1);
1405
+ rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
1406
+ rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
1407
+ rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
1408
+ rb_define_module_function (EmModule, "report_connection_error_status", (VALUE(*)(...))t_report_connection_error_status, 1);
1409
+ rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
1410
+ rb_define_module_function (EmModule, "bind_connect_server", (VALUE(*)(...))t_bind_connect_server, 4);
1411
+ rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);
1412
+
1413
+ rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 2);
1414
+ rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
1415
+ rb_define_module_function (EmModule, "get_file_descriptor", (VALUE (*)(...))t_get_file_descriptor, 1);
1416
+ rb_define_module_function (EmModule, "get_sock_opt", (VALUE (*)(...))t_get_sock_opt, 3);
1417
+ rb_define_module_function (EmModule, "set_sock_opt", (VALUE (*)(...))t_set_sock_opt, 4);
1418
+ rb_define_module_function (EmModule, "set_notify_readable", (VALUE (*)(...))t_set_notify_readable, 2);
1419
+ rb_define_module_function (EmModule, "set_notify_writable", (VALUE (*)(...))t_set_notify_writable, 2);
1420
+ rb_define_module_function (EmModule, "is_notify_readable", (VALUE (*)(...))t_is_notify_readable, 1);
1421
+ rb_define_module_function (EmModule, "is_notify_writable", (VALUE (*)(...))t_is_notify_writable, 1);
1422
+
1423
+ rb_define_module_function (EmModule, "pause_connection", (VALUE (*)(...))t_pause, 1);
1424
+ rb_define_module_function (EmModule, "resume_connection", (VALUE (*)(...))t_resume, 1);
1425
+ rb_define_module_function (EmModule, "connection_paused?", (VALUE (*)(...))t_paused_p, 1);
1426
+ rb_define_module_function (EmModule, "num_close_scheduled", (VALUE (*)(...))t_num_close_scheduled, 0);
1427
+
1428
+ rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 4);
1429
+ rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
1430
+ rb_define_module_function (EmModule, "get_proxied_bytes", (VALUE (*)(...))t_proxied_bytes, 1);
1431
+
1432
+ rb_define_module_function (EmModule, "watch_filename", (VALUE (*)(...))t_watch_filename, 1);
1433
+ rb_define_module_function (EmModule, "unwatch_filename", (VALUE (*)(...))t_unwatch_filename, 1);
1434
+
1435
+ rb_define_module_function (EmModule, "watch_pid", (VALUE (*)(...))t_watch_pid, 1);
1436
+ rb_define_module_function (EmModule, "unwatch_pid", (VALUE (*)(...))t_unwatch_pid, 1);
1437
+
1438
+ rb_define_module_function (EmModule, "current_time", (VALUE(*)(...))t_get_loop_time, 0);
1439
+
1440
+ rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
1441
+ rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
1442
+ rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
1443
+ rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
1444
+ rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
1445
+ rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
1446
+ rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
1447
+ rb_define_module_function (EmModule, "get_max_timer_count", (VALUE(*)(...))t_get_max_timer_count, 0);
1448
+ rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
1449
+ rb_define_module_function (EmModule, "get_simultaneous_accept_count", (VALUE(*)(...))t_get_simultaneous_accept_count, 0);
1450
+ rb_define_module_function (EmModule, "set_simultaneous_accept_count", (VALUE(*)(...))t_set_simultaneous_accept_count, 1);
1451
+ rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
1452
+ rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
1453
+ rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
1454
+ rb_define_module_function (EmModule, "get_heartbeat_interval", (VALUE(*)(...))t_get_heartbeat_interval, 0);
1455
+ rb_define_module_function (EmModule, "set_heartbeat_interval", (VALUE(*)(...))t_set_heartbeat_interval, 1);
1456
+ rb_define_module_function (EmModule, "get_idle_time", (VALUE(*)(...))t_get_idle_time, 1);
1457
+
1458
+ rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
1459
+ rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
1460
+ rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
1461
+ rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
1462
+ rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
1463
+ rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
1464
+ rb_define_module_function (EmModule, "get_pending_connect_timeout", (VALUE(*)(...))t_get_pending_connect_timeout, 1);
1465
+ rb_define_module_function (EmModule, "set_pending_connect_timeout", (VALUE(*)(...))t_set_pending_connect_timeout, 2);
1466
+ rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
1467
+ rb_define_module_function (EmModule, "get_connection_count", (VALUE(*)(...))t_get_connection_count, 0);
1468
+
1469
+ rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
1470
+ rb_define_module_function (EmModule, "epoll=", (VALUE(*)(...))t__epoll_set, 1);
1471
+ rb_define_module_function (EmModule, "epoll?", (VALUE(*)(...))t__epoll_p, 0);
1472
+
1473
+ rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
1474
+ rb_define_module_function (EmModule, "kqueue=", (VALUE(*)(...))t__kqueue_set, 1);
1475
+ rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);
1476
+
1477
+ rb_define_module_function (EmModule, "ssl?", (VALUE(*)(...))t__ssl_p, 0);
1478
+ rb_define_module_function(EmModule, "stopping?",(VALUE(*)(...))t_stopping, 0);
1479
+
1480
+ rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
1481
+ rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);
1482
+
1483
+ // Connection states
1484
+ rb_define_const (EmModule, "TimerFired", INT2NUM(EM_TIMER_FIRED ));
1485
+ rb_define_const (EmModule, "ConnectionData", INT2NUM(EM_CONNECTION_READ ));
1486
+ rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(EM_CONNECTION_UNBOUND ));
1487
+ rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(EM_CONNECTION_ACCEPTED ));
1488
+ rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(EM_CONNECTION_COMPLETED ));
1489
+ rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(EM_LOOPBREAK_SIGNAL ));
1490
+ rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(EM_CONNECTION_NOTIFY_READABLE));
1491
+ rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(EM_CONNECTION_NOTIFY_WRITABLE));
1492
+ rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(EM_SSL_HANDSHAKE_COMPLETED ));
1493
+ // EM_SSL_VERIFY = 109,
1494
+ // EM_PROXY_TARGET_UNBOUND = 110,
1495
+ // EM_PROXY_COMPLETED = 111
1496
+
1497
+ // SSL Protocols
1498
+ rb_define_const (EmModule, "EM_PROTO_SSLv2", INT2NUM(EM_PROTO_SSLv2 ));
1499
+ rb_define_const (EmModule, "EM_PROTO_SSLv3", INT2NUM(EM_PROTO_SSLv3 ));
1500
+ rb_define_const (EmModule, "EM_PROTO_TLSv1", INT2NUM(EM_PROTO_TLSv1 ));
1501
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_1", INT2NUM(EM_PROTO_TLSv1_1));
1502
+ rb_define_const (EmModule, "EM_PROTO_TLSv1_2", INT2NUM(EM_PROTO_TLSv1_2));
1503
+ }
1504
+