wj_eventmachine 1.3.0.dev.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 (180) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +179 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +110 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +520 -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 +52 -0
  35. data/ext/cmain.cpp +1046 -0
  36. data/ext/ed.cpp +2238 -0
  37. data/ext/ed.h +460 -0
  38. data/ext/em.cpp +2378 -0
  39. data/ext/em.h +266 -0
  40. data/ext/eventmachine.h +152 -0
  41. data/ext/extconf.rb +285 -0
  42. data/ext/fastfilereader/extconf.rb +120 -0
  43. data/ext/fastfilereader/mapper.cpp +214 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +126 -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 +174 -0
  51. data/ext/rubymain.cpp +1610 -0
  52. data/ext/ssl.cpp +627 -0
  53. data/ext/ssl.h +103 -0
  54. data/ext/wait_for_single_fd.h +36 -0
  55. data/java/.classpath +8 -0
  56. data/java/.project +17 -0
  57. data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
  58. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  59. data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
  60. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  61. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  62. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  63. data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
  64. data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
  65. data/lib/em/buftok.rb +59 -0
  66. data/lib/em/callback.rb +58 -0
  67. data/lib/em/channel.rb +69 -0
  68. data/lib/em/completion.rb +307 -0
  69. data/lib/em/connection.rb +776 -0
  70. data/lib/em/deferrable.rb +210 -0
  71. data/lib/em/deferrable/pool.rb +2 -0
  72. data/lib/em/file_watch.rb +73 -0
  73. data/lib/em/future.rb +61 -0
  74. data/lib/em/io_streamer.rb +68 -0
  75. data/lib/em/iterator.rb +252 -0
  76. data/lib/em/messages.rb +66 -0
  77. data/lib/em/pool.rb +151 -0
  78. data/lib/em/process_watch.rb +45 -0
  79. data/lib/em/processes.rb +123 -0
  80. data/lib/em/protocols.rb +37 -0
  81. data/lib/em/protocols/header_and_content.rb +138 -0
  82. data/lib/em/protocols/httpclient.rb +303 -0
  83. data/lib/em/protocols/httpclient2.rb +602 -0
  84. data/lib/em/protocols/line_and_text.rb +125 -0
  85. data/lib/em/protocols/line_protocol.rb +33 -0
  86. data/lib/em/protocols/linetext2.rb +179 -0
  87. data/lib/em/protocols/memcache.rb +331 -0
  88. data/lib/em/protocols/object_protocol.rb +46 -0
  89. data/lib/em/protocols/postgres3.rb +246 -0
  90. data/lib/em/protocols/saslauth.rb +175 -0
  91. data/lib/em/protocols/smtpclient.rb +394 -0
  92. data/lib/em/protocols/smtpserver.rb +666 -0
  93. data/lib/em/protocols/socks4.rb +66 -0
  94. data/lib/em/protocols/stomp.rb +205 -0
  95. data/lib/em/protocols/tcptest.rb +54 -0
  96. data/lib/em/pure_ruby.rb +1299 -0
  97. data/lib/em/queue.rb +80 -0
  98. data/lib/em/resolver.rb +232 -0
  99. data/lib/em/spawnable.rb +84 -0
  100. data/lib/em/streamer.rb +118 -0
  101. data/lib/em/threaded_resource.rb +90 -0
  102. data/lib/em/tick_loop.rb +85 -0
  103. data/lib/em/timers.rb +61 -0
  104. data/lib/em/version.rb +3 -0
  105. data/lib/eventmachine.rb +1602 -0
  106. data/lib/jeventmachine.rb +318 -0
  107. data/rakelib/package.rake +120 -0
  108. data/rakelib/test.rake +6 -0
  109. data/rakelib/test_pure.rake +11 -0
  110. data/tests/client.crt +31 -0
  111. data/tests/client.key +51 -0
  112. data/tests/dhparam.pem +13 -0
  113. data/tests/em_ssl_handlers.rb +153 -0
  114. data/tests/em_test_helper.rb +198 -0
  115. data/tests/jruby/test_jeventmachine.rb +38 -0
  116. data/tests/test_attach.rb +199 -0
  117. data/tests/test_basic.rb +321 -0
  118. data/tests/test_channel.rb +75 -0
  119. data/tests/test_completion.rb +178 -0
  120. data/tests/test_connection_count.rb +83 -0
  121. data/tests/test_connection_write.rb +35 -0
  122. data/tests/test_defer.rb +35 -0
  123. data/tests/test_deferrable.rb +35 -0
  124. data/tests/test_epoll.rb +141 -0
  125. data/tests/test_error_handler.rb +38 -0
  126. data/tests/test_exc.rb +37 -0
  127. data/tests/test_file_watch.rb +86 -0
  128. data/tests/test_fork.rb +75 -0
  129. data/tests/test_futures.rb +170 -0
  130. data/tests/test_handler_check.rb +35 -0
  131. data/tests/test_hc.rb +155 -0
  132. data/tests/test_httpclient.rb +238 -0
  133. data/tests/test_httpclient2.rb +132 -0
  134. data/tests/test_idle_connection.rb +31 -0
  135. data/tests/test_inactivity_timeout.rb +102 -0
  136. data/tests/test_io_streamer.rb +47 -0
  137. data/tests/test_ipv4.rb +96 -0
  138. data/tests/test_ipv6.rb +107 -0
  139. data/tests/test_iterator.rb +122 -0
  140. data/tests/test_kb.rb +28 -0
  141. data/tests/test_keepalive.rb +113 -0
  142. data/tests/test_line_protocol.rb +33 -0
  143. data/tests/test_ltp.rb +155 -0
  144. data/tests/test_ltp2.rb +332 -0
  145. data/tests/test_many_fds.rb +21 -0
  146. data/tests/test_next_tick.rb +104 -0
  147. data/tests/test_object_protocol.rb +36 -0
  148. data/tests/test_pause.rb +109 -0
  149. data/tests/test_pending_connect_timeout.rb +52 -0
  150. data/tests/test_pool.rb +196 -0
  151. data/tests/test_process_watch.rb +50 -0
  152. data/tests/test_processes.rb +128 -0
  153. data/tests/test_proxy_connection.rb +180 -0
  154. data/tests/test_pure.rb +156 -0
  155. data/tests/test_queue.rb +64 -0
  156. data/tests/test_resolver.rb +129 -0
  157. data/tests/test_running.rb +14 -0
  158. data/tests/test_sasl.rb +46 -0
  159. data/tests/test_send_file.rb +217 -0
  160. data/tests/test_servers.rb +32 -0
  161. data/tests/test_shutdown_hooks.rb +23 -0
  162. data/tests/test_smtpclient.rb +75 -0
  163. data/tests/test_smtpserver.rb +90 -0
  164. data/tests/test_sock_opt.rb +53 -0
  165. data/tests/test_spawn.rb +290 -0
  166. data/tests/test_ssl_args.rb +41 -0
  167. data/tests/test_ssl_dhparam.rb +57 -0
  168. data/tests/test_ssl_ecdh_curve.rb +57 -0
  169. data/tests/test_ssl_extensions.rb +24 -0
  170. data/tests/test_ssl_methods.rb +31 -0
  171. data/tests/test_ssl_protocols.rb +190 -0
  172. data/tests/test_ssl_verify.rb +52 -0
  173. data/tests/test_stomp.rb +38 -0
  174. data/tests/test_system.rb +46 -0
  175. data/tests/test_threaded_resource.rb +68 -0
  176. data/tests/test_tick_loop.rb +58 -0
  177. data/tests/test_timers.rb +150 -0
  178. data/tests/test_ud.rb +8 -0
  179. data/tests/test_unbind_reason.rb +40 -0
  180. metadata +384 -0
@@ -0,0 +1,266 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: em.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
+ #ifndef __EventMachine__H_
21
+ #define __EventMachine__H_
22
+
23
+ #ifdef BUILD_FOR_RUBY
24
+ #include <ruby.h>
25
+ #include <ruby/thread.h>
26
+ #include <ruby/io.h>
27
+
28
+ #ifndef HAVE_RB_WAIT_FOR_SINGLE_FD
29
+ #include "wait_for_single_fd.h"
30
+ #endif
31
+
32
+ #if !defined(HAVE_TYPE_RB_FDSET_T)
33
+ #define fd_check(n) (((n) < FD_SETSIZE) ? 1 : 0*fprintf(stderr, "fd %d too large for select\n", (n)))
34
+ // These definitions are cribbed from include/ruby/intern.h in Ruby 1.9.3,
35
+ // with this change: any macros that read or write the nth element of an
36
+ // fdset first call fd_check to make sure n is in bounds.
37
+ typedef fd_set rb_fdset_t;
38
+ #define rb_fd_zero(f) FD_ZERO(f)
39
+ #define rb_fd_set(n, f) do { if (fd_check(n)) FD_SET((n), (f)); } while(0)
40
+ #define rb_fd_clr(n, f) do { if (fd_check(n)) FD_CLR((n), (f)); } while(0)
41
+ #define rb_fd_isset(n, f) (fd_check(n) ? FD_ISSET((n), (f)) : 0)
42
+ #define rb_fd_init(f) FD_ZERO(f)
43
+ #define rb_fd_term(f) ((void)(f))
44
+ #endif
45
+
46
+ #ifdef HAVE_RB_THREAD_FD_SELECT
47
+ #define EmSelect rb_thread_fd_select
48
+ #else
49
+ #define EmSelect select
50
+ #endif
51
+ #else
52
+ #define EmSelect select
53
+ #endif
54
+
55
+ // This Solaris fix is adapted from eval_intern.h in Ruby 1.9.3:
56
+ // Solaris sys/select.h switches select to select_large_fdset to support larger
57
+ // file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
58
+ // But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
59
+ // So following definition is required to use select_large_fdset.
60
+ #ifdef HAVE_SELECT_LARGE_FDSET
61
+ #define select(n, r, w, e, t) select_large_fdset((n), (r), (w), (e), (t))
62
+ extern "C" {
63
+ int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval *);
64
+ }
65
+ #endif
66
+
67
+ class EventableDescriptor;
68
+ class InotifyDescriptor;
69
+ struct SelectData_t;
70
+
71
+ /*************
72
+ enum Poller_t
73
+ *************/
74
+ enum Poller_t {
75
+ Poller_Default, // typically Select
76
+ Poller_Epoll,
77
+ Poller_Kqueue
78
+ };
79
+
80
+
81
+ /********************
82
+ class EventMachine_t
83
+ ********************/
84
+
85
+ class EventMachine_t
86
+ {
87
+ public:
88
+ static int GetMaxTimerCount();
89
+ static void SetMaxTimerCount (int);
90
+
91
+ static int GetSimultaneousAcceptCount();
92
+ static void SetSimultaneousAcceptCount (int);
93
+
94
+ public:
95
+ EventMachine_t (EMCallback, Poller_t);
96
+ virtual ~EventMachine_t();
97
+
98
+ bool RunOnce();
99
+ void Run();
100
+ void ScheduleHalt();
101
+ bool Stopping();
102
+ void SignalLoopBreaker();
103
+ size_t GetTimerCount();
104
+ const uintptr_t InstallOneshotTimer (uint64_t);
105
+ const uintptr_t ConnectToServer (const char *, int, const char *, int);
106
+ const uintptr_t ConnectToUnixServer (const char *);
107
+
108
+ const uintptr_t CreateTcpServer (const char *, int);
109
+ const uintptr_t OpenDatagramSocket (const char *, int);
110
+ const uintptr_t CreateUnixDomainServer (const char*);
111
+ const uintptr_t AttachSD (SOCKET);
112
+ const uintptr_t OpenKeyboard();
113
+ //const char *Popen (const char*, const char*);
114
+ const uintptr_t Socketpair (char* const*);
115
+
116
+ void Add (EventableDescriptor*);
117
+ void Modify (EventableDescriptor*);
118
+ void Deregister (EventableDescriptor*);
119
+
120
+ const uintptr_t AttachFD (SOCKET, bool);
121
+ int DetachFD (EventableDescriptor*);
122
+
123
+ void ArmKqueueWriter (EventableDescriptor*);
124
+ void ArmKqueueReader (EventableDescriptor*);
125
+
126
+ uint64_t GetTimerQuantum();
127
+ void SetTimerQuantum (int);
128
+ static void SetuidString (const char*);
129
+ static int SetRlimitNofile (int);
130
+
131
+ pid_t SubprocessPid;
132
+ int SubprocessExitStatus;
133
+
134
+ int GetConnectionCount();
135
+ float GetHeartbeatInterval();
136
+ int SetHeartbeatInterval(float);
137
+
138
+ const uintptr_t WatchFile (const char*);
139
+ void UnwatchFile (int);
140
+ void UnwatchFile (const uintptr_t);
141
+
142
+ #ifdef HAVE_KQUEUE
143
+ void _HandleKqueueFileEvent (struct kevent*);
144
+ void _RegisterKqueueFileEvent(int);
145
+ #endif
146
+
147
+ const uintptr_t WatchPid (int);
148
+ void UnwatchPid (int);
149
+ void UnwatchPid (const uintptr_t);
150
+
151
+ #ifdef HAVE_KQUEUE
152
+ void _HandleKqueuePidEvent (struct kevent*);
153
+ #endif
154
+
155
+ uint64_t GetCurrentLoopTime() { return MyCurrentLoopTime; }
156
+
157
+ void QueueHeartbeat(EventableDescriptor*);
158
+ void ClearHeartbeat(uint64_t, EventableDescriptor*);
159
+
160
+ uint64_t GetRealTime();
161
+
162
+ Poller_t GetPoller() { return Poller; }
163
+
164
+ static int name2address (const char *server, int port, int socktype, struct sockaddr *addr, size_t *addr_len);
165
+
166
+ private:
167
+ void _RunTimers();
168
+ void _UpdateTime();
169
+ void _AddNewDescriptors();
170
+ void _ModifyDescriptors();
171
+ void _InitializeLoopBreaker();
172
+ void _CleanupSockets();
173
+
174
+ void _RunSelectOnce();
175
+ void _RunEpollOnce();
176
+ void _RunKqueueOnce();
177
+
178
+ void _ModifyEpollEvent (EventableDescriptor*);
179
+ void _DispatchHeartbeats();
180
+ timeval _TimeTilNextEvent();
181
+ void _CleanBadDescriptors();
182
+
183
+ public:
184
+ void _ReadLoopBreaker();
185
+ void _ReadInotifyEvents();
186
+ int NumCloseScheduled;
187
+
188
+ private:
189
+ enum {
190
+ MaxEvents = 4096
191
+ };
192
+ int HeartbeatInterval;
193
+ EMCallback EventCallback;
194
+
195
+ class Timer_t: public Bindable_t {
196
+ };
197
+
198
+ std::multimap<uint64_t, Timer_t> Timers;
199
+ std::multimap<uint64_t, EventableDescriptor*> Heartbeats;
200
+ std::map<int, Bindable_t*> Files;
201
+ std::map<int, Bindable_t*> Pids;
202
+ std::vector<EventableDescriptor*> Descriptors;
203
+ std::vector<EventableDescriptor*> NewDescriptors;
204
+ std::set<EventableDescriptor*> ModifiedDescriptors;
205
+
206
+ SOCKET LoopBreakerReader;
207
+ SOCKET LoopBreakerWriter;
208
+ #ifdef OS_WIN32
209
+ struct sockaddr_in LoopBreakerTarget;
210
+ #endif
211
+
212
+ timeval Quantum;
213
+
214
+ uint64_t MyCurrentLoopTime;
215
+
216
+ #ifdef OS_WIN32
217
+ unsigned TickCountTickover;
218
+ unsigned LastTickCount;
219
+ #endif
220
+
221
+ #ifdef OS_DARWIN
222
+ mach_timebase_info_data_t mach_timebase;
223
+ #endif
224
+
225
+ private:
226
+ bool bTerminateSignalReceived;
227
+ SelectData_t *SelectData;
228
+
229
+ Poller_t Poller;
230
+
231
+ int epfd; // Epoll file-descriptor
232
+ #ifdef HAVE_EPOLL
233
+ struct epoll_event epoll_events [MaxEvents];
234
+ #endif
235
+
236
+ int kqfd; // Kqueue file-descriptor
237
+ #ifdef HAVE_KQUEUE
238
+ struct kevent Karray [MaxEvents];
239
+ #endif
240
+
241
+ #ifdef HAVE_INOTIFY
242
+ InotifyDescriptor *inotify; // pollable descriptor for our inotify instance
243
+ #endif
244
+ };
245
+
246
+
247
+ /*******************
248
+ struct SelectData_t
249
+ *******************/
250
+
251
+ struct SelectData_t
252
+ {
253
+ SelectData_t();
254
+ ~SelectData_t();
255
+
256
+ int _Select();
257
+ void _Clear();
258
+
259
+ SOCKET maxsocket;
260
+ rb_fdset_t fdreads;
261
+ rb_fdset_t fdwrites;
262
+ rb_fdset_t fderrors;
263
+ timeval tv;
264
+ };
265
+
266
+ #endif // __EventMachine__H_
@@ -0,0 +1,152 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: eventmachine.h
6
+ Date: 15Apr06
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
+ #ifndef __EVMA_EventMachine__H_
21
+ #define __EVMA_EventMachine__H_
22
+
23
+ #if __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ enum { // Event names
28
+ EM_TIMER_FIRED = 100,
29
+ EM_CONNECTION_READ = 101,
30
+ EM_CONNECTION_UNBOUND = 102,
31
+ EM_CONNECTION_ACCEPTED = 103,
32
+ EM_CONNECTION_COMPLETED = 104,
33
+ EM_LOOPBREAK_SIGNAL = 105,
34
+ EM_CONNECTION_NOTIFY_READABLE = 106,
35
+ EM_CONNECTION_NOTIFY_WRITABLE = 107,
36
+ EM_SSL_HANDSHAKE_COMPLETED = 108,
37
+ EM_SSL_VERIFY = 109,
38
+ EM_PROXY_TARGET_UNBOUND = 110,
39
+ EM_PROXY_COMPLETED = 111
40
+ };
41
+
42
+ enum { // SSL/TLS Protocols
43
+ EM_PROTO_SSLv2 = 2,
44
+ EM_PROTO_SSLv3 = 4,
45
+ EM_PROTO_TLSv1 = 8,
46
+ EM_PROTO_TLSv1_1 = 16,
47
+ #ifdef TLS1_3_VERSION
48
+ EM_PROTO_TLSv1_2 = 32,
49
+ EM_PROTO_TLSv1_3 = 64
50
+ #else
51
+ EM_PROTO_TLSv1_2 = 32
52
+ #endif
53
+ };
54
+
55
+ void evma_initialize_library (EMCallback);
56
+ bool evma_run_machine_once();
57
+ void evma_run_machine();
58
+ void evma_release_library();
59
+ const size_t evma_get_timer_count ();
60
+ const uintptr_t evma_install_oneshot_timer (uint64_t milliseconds);
61
+ const uintptr_t evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
62
+ const uintptr_t evma_connect_to_unix_server (const char *server);
63
+
64
+ const uintptr_t evma_attach_fd (int file_descriptor, int watch_mode);
65
+ int evma_detach_fd (const uintptr_t binding);
66
+ int evma_get_file_descriptor (const uintptr_t binding);
67
+ int evma_is_notify_readable (const uintptr_t binding);
68
+ void evma_set_notify_readable (const uintptr_t binding, int mode);
69
+ int evma_is_notify_writable (const uintptr_t binding);
70
+ void evma_set_notify_writable (const uintptr_t binding, int mode);
71
+
72
+ int evma_pause(const uintptr_t binding);
73
+ int evma_is_paused(const uintptr_t binding);
74
+ int evma_resume(const uintptr_t binding);
75
+
76
+ int evma_num_close_scheduled();
77
+
78
+ void evma_stop_tcp_server (const uintptr_t binding);
79
+ const uintptr_t evma_create_tcp_server (const char *address, int port);
80
+ const uintptr_t evma_create_unix_domain_server (const char *filename);
81
+ const uintptr_t evma_attach_sd (int sd);
82
+ const uintptr_t evma_open_datagram_socket (const char *server, int port);
83
+ const uintptr_t evma_open_keyboard();
84
+ void evma_set_tls_parms (const uintptr_t binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer, int fail_if_no_peer_cert, const char *sni_hostname, const char *cipherlist, const char *ecdh_curve, const char *dhparam, int protocols);
85
+ void evma_start_tls (const uintptr_t binding);
86
+
87
+ #ifdef WITH_SSL
88
+ X509 *evma_get_peer_cert (const uintptr_t binding);
89
+ int evma_get_cipher_bits (const uintptr_t binding);
90
+ const char *evma_get_cipher_name (const uintptr_t binding);
91
+ const char *evma_get_cipher_protocol (const uintptr_t binding);
92
+ const char *evma_get_sni_hostname (const uintptr_t binding);
93
+ void evma_accept_ssl_peer (const uintptr_t binding);
94
+ #endif
95
+
96
+ int evma_get_peername (const uintptr_t binding, struct sockaddr*, socklen_t*);
97
+ int evma_get_sockname (const uintptr_t binding, struct sockaddr*, socklen_t*);
98
+ int evma_get_subprocess_pid (const uintptr_t binding, pid_t*);
99
+ int evma_get_subprocess_status (const uintptr_t binding, int*);
100
+ int evma_enable_keepalive (const uintptr_t binding, int idle, int intvl, int cnt);
101
+ int evma_disable_keepalive (const uintptr_t binding);
102
+ int evma_get_connection_count();
103
+ int evma_send_data_to_connection (const uintptr_t binding, const char *data, int data_length);
104
+ int evma_send_datagram (const uintptr_t binding, const char *data, int data_length, const char *address, int port);
105
+ float evma_get_comm_inactivity_timeout (const uintptr_t binding);
106
+ int evma_set_comm_inactivity_timeout (const uintptr_t binding, float value);
107
+ float evma_get_pending_connect_timeout (const uintptr_t binding);
108
+ int evma_set_pending_connect_timeout (const uintptr_t binding, float value);
109
+ int evma_get_outbound_data_size (const uintptr_t binding);
110
+ uint64_t evma_get_last_activity_time (const uintptr_t binding);
111
+ int evma_send_file_data_to_connection (const uintptr_t binding, const char *filename);
112
+
113
+ void evma_close_connection (const uintptr_t binding, int after_writing);
114
+ int evma_report_connection_error_status (const uintptr_t binding);
115
+ void evma_signal_loopbreak();
116
+ void evma_set_timer_quantum (int);
117
+ int evma_get_max_timer_count();
118
+ void evma_set_max_timer_count (int);
119
+ int evma_get_simultaneous_accept_count();
120
+ void evma_set_simultaneous_accept_count (int);
121
+ void evma_setuid_string (const char *username);
122
+ void evma_stop_machine();
123
+ bool evma_stopping();
124
+ float evma_get_heartbeat_interval();
125
+ int evma_set_heartbeat_interval(float);
126
+
127
+ const uintptr_t evma_popen (char * const*cmd_strings);
128
+
129
+ const uintptr_t evma_watch_filename (const char *fname);
130
+ void evma_unwatch_filename (const uintptr_t binding);
131
+
132
+ const uintptr_t evma_watch_pid (int);
133
+ void evma_unwatch_pid (const uintptr_t binding);
134
+ int evma_is_watch_only(const uintptr_t binding);
135
+
136
+ void evma_start_proxy(const uintptr_t from, const uintptr_t to, const unsigned long bufsize, const unsigned long length);
137
+ void evma_stop_proxy(const uintptr_t from);
138
+ unsigned long evma_proxied_bytes(const uintptr_t from);
139
+
140
+ int evma_set_rlimit_nofile (int n_files);
141
+
142
+ void evma_set_epoll (int use);
143
+ void evma_set_kqueue (int use);
144
+
145
+ uint64_t evma_get_current_loop_time();
146
+ #if __cplusplus
147
+ }
148
+ #endif
149
+
150
+
151
+ #endif // __EventMachine__H_
152
+
@@ -0,0 +1,285 @@
1
+ require 'fileutils'
2
+ require 'mkmf'
3
+
4
+ # Eager check devs tools
5
+ have_devel? if respond_to?(:have_devel?)
6
+
7
+ def check_libs libs = [], fatal = false
8
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
9
+ end
10
+
11
+ def check_heads heads = [], fatal = false
12
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
13
+ end
14
+
15
+ def add_define(name)
16
+ $defs.push("-D#{name}")
17
+ end
18
+
19
+ ##
20
+ # OpenSSL:
21
+
22
+ # override append_library, so it actually appends (instead of prepending)
23
+ # this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
24
+ def append_library(libs, lib)
25
+ libs + " " + format(LIBARG, lib)
26
+ end
27
+
28
+ def dir_config_wrapper(pretty_name, name, idefault=nil, ldefault=nil)
29
+ inc, lib = dir_config(name, idefault, ldefault)
30
+ if inc && lib
31
+ unless idefault && ldefault
32
+ abort "-----\nCannot find #{pretty_name} include path #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
33
+ abort "-----\nCannot find #{pretty_name} library path #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
34
+ warn "-----\nUsing #{pretty_name} in path #{File.dirname inc}\n-----"
35
+ end
36
+ true
37
+ end
38
+ end
39
+
40
+ def dir_config_search(pretty_name, name, paths, &b)
41
+ paths.each do |p|
42
+ if dir_config_wrapper(pretty_name, name, p + '/include', p + '/lib') && yield
43
+ warn "-----\nFound #{pretty_name} in path #{p}\n-----"
44
+ return true
45
+ end
46
+ end
47
+ false
48
+ end
49
+
50
+ def pkg_config_wrapper(pretty_name, name)
51
+ cflags, ldflags, libs = pkg_config(name)
52
+ unless [cflags, ldflags, libs].any?(&:nil?) || [cflags, ldflags, libs].any?(&:empty?)
53
+ warn "-----\nUsing #{pretty_name} from pkg-config #{cflags} && #{ldflags} && #{libs}\n-----"
54
+ true
55
+ end
56
+ end
57
+
58
+ def find_openssl_library
59
+ if $mswin || $mingw
60
+ # required for static OpenSSL libraries
61
+ have_library("gdi32") # OpenSSL <= 1.0.2 (for RAND_screen())
62
+ have_library("crypt32")
63
+ end
64
+
65
+ return false unless have_header("openssl/ssl.h") && have_header("openssl/err.h")
66
+
67
+ ret = have_library("crypto", "CRYPTO_malloc") &&
68
+ have_library("ssl", "SSL_new")
69
+ return ret if ret
70
+ end
71
+
72
+ if ENV['CROSS_COMPILING']
73
+ openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.2e")
74
+ openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-#{openssl_version}/")
75
+ if File.exist?(openssl_dir)
76
+ FileUtils.mkdir_p Dir.pwd+"/openssl/"
77
+ FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
78
+ FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
79
+ $INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
80
+ add_define "WITH_SSL"
81
+ else
82
+ STDERR.puts
83
+ STDERR.puts "**************************************************************************************"
84
+ STDERR.puts "**** Cross-compiled OpenSSL not found"
85
+ STDERR.puts "**** Run: hg clone http://bitbucket.org/ged/ruby-pg && cd ruby-pg && rake openssl_libs"
86
+ STDERR.puts "**************************************************************************************"
87
+ STDERR.puts
88
+ end
89
+ elsif dir_config_wrapper('OpenSSL', 'openssl')
90
+ # If the user has provided a --with-openssl-dir argument, we must respect it or fail.
91
+ add_define 'WITH_SSL' if find_openssl_library
92
+ elsif dir_config_wrapper('OpenSSL', 'ssl')
93
+ # If the user has provided a --with-ssl-dir argument, we must respect it or fail.
94
+ add_define 'WITH_SSL' if find_openssl_library
95
+ elsif pkg_config_wrapper('OpenSSL', 'openssl')
96
+ # If we can detect OpenSSL by pkg-config, use it as the next-best option
97
+ add_define 'WITH_SSL' if find_openssl_library
98
+ elsif find_openssl_library
99
+ # If we don't even need any options to find a usable OpenSSL, go with it
100
+ add_define 'WITH_SSL'
101
+ elsif dir_config_search('OpenSSL', 'openssl', ['/usr/local', '/opt/local', '/usr/local/opt/openssl']) do
102
+ find_openssl_library
103
+ end
104
+ # Finally, look for OpenSSL in alternate locations including MacPorts and HomeBrew
105
+ add_define 'WITH_SSL'
106
+ end
107
+
108
+ add_define 'BUILD_FOR_RUBY'
109
+
110
+ # Rubinius workarounds:
111
+ have_type('rb_fdset_t', 'ruby/intern.h')
112
+ have_func('rb_wait_for_single_fd')
113
+ have_func('rb_thread_fd_select')
114
+
115
+ # System features:
116
+
117
+ add_define('HAVE_INOTIFY') if inotify = have_func('inotify_init', 'sys/inotify.h')
118
+ add_define('HAVE_OLD_INOTIFY') if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
119
+ have_func('writev', 'sys/uio.h')
120
+ have_func('pipe2', 'unistd.h')
121
+ have_func('accept4', 'sys/socket.h')
122
+ have_const('SOCK_CLOEXEC', 'sys/socket.h')
123
+
124
+ # Minor platform details between *nix and Windows:
125
+
126
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
127
+ GNU_CHAIN = ENV['CROSS_COMPILING'] || $1 == 'mingw'
128
+ OS_WIN32 = true
129
+ add_define "OS_WIN32"
130
+ else
131
+ GNU_CHAIN = true
132
+ OS_UNIX = true
133
+ add_define 'OS_UNIX'
134
+
135
+ add_define "HAVE_KQUEUE" if have_header("sys/event.h") && have_header("sys/queue.h")
136
+ end
137
+
138
+ # Adjust number of file descriptors (FD) on Windows
139
+
140
+ if RbConfig::CONFIG["host_os"] =~ /mingw/
141
+ found = RbConfig::CONFIG.values_at("CFLAGS", "CPPFLAGS").
142
+ any? { |v| v.include?("FD_SETSIZE") }
143
+
144
+ add_define "FD_SETSIZE=32767" unless found
145
+ # needed for new versions of headers-git & crt-git
146
+ if RbConfig::CONFIG["ruby_version"] >= "2.4"
147
+ append_ldflags "-l:libssp.a -fstack-protector"
148
+ end
149
+ end
150
+
151
+ # Main platform invariances:
152
+
153
+ ldshared = CONFIG['LDSHARED']
154
+
155
+ case RUBY_PLATFORM
156
+ when /mswin32/, /mingw32/, /bccwin32/
157
+ check_heads(%w[windows.h winsock.h], true)
158
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
159
+
160
+ if GNU_CHAIN
161
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -static-libgcc -static-libstdc++"
162
+ else
163
+ $defs.push "-EHs"
164
+ $defs.push "-GR"
165
+ end
166
+
167
+ # Newer versions of Ruby already define _WIN32_WINNT, which is needed
168
+ # to get access to newer POSIX networking functions (e.g. getaddrinfo)
169
+ add_define '_WIN32_WINNT=0x0501' unless have_func('getaddrinfo')
170
+
171
+ when /solaris/
172
+ add_define 'OS_SOLARIS8'
173
+ check_libs(%w[nsl socket], true)
174
+
175
+ # If Ruby was compiled for 32-bits, then select() can only handle 1024 fds
176
+ # There is an alternate function, select_large_fdset, that supports more.
177
+ have_func('select_large_fdset', 'sys/select.h')
178
+
179
+ if CONFIG['CC'] == 'cc' && (
180
+ `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
181
+ `cc -V 2>&1` =~ /Sun/ # detect Solaris Studio compiler
182
+ )
183
+ # SUN CHAIN
184
+ add_define 'CC_SUNWspro'
185
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
186
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
187
+ CONFIG['CCDLFLAGS'] = "-KPIC"
188
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
189
+ CONFIG['LDSHAREDXX'] = "$(CXX) -G -KPIC -lCstd"
190
+ else
191
+ # GNU CHAIN
192
+ # on Unix we need a g++ link, not gcc.
193
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
194
+ end
195
+
196
+ when /openbsd/
197
+ # OpenBSD branch contributed by Guillaume Sellier.
198
+
199
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
200
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
201
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
202
+
203
+ when /darwin/
204
+ add_define 'OS_DARWIN'
205
+
206
+ # on Unix we need a g++ link, not gcc.
207
+ # Ff line contributed by Daniel Harple.
208
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
209
+
210
+ when /linux/
211
+ # epoll_create1 was added in Linux 2.6.27 and glibc 2.9
212
+ add_define 'HAVE_EPOLL' if have_func('epoll_create1', 'sys/epoll.h')
213
+
214
+ # on Unix we need a g++ link, not gcc.
215
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
216
+
217
+ when /aix/
218
+ CONFIG['LDSHARED'] = "$(CXX) -Wl,-bstatic -Wl,-bdynamic -Wl,-G -Wl,-brtl"
219
+
220
+ when /cygwin/
221
+ # For rubies built with Cygwin, CXX may be set to CC, which is just
222
+ # a wrapper for gcc.
223
+ # This will compile, but it will not link to the C++ std library.
224
+ # Explicitly set CXX to use g++.
225
+ CONFIG['CXX'] = "g++"
226
+ # on Unix we need a g++ link, not gcc.
227
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
228
+
229
+ else
230
+ # on Unix we need a g++ link, not gcc.
231
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
232
+ end
233
+
234
+ if RUBY_ENGINE == "truffleruby"
235
+ # Keep the original LDSHARED on TruffleRuby, as linking is done on bitcode
236
+ CONFIG['LDSHARED'] = ldshared
237
+ end
238
+
239
+ # Platform-specific time functions
240
+ if have_func('clock_gettime')
241
+ # clock_gettime is POSIX, but the monotonic clocks are not
242
+ have_const('CLOCK_MONOTONIC_RAW', 'time.h') # Linux
243
+ have_const('CLOCK_MONOTONIC', 'time.h') # Linux, Solaris, BSDs
244
+ else
245
+ have_func('gethrtime') # Older Solaris and HP-UX
246
+ end
247
+
248
+ # OpenSSL version checks
249
+ # below are yes for 1.1.0 & later, may need to check func rather than macro
250
+ # with versions after 1.1.1
251
+ have_func "TLS_server_method" , "openssl/ssl.h"
252
+ have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
253
+
254
+ # Hack so that try_link will test with a C++ compiler instead of a C compiler
255
+ TRY_LINK.sub!('$(CC)', '$(CXX)')
256
+
257
+ # This is our wishlist. We use whichever flags work on the host.
258
+ # In the future, add -Werror to make sure all warnings are resolved.
259
+ # deprecated-declarations are used in OS X OpenSSL
260
+ # ignored-qualifiers are used by the Bindings (would-be void *)
261
+ # unused-result because GCC 4.6 no longer silences (void) ignore_this(function)
262
+ # address because on Windows, rb_fd_select checks if &fds is non-NULL, which it cannot be
263
+ %w(
264
+ -Wall
265
+ -Wextra
266
+ -Wno-deprecated-declarations
267
+ -Wno-ignored-qualifiers
268
+ -Wno-unused-result
269
+ -Wno-address
270
+ ).select do |flag|
271
+ try_link('int main() {return 0;}', flag)
272
+ end.each do |flag|
273
+ CONFIG['CXXFLAGS'] << ' ' << flag
274
+ end
275
+ puts "CXXFLAGS=#{CONFIG['CXXFLAGS']}"
276
+
277
+ # Solaris C++ compiler doesn't have make_pair()
278
+ add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
279
+ #include <utility>
280
+ using namespace std;
281
+ int main(){ pair<const int,int> tuple = make_pair(1,2); }
282
+ SRC
283
+ TRY_LINK.sub!('$(CXX)', '$(CC)')
284
+
285
+ create_makefile "rubyeventmachine"