sonixlabs-eventmachine-java 1.0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +12 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +33 -0
  6. data/GNU +281 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +60 -0
  9. data/README.md +109 -0
  10. data/README_JP.md +18 -0
  11. data/Rakefile +20 -0
  12. data/docs/DocumentationGuidesIndex.md +27 -0
  13. data/docs/GettingStarted.md +521 -0
  14. data/docs/old/ChangeLog +211 -0
  15. data/docs/old/DEFERRABLES +246 -0
  16. data/docs/old/EPOLL +141 -0
  17. data/docs/old/INSTALL +13 -0
  18. data/docs/old/KEYBOARD +42 -0
  19. data/docs/old/LEGAL +25 -0
  20. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  21. data/docs/old/PURE_RUBY +75 -0
  22. data/docs/old/RELEASE_NOTES +94 -0
  23. data/docs/old/SMTP +4 -0
  24. data/docs/old/SPAWNED_PROCESSES +148 -0
  25. data/docs/old/TODO +8 -0
  26. data/eventmachine.gemspec +38 -0
  27. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  28. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  29. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  30. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  31. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  32. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  33. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  34. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  35. data/examples/old/ex_channel.rb +43 -0
  36. data/examples/old/ex_queue.rb +2 -0
  37. data/examples/old/ex_tick_loop_array.rb +15 -0
  38. data/examples/old/ex_tick_loop_counter.rb +32 -0
  39. data/examples/old/helper.rb +2 -0
  40. data/ext/binder.cpp +124 -0
  41. data/ext/binder.h +46 -0
  42. data/ext/cmain.cpp +887 -0
  43. data/ext/ed.cpp +1988 -0
  44. data/ext/ed.h +422 -0
  45. data/ext/em.cpp +2351 -0
  46. data/ext/em.h +244 -0
  47. data/ext/eventmachine.h +128 -0
  48. data/ext/extconf.rb +177 -0
  49. data/ext/fastfilereader/extconf.rb +103 -0
  50. data/ext/fastfilereader/mapper.cpp +214 -0
  51. data/ext/fastfilereader/mapper.h +59 -0
  52. data/ext/fastfilereader/rubymain.cpp +127 -0
  53. data/ext/kb.cpp +79 -0
  54. data/ext/page.cpp +107 -0
  55. data/ext/page.h +51 -0
  56. data/ext/pipe.cpp +347 -0
  57. data/ext/project.h +156 -0
  58. data/ext/rubymain.cpp +1318 -0
  59. data/ext/ssl.cpp +468 -0
  60. data/ext/ssl.h +94 -0
  61. data/java/.classpath +6 -0
  62. data/java/.gitignore +1 -0
  63. data/java/.project +17 -0
  64. data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
  65. data/java/src/com/rubyeventmachine/EmReactor.java +529 -0
  66. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  67. data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
  68. data/java/src/com/rubyeventmachine/EventCode.java +26 -0
  69. data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
  70. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +180 -0
  71. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
  72. data/java/src/com/rubyeventmachine/SslBox.java +310 -0
  73. data/lib/em/buftok.rb +110 -0
  74. data/lib/em/callback.rb +58 -0
  75. data/lib/em/channel.rb +64 -0
  76. data/lib/em/completion.rb +304 -0
  77. data/lib/em/connection.rb +712 -0
  78. data/lib/em/deferrable.rb +210 -0
  79. data/lib/em/deferrable/pool.rb +2 -0
  80. data/lib/em/file_watch.rb +73 -0
  81. data/lib/em/future.rb +61 -0
  82. data/lib/em/iterator.rb +231 -0
  83. data/lib/em/messages.rb +66 -0
  84. data/lib/em/pool.rb +151 -0
  85. data/lib/em/process_watch.rb +45 -0
  86. data/lib/em/processes.rb +123 -0
  87. data/lib/em/protocols.rb +37 -0
  88. data/lib/em/protocols/header_and_content.rb +138 -0
  89. data/lib/em/protocols/httpclient.rb +279 -0
  90. data/lib/em/protocols/httpclient2.rb +600 -0
  91. data/lib/em/protocols/line_and_text.rb +125 -0
  92. data/lib/em/protocols/line_protocol.rb +29 -0
  93. data/lib/em/protocols/linetext2.rb +161 -0
  94. data/lib/em/protocols/memcache.rb +331 -0
  95. data/lib/em/protocols/object_protocol.rb +46 -0
  96. data/lib/em/protocols/postgres3.rb +246 -0
  97. data/lib/em/protocols/saslauth.rb +175 -0
  98. data/lib/em/protocols/smtpclient.rb +365 -0
  99. data/lib/em/protocols/smtpserver.rb +643 -0
  100. data/lib/em/protocols/socks4.rb +66 -0
  101. data/lib/em/protocols/stomp.rb +205 -0
  102. data/lib/em/protocols/tcptest.rb +54 -0
  103. data/lib/em/pure_ruby.rb +1017 -0
  104. data/lib/em/queue.rb +71 -0
  105. data/lib/em/resolver.rb +192 -0
  106. data/lib/em/spawnable.rb +84 -0
  107. data/lib/em/streamer.rb +118 -0
  108. data/lib/em/threaded_resource.rb +90 -0
  109. data/lib/em/tick_loop.rb +85 -0
  110. data/lib/em/timers.rb +61 -0
  111. data/lib/em/version.rb +3 -0
  112. data/lib/eventmachine.rb +1553 -0
  113. data/lib/jeventmachine.rb +331 -0
  114. data/lib/sonixlabs-eventmachine-java.rb +1 -0
  115. data/rakelib/cpp.rake_example +77 -0
  116. data/rakelib/package.rake +96 -0
  117. data/rakelib/test.rake +8 -0
  118. data/tests/client.crt +31 -0
  119. data/tests/client.key +51 -0
  120. data/tests/em_test_helper.rb +64 -0
  121. data/tests/server.crt +36 -0
  122. data/tests/server.key +51 -0
  123. data/tests/test_attach.rb +150 -0
  124. data/tests/test_basic.rb +294 -0
  125. data/tests/test_channel.rb +62 -0
  126. data/tests/test_completion.rb +177 -0
  127. data/tests/test_connection_count.rb +53 -0
  128. data/tests/test_defer.rb +18 -0
  129. data/tests/test_deferrable.rb +35 -0
  130. data/tests/test_epoll.rb +145 -0
  131. data/tests/test_error_handler.rb +38 -0
  132. data/tests/test_exc.rb +28 -0
  133. data/tests/test_file_watch.rb +65 -0
  134. data/tests/test_futures.rb +170 -0
  135. data/tests/test_get_sock_opt.rb +37 -0
  136. data/tests/test_handler_check.rb +35 -0
  137. data/tests/test_hc.rb +155 -0
  138. data/tests/test_httpclient.rb +190 -0
  139. data/tests/test_httpclient2.rb +133 -0
  140. data/tests/test_idle_connection.rb +25 -0
  141. data/tests/test_inactivity_timeout.rb +54 -0
  142. data/tests/test_iterator.rb +97 -0
  143. data/tests/test_kb.rb +34 -0
  144. data/tests/test_line_protocol.rb +33 -0
  145. data/tests/test_ltp.rb +138 -0
  146. data/tests/test_ltp2.rb +288 -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 +102 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +194 -0
  152. data/tests/test_process_watch.rb +48 -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 +50 -0
  157. data/tests/test_resolver.rb +55 -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 +37 -0
  163. data/tests/test_shutdown_hooks.rb +23 -0
  164. data/tests/test_smtpclient.rb +55 -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_echo_data.rb +60 -0
  169. data/tests/test_ssl_methods.rb +56 -0
  170. data/tests/test_ssl_verify.rb +82 -0
  171. data/tests/test_stomp.rb +37 -0
  172. data/tests/test_system.rb +42 -0
  173. data/tests/test_threaded_resource.rb +53 -0
  174. data/tests/test_tick_loop.rb +59 -0
  175. data/tests/test_timers.rb +123 -0
  176. data/tests/test_ud.rb +8 -0
  177. data/tests/test_unbind_reason.rb +48 -0
  178. metadata +298 -0
@@ -0,0 +1,244 @@
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
+ #define EmSelect rb_thread_select
26
+
27
+ #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD
28
+ #include <ruby/io.h>
29
+ #endif
30
+
31
+ #if defined(HAVE_RBTRAP)
32
+ #include <rubysig.h>
33
+ #elif defined(HAVE_RB_ENABLE_INTERRUPT)
34
+ extern "C" {
35
+ void rb_enable_interrupt(void);
36
+ void rb_disable_interrupt(void);
37
+ }
38
+
39
+ #define TRAP_BEG rb_enable_interrupt()
40
+ #define TRAP_END do { rb_disable_interrupt(); rb_thread_check_ints(); } while(0)
41
+ #else
42
+ #define TRAP_BEG
43
+ #define TRAP_END
44
+ #endif
45
+
46
+ // 1.9.0 compat
47
+ #ifndef RUBY_UBF_IO
48
+ #define RUBY_UBF_IO RB_UBF_DFL
49
+ #endif
50
+ #ifndef RSTRING_PTR
51
+ #define RSTRING_PTR(str) RSTRING(str)->ptr
52
+ #endif
53
+ #ifndef RSTRING_LEN
54
+ #define RSTRING_LEN(str) RSTRING(str)->len
55
+ #endif
56
+ #ifndef RSTRING_LENINT
57
+ #define RSTRING_LENINT(str) RSTRING_LEN(str)
58
+ #endif
59
+ #else
60
+ #define EmSelect select
61
+ #endif
62
+
63
+ class EventableDescriptor;
64
+ class InotifyDescriptor;
65
+
66
+
67
+ /********************
68
+ class EventMachine_t
69
+ ********************/
70
+
71
+ class EventMachine_t
72
+ {
73
+ public:
74
+ static int GetMaxTimerCount();
75
+ static void SetMaxTimerCount (int);
76
+
77
+ public:
78
+ EventMachine_t (EMCallback);
79
+ virtual ~EventMachine_t();
80
+
81
+ void Run();
82
+ void ScheduleHalt();
83
+ void SignalLoopBreaker();
84
+ const unsigned long InstallOneshotTimer (int);
85
+ const unsigned long ConnectToServer (const char *, int, const char *, int);
86
+ const unsigned long ConnectToUnixServer (const char *);
87
+
88
+ const unsigned long CreateTcpServer (const char *, int);
89
+ const unsigned long OpenDatagramSocket (const char *, int);
90
+ const unsigned long CreateUnixDomainServer (const char*);
91
+ const unsigned long AttachSD (int);
92
+ const unsigned long OpenKeyboard();
93
+ //const char *Popen (const char*, const char*);
94
+ const unsigned long Socketpair (char* const*);
95
+
96
+ void Add (EventableDescriptor*);
97
+ void Modify (EventableDescriptor*);
98
+ void Deregister (EventableDescriptor*);
99
+
100
+ const unsigned long AttachFD (int, bool);
101
+ int DetachFD (EventableDescriptor*);
102
+
103
+ void ArmKqueueWriter (EventableDescriptor*);
104
+ void ArmKqueueReader (EventableDescriptor*);
105
+
106
+ void SetTimerQuantum (int);
107
+ static void SetuidString (const char*);
108
+ static int SetRlimitNofile (int);
109
+
110
+ pid_t SubprocessPid;
111
+ int SubprocessExitStatus;
112
+
113
+ int GetConnectionCount();
114
+ float GetHeartbeatInterval();
115
+ int SetHeartbeatInterval(float);
116
+
117
+ const unsigned long WatchFile (const char*);
118
+ void UnwatchFile (int);
119
+ void UnwatchFile (const unsigned long);
120
+
121
+ #ifdef HAVE_KQUEUE
122
+ void _HandleKqueueFileEvent (struct kevent*);
123
+ void _RegisterKqueueFileEvent(int);
124
+ #endif
125
+
126
+ const unsigned long WatchPid (int);
127
+ void UnwatchPid (int);
128
+ void UnwatchPid (const unsigned long);
129
+
130
+ #ifdef HAVE_KQUEUE
131
+ void _HandleKqueuePidEvent (struct kevent*);
132
+ #endif
133
+
134
+ uint64_t GetCurrentLoopTime() { return MyCurrentLoopTime; }
135
+
136
+ // Temporary:
137
+ void _UseEpoll();
138
+ void _UseKqueue();
139
+
140
+ bool UsingKqueue() { return bKqueue; }
141
+ bool UsingEpoll() { return bEpoll; }
142
+
143
+ void QueueHeartbeat(EventableDescriptor*);
144
+ void ClearHeartbeat(uint64_t, EventableDescriptor*);
145
+
146
+ uint64_t GetRealTime();
147
+
148
+ private:
149
+ void _RunOnce();
150
+ void _RunTimers();
151
+ void _UpdateTime();
152
+ void _AddNewDescriptors();
153
+ void _ModifyDescriptors();
154
+ void _InitializeLoopBreaker();
155
+ void _CleanupSockets();
156
+
157
+ void _RunSelectOnce();
158
+ void _RunEpollOnce();
159
+ void _RunKqueueOnce();
160
+
161
+ void _ModifyEpollEvent (EventableDescriptor*);
162
+ void _DispatchHeartbeats();
163
+ timeval _TimeTilNextEvent();
164
+ void _CleanBadDescriptors();
165
+
166
+ public:
167
+ void _ReadLoopBreaker();
168
+ void _ReadInotifyEvents();
169
+ int NumCloseScheduled;
170
+
171
+ private:
172
+ enum {
173
+ MaxEpollDescriptors = 64*1024,
174
+ MaxEvents = 4096
175
+ };
176
+ int HeartbeatInterval;
177
+ EMCallback EventCallback;
178
+
179
+ class Timer_t: public Bindable_t {
180
+ };
181
+
182
+ multimap<uint64_t, Timer_t> Timers;
183
+ multimap<uint64_t, EventableDescriptor*> Heartbeats;
184
+ map<int, Bindable_t*> Files;
185
+ map<int, Bindable_t*> Pids;
186
+ vector<EventableDescriptor*> Descriptors;
187
+ vector<EventableDescriptor*> NewDescriptors;
188
+ set<EventableDescriptor*> ModifiedDescriptors;
189
+
190
+ uint64_t NextHeartbeatTime;
191
+
192
+ int LoopBreakerReader;
193
+ int LoopBreakerWriter;
194
+ #ifdef OS_WIN32
195
+ struct sockaddr_in LoopBreakerTarget;
196
+ #endif
197
+
198
+ timeval Quantum;
199
+
200
+ uint64_t MyCurrentLoopTime;
201
+
202
+ #ifdef OS_WIN32
203
+ unsigned TickCountTickover;
204
+ unsigned LastTickCount;
205
+ #endif
206
+
207
+ private:
208
+ bool bTerminateSignalReceived;
209
+
210
+ bool bEpoll;
211
+ int epfd; // Epoll file-descriptor
212
+ #ifdef HAVE_EPOLL
213
+ struct epoll_event epoll_events [MaxEvents];
214
+ #endif
215
+
216
+ bool bKqueue;
217
+ int kqfd; // Kqueue file-descriptor
218
+ #ifdef HAVE_KQUEUE
219
+ struct kevent Karray [MaxEvents];
220
+ #endif
221
+
222
+ InotifyDescriptor *inotify; // pollable descriptor for our inotify instance
223
+ };
224
+
225
+
226
+ /*******************
227
+ struct SelectData_t
228
+ *******************/
229
+
230
+ struct SelectData_t
231
+ {
232
+ SelectData_t();
233
+
234
+ int _Select();
235
+
236
+ int maxsocket;
237
+ fd_set fdreads;
238
+ fd_set fdwrites;
239
+ fd_set fderrors;
240
+ timeval tv;
241
+ int nSockets;
242
+ };
243
+
244
+ #endif // __EventMachine__H_
@@ -0,0 +1,128 @@
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
+
43
+ void evma_initialize_library (EMCallback);
44
+ void evma_run_machine();
45
+ void evma_release_library();
46
+ const unsigned long evma_install_oneshot_timer (int seconds);
47
+ const unsigned long evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
48
+ const unsigned long evma_connect_to_unix_server (const char *server);
49
+
50
+ const unsigned long evma_attach_fd (int file_descriptor, int watch_mode);
51
+ int evma_detach_fd (const unsigned long binding);
52
+ int evma_get_file_descriptor (const unsigned long binding);
53
+ int evma_is_notify_readable (const unsigned long binding);
54
+ void evma_set_notify_readable (const unsigned long binding, int mode);
55
+ int evma_is_notify_writable (const unsigned long binding);
56
+ void evma_set_notify_writable (const unsigned long binding, int mode);
57
+
58
+ int evma_pause(const unsigned long binding);
59
+ int evma_is_paused(const unsigned long binding);
60
+ int evma_resume(const unsigned long binding);
61
+
62
+ int evma_num_close_scheduled();
63
+
64
+ void evma_stop_tcp_server (const unsigned long signature);
65
+ const unsigned long evma_create_tcp_server (const char *address, int port);
66
+ const unsigned long evma_create_unix_domain_server (const char *filename);
67
+ const unsigned long evma_attach_sd (int sd);
68
+ const unsigned long evma_open_datagram_socket (const char *server, int port);
69
+ const unsigned long evma_open_keyboard();
70
+ void evma_set_tls_parms (const unsigned long binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer);
71
+ void evma_start_tls (const unsigned long binding);
72
+
73
+ #ifdef WITH_SSL
74
+ X509 *evma_get_peer_cert (const unsigned long binding);
75
+ void evma_accept_ssl_peer (const unsigned long binding);
76
+ #endif
77
+
78
+ int evma_get_peername (const unsigned long binding, struct sockaddr*, socklen_t*);
79
+ int evma_get_sockname (const unsigned long binding, struct sockaddr*, socklen_t*);
80
+ int evma_get_subprocess_pid (const unsigned long binding, pid_t*);
81
+ int evma_get_subprocess_status (const unsigned long binding, int*);
82
+ int evma_get_connection_count();
83
+ int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length);
84
+ int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port);
85
+ float evma_get_comm_inactivity_timeout (const unsigned long binding);
86
+ int evma_set_comm_inactivity_timeout (const unsigned long binding, float value);
87
+ float evma_get_pending_connect_timeout (const unsigned long binding);
88
+ int evma_set_pending_connect_timeout (const unsigned long binding, float value);
89
+ int evma_get_outbound_data_size (const unsigned long binding);
90
+ uint64_t evma_get_last_activity_time (const unsigned long);
91
+ int evma_send_file_data_to_connection (const unsigned long binding, const char *filename);
92
+
93
+ void evma_close_connection (const unsigned long binding, int after_writing);
94
+ int evma_report_connection_error_status (const unsigned long binding);
95
+ void evma_signal_loopbreak();
96
+ void evma_set_timer_quantum (int);
97
+ int evma_get_max_timer_count();
98
+ void evma_set_max_timer_count (int);
99
+ void evma_setuid_string (const char *username);
100
+ void evma_stop_machine();
101
+ float evma_get_heartbeat_interval();
102
+ int evma_set_heartbeat_interval(float);
103
+
104
+ const unsigned long evma_popen (char * const*cmd_strings);
105
+
106
+ const unsigned long evma_watch_filename (const char *fname);
107
+ void evma_unwatch_filename (const unsigned long);
108
+
109
+ const unsigned long evma_watch_pid (int);
110
+ void evma_unwatch_pid (const unsigned long);
111
+
112
+ void evma_start_proxy(const unsigned long, const unsigned long, const unsigned long, const unsigned long);
113
+ void evma_stop_proxy(const unsigned long);
114
+ unsigned long evma_proxied_bytes(const unsigned long);
115
+
116
+ int evma_set_rlimit_nofile (int n_files);
117
+
118
+ void evma_set_epoll (int use);
119
+ void evma_set_kqueue (int use);
120
+
121
+ uint64_t evma_get_current_loop_time();
122
+ #if __cplusplus
123
+ }
124
+ #endif
125
+
126
+
127
+ #endif // __EventMachine__H_
128
+
@@ -0,0 +1,177 @@
1
+ require 'fileutils'
2
+ require 'mkmf'
3
+
4
+ def check_libs libs = [], fatal = false
5
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
6
+ end
7
+
8
+ def check_heads heads = [], fatal = false
9
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
10
+ end
11
+
12
+ def add_define(name)
13
+ $defs.push("-D#{name}")
14
+ end
15
+
16
+ ##
17
+ # OpenSSL:
18
+
19
+ # override append_library, so it actually appends (instead of prepending)
20
+ # this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
21
+ def append_library(libs, lib)
22
+ libs + " " + format(LIBARG, lib)
23
+ end
24
+
25
+ def manual_ssl_config
26
+ ssl_libs_heads_args = {
27
+ :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
28
+ :mswin => [%w[ssleay32 eay32], %w[openssl/ssl.h openssl/err.h]],
29
+ }
30
+
31
+ dc_flags = ['ssl']
32
+ dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM and ENV['OPENSSL']
33
+
34
+ libs, heads = case RUBY_PLATFORM
35
+ when /mswin/ ; ssl_libs_heads_args[:mswin]
36
+ else ssl_libs_heads_args[:unix]
37
+ end
38
+ dir_config(*dc_flags)
39
+ check_libs(libs) and check_heads(heads)
40
+ end
41
+
42
+ if ENV['CROSS_COMPILING']
43
+ openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.0j")
44
+ openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-#{openssl_version}/")
45
+ if File.exists?(openssl_dir)
46
+ FileUtils.mkdir_p Dir.pwd+"/openssl/"
47
+ FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
48
+ FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
49
+ $INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
50
+ else
51
+ STDERR.puts
52
+ STDERR.puts "**************************************************************************************"
53
+ STDERR.puts "**** Cross-compiled OpenSSL not found"
54
+ STDERR.puts "**** Run: hg clone http://bitbucket.org/ged/ruby-pg && cd ruby-pg && rake openssl_libs"
55
+ STDERR.puts "**************************************************************************************"
56
+ STDERR.puts
57
+ end
58
+ end
59
+
60
+ # Try to use pkg_config first, fixes #73
61
+ if (!ENV['CROSS_COMPILING'] and pkg_config('openssl')) || manual_ssl_config
62
+ add_define "WITH_SSL"
63
+ else
64
+ add_define "WITHOUT_SSL"
65
+ end
66
+
67
+ add_define 'BUILD_FOR_RUBY'
68
+ add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
69
+ add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
70
+ add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
71
+ add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
72
+ add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
73
+
74
+ have_func('rb_wait_for_single_fd')
75
+ have_func('rb_enable_interrupt')
76
+ have_func('rb_time_new')
77
+
78
+ # Minor platform details between *nix and Windows:
79
+
80
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
81
+ GNU_CHAIN = ENV['CROSS_COMPILING'] || $1 == 'mingw'
82
+ OS_WIN32 = true
83
+ add_define "OS_WIN32"
84
+ else
85
+ GNU_CHAIN = true
86
+ OS_UNIX = true
87
+ add_define 'OS_UNIX'
88
+
89
+ add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
90
+ end
91
+
92
+ # Adjust number of file descriptors (FD) on Windows
93
+
94
+ if RbConfig::CONFIG["host_os"] =~ /mingw/
95
+ found = RbConfig::CONFIG.values_at("CFLAGS", "CPPFLAGS").
96
+ any? { |v| v.include?("FD_SETSIZE") }
97
+
98
+ add_define "FD_SETSIZE=32767" unless found
99
+ end
100
+
101
+ # Main platform invariances:
102
+
103
+ case RUBY_PLATFORM
104
+ when /mswin32/, /mingw32/, /bccwin32/
105
+ check_heads(%w[windows.h winsock.h], true)
106
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
107
+
108
+ if GNU_CHAIN
109
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
110
+ else
111
+ $defs.push "-EHs"
112
+ $defs.push "-GR"
113
+ end
114
+
115
+ when /solaris/
116
+ add_define 'OS_SOLARIS8'
117
+ check_libs(%w[nsl socket], true)
118
+
119
+ if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
120
+ # SUN CHAIN
121
+ add_define 'CC_SUNWspro'
122
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
123
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
124
+ CONFIG['CCDLFLAGS'] = "-KPIC"
125
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
126
+ else
127
+ # GNU CHAIN
128
+ # on Unix we need a g++ link, not gcc.
129
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
130
+ end
131
+
132
+ when /openbsd/
133
+ # OpenBSD branch contributed by Guillaume Sellier.
134
+
135
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
136
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
137
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
138
+
139
+ when /darwin/
140
+ # on Unix we need a g++ link, not gcc.
141
+ # Ff line contributed by Daniel Harple.
142
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
143
+
144
+ when /linux/
145
+ add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
146
+
147
+ # on Unix we need a g++ link, not gcc.
148
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
149
+
150
+ when /aix/
151
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
152
+
153
+ when /cygwin/
154
+ # For rubies built with Cygwin, CXX may be set to CC, which is just
155
+ # a wrapper for gcc.
156
+ # This will compile, but it will not link to the C++ std library.
157
+ # Explicitly set CXX to use g++.
158
+ CONFIG['CXX'] = "g++"
159
+ # on Unix we need a g++ link, not gcc.
160
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
161
+
162
+ else
163
+ # on Unix we need a g++ link, not gcc.
164
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
165
+ end
166
+
167
+
168
+ # solaris c++ compiler doesn't have make_pair()
169
+ TRY_LINK.sub!('$(CC)', '$(CXX)')
170
+ add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
171
+ #include <utility>
172
+ using namespace std;
173
+ int main(){ pair<const int,int> tuple = make_pair(1,2); }
174
+ SRC
175
+ TRY_LINK.sub!('$(CXX)', '$(CC)')
176
+
177
+ create_makefile "rubyeventmachine"