wj_eventmachine 1.3.0.dev.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +179 -0
- data/GNU +281 -0
- data/LICENSE +60 -0
- data/README.md +110 -0
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +520 -0
- data/docs/old/ChangeLog +211 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/old/EPOLL +141 -0
- data/docs/old/INSTALL +13 -0
- data/docs/old/KEYBOARD +42 -0
- data/docs/old/LEGAL +25 -0
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/PURE_RUBY +75 -0
- data/docs/old/RELEASE_NOTES +94 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/docs/old/TODO +8 -0
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/old/ex_channel.rb +43 -0
- data/examples/old/ex_queue.rb +2 -0
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/examples/old/helper.rb +2 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +52 -0
- data/ext/cmain.cpp +1046 -0
- data/ext/ed.cpp +2238 -0
- data/ext/ed.h +460 -0
- data/ext/em.cpp +2378 -0
- data/ext/em.h +266 -0
- data/ext/eventmachine.h +152 -0
- data/ext/extconf.rb +285 -0
- data/ext/fastfilereader/extconf.rb +120 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +126 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +354 -0
- data/ext/project.h +174 -0
- data/ext/rubymain.cpp +1610 -0
- data/ext/ssl.cpp +627 -0
- data/ext/ssl.h +103 -0
- data/ext/wait_for_single_fd.h +36 -0
- data/java/.classpath +8 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
- data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
- data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
- data/lib/em/buftok.rb +59 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +69 -0
- data/lib/em/completion.rb +307 -0
- data/lib/em/connection.rb +776 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/io_streamer.rb +68 -0
- data/lib/em/iterator.rb +252 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +303 -0
- data/lib/em/protocols/httpclient2.rb +602 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +33 -0
- data/lib/em/protocols/linetext2.rb +179 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +394 -0
- data/lib/em/protocols/smtpserver.rb +666 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +205 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/pure_ruby.rb +1299 -0
- data/lib/em/queue.rb +80 -0
- data/lib/em/resolver.rb +232 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +61 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1602 -0
- data/lib/jeventmachine.rb +318 -0
- data/rakelib/package.rake +120 -0
- data/rakelib/test.rake +6 -0
- data/rakelib/test_pure.rake +11 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/dhparam.pem +13 -0
- data/tests/em_ssl_handlers.rb +153 -0
- data/tests/em_test_helper.rb +198 -0
- data/tests/jruby/test_jeventmachine.rb +38 -0
- data/tests/test_attach.rb +199 -0
- data/tests/test_basic.rb +321 -0
- data/tests/test_channel.rb +75 -0
- data/tests/test_completion.rb +178 -0
- data/tests/test_connection_count.rb +83 -0
- data/tests/test_connection_write.rb +35 -0
- data/tests/test_defer.rb +35 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +141 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +37 -0
- data/tests/test_file_watch.rb +86 -0
- data/tests/test_fork.rb +75 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +238 -0
- data/tests/test_httpclient2.rb +132 -0
- data/tests/test_idle_connection.rb +31 -0
- data/tests/test_inactivity_timeout.rb +102 -0
- data/tests/test_io_streamer.rb +47 -0
- data/tests/test_ipv4.rb +96 -0
- data/tests/test_ipv6.rb +107 -0
- data/tests/test_iterator.rb +122 -0
- data/tests/test_kb.rb +28 -0
- data/tests/test_keepalive.rb +113 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +155 -0
- data/tests/test_ltp2.rb +332 -0
- data/tests/test_many_fds.rb +21 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +109 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +196 -0
- data/tests/test_process_watch.rb +50 -0
- data/tests/test_processes.rb +128 -0
- data/tests/test_proxy_connection.rb +180 -0
- data/tests/test_pure.rb +156 -0
- data/tests/test_queue.rb +64 -0
- data/tests/test_resolver.rb +129 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +46 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +32 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +75 -0
- data/tests/test_smtpserver.rb +90 -0
- data/tests/test_sock_opt.rb +53 -0
- data/tests/test_spawn.rb +290 -0
- data/tests/test_ssl_args.rb +41 -0
- data/tests/test_ssl_dhparam.rb +57 -0
- data/tests/test_ssl_ecdh_curve.rb +57 -0
- data/tests/test_ssl_extensions.rb +24 -0
- data/tests/test_ssl_methods.rb +31 -0
- data/tests/test_ssl_protocols.rb +190 -0
- data/tests/test_ssl_verify.rb +52 -0
- data/tests/test_stomp.rb +38 -0
- data/tests/test_system.rb +46 -0
- data/tests/test_threaded_resource.rb +68 -0
- data/tests/test_tick_loop.rb +58 -0
- data/tests/test_timers.rb +150 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_unbind_reason.rb +40 -0
- metadata +384 -0
@@ -0,0 +1,318 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 8 Apr 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
|
26
|
+
# This module provides "glue" for the Java version of the EventMachine reactor core.
|
27
|
+
# For C++ EventMachines, the analogous functionality is found in ext/rubymain.cpp,
|
28
|
+
# which is a garden-variety Ruby-extension glue module.
|
29
|
+
|
30
|
+
require 'java'
|
31
|
+
require 'rubyeventmachine'
|
32
|
+
require 'socket'
|
33
|
+
|
34
|
+
java_import java.io.FileDescriptor
|
35
|
+
java_import java.nio.channels.SocketChannel
|
36
|
+
java_import java.lang.reflect.Field
|
37
|
+
|
38
|
+
module JavaFields
|
39
|
+
def set_field(key, value)
|
40
|
+
field = getClass.getDeclaredField(key)
|
41
|
+
field.setAccessible(true)
|
42
|
+
if field.getType.toString == 'int'
|
43
|
+
field.setInt(self, value)
|
44
|
+
else
|
45
|
+
field.set(self, value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_field(key)
|
50
|
+
field = getClass.getDeclaredField(key)
|
51
|
+
field.setAccessible(true)
|
52
|
+
field.get(self)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
FileDescriptor.send :include, JavaFields
|
57
|
+
SocketChannel.send :include, JavaFields
|
58
|
+
|
59
|
+
module EventMachine
|
60
|
+
# TODO: These event numbers are defined in way too many places.
|
61
|
+
# DRY them up.
|
62
|
+
# @private
|
63
|
+
TimerFired = 100
|
64
|
+
# @private
|
65
|
+
ConnectionData = 101
|
66
|
+
# @private
|
67
|
+
ConnectionUnbound = 102
|
68
|
+
# @private
|
69
|
+
ConnectionAccepted = 103
|
70
|
+
# @private
|
71
|
+
ConnectionCompleted = 104
|
72
|
+
# @private
|
73
|
+
LoopbreakSignalled = 105
|
74
|
+
# @private
|
75
|
+
ConnectionNotifyReadable = 106
|
76
|
+
# @private
|
77
|
+
ConnectionNotifyWritable = 107
|
78
|
+
# @private
|
79
|
+
SslHandshakeCompleted = 108
|
80
|
+
# @private
|
81
|
+
SslVerify = 109
|
82
|
+
|
83
|
+
# @private
|
84
|
+
EM_PROTO_SSLv2 = 2
|
85
|
+
# @private
|
86
|
+
EM_PROTO_SSLv3 = 4
|
87
|
+
# @private
|
88
|
+
EM_PROTO_TLSv1 = 8
|
89
|
+
# @private
|
90
|
+
EM_PROTO_TLSv1_1 = 16
|
91
|
+
# @private
|
92
|
+
EM_PROTO_TLSv1_2 = 32
|
93
|
+
|
94
|
+
NULL_EM_REACTOR = com.rubyeventmachine.NullEmReactor.new
|
95
|
+
@em ||= NULL_EM_REACTOR
|
96
|
+
|
97
|
+
# Exceptions that are defined in rubymain.cpp
|
98
|
+
class ConnectionError < RuntimeError; end
|
99
|
+
class ConnectionNotBound < RuntimeError; end
|
100
|
+
class UnknownTimerFired < RuntimeError; end
|
101
|
+
class Unsupported < RuntimeError; end
|
102
|
+
|
103
|
+
# This thunk class used to be called EM, but that caused conflicts with
|
104
|
+
# the alias "EM" for module EventMachine. (FC, 20Jun08)
|
105
|
+
class JEM < com.rubyeventmachine.EmReactor
|
106
|
+
def eventCallback a1, a2, a3, a4
|
107
|
+
s = String.from_java_bytes(a3.array[a3.position...a3.limit]) if a3
|
108
|
+
EventMachine::event_callback a1, a2, s || a4
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
# class Connection < com.rubyeventmachine.Connection
|
113
|
+
# def associate_callback_target sig
|
114
|
+
# # No-op for the time being.
|
115
|
+
# end
|
116
|
+
# end
|
117
|
+
def self.initialize_event_machine
|
118
|
+
@em = JEM.new
|
119
|
+
end
|
120
|
+
def self.release_machine
|
121
|
+
@em = NULL_EM_REACTOR
|
122
|
+
end
|
123
|
+
def self.add_oneshot_timer interval
|
124
|
+
@em.installOneshotTimer interval
|
125
|
+
end
|
126
|
+
def self.run_machine
|
127
|
+
@em.run
|
128
|
+
end
|
129
|
+
def self.stop
|
130
|
+
@em.stop
|
131
|
+
end
|
132
|
+
def self.start_tcp_server server, port
|
133
|
+
@em.startTcpServer server, port
|
134
|
+
end
|
135
|
+
def self.stop_tcp_server sig
|
136
|
+
@em.stopTcpServer sig
|
137
|
+
end
|
138
|
+
def self.start_unix_server filename
|
139
|
+
# TEMPORARILY unsupported until someone figures out how to do it.
|
140
|
+
raise "unsupported on this platform"
|
141
|
+
end
|
142
|
+
def self.send_data sig, data, length
|
143
|
+
@em.sendData sig, data.to_java_bytes
|
144
|
+
rescue java.lang.NullPointerException
|
145
|
+
0
|
146
|
+
end
|
147
|
+
def self.send_datagram sig, data, length, address, port
|
148
|
+
@em.sendDatagram sig, data.to_java_bytes, length, address, port
|
149
|
+
end
|
150
|
+
def self.connect_server server, port
|
151
|
+
bind_connect_server nil, nil, server, port
|
152
|
+
end
|
153
|
+
def self.bind_connect_server bind_addr, bind_port, server, port
|
154
|
+
@em.connectTcpServer bind_addr, bind_port.to_i, server, port
|
155
|
+
end
|
156
|
+
def self.close_connection sig, after_writing
|
157
|
+
@em.closeConnection sig, after_writing
|
158
|
+
end
|
159
|
+
def self.set_comm_inactivity_timeout sig, interval
|
160
|
+
@em.setCommInactivityTimeout sig, interval
|
161
|
+
end
|
162
|
+
def self.set_pending_connect_timeout sig, val
|
163
|
+
end
|
164
|
+
def self.set_heartbeat_interval val
|
165
|
+
end
|
166
|
+
def self.start_tls sig
|
167
|
+
@em.startTls sig
|
168
|
+
end
|
169
|
+
def self.ssl?
|
170
|
+
false
|
171
|
+
end
|
172
|
+
def self.signal_loopbreak
|
173
|
+
@em.signalLoopbreak
|
174
|
+
end
|
175
|
+
def self.set_timer_quantum q
|
176
|
+
@em.setTimerQuantum q
|
177
|
+
end
|
178
|
+
def self.epoll
|
179
|
+
# Epoll is a no-op for Java.
|
180
|
+
# The latest Java versions run epoll when possible in NIO.
|
181
|
+
end
|
182
|
+
def self.epoll= val
|
183
|
+
end
|
184
|
+
def self.kqueue
|
185
|
+
end
|
186
|
+
def self.kqueue= val
|
187
|
+
end
|
188
|
+
def self.epoll?
|
189
|
+
false
|
190
|
+
end
|
191
|
+
def self.kqueue?
|
192
|
+
false
|
193
|
+
end
|
194
|
+
def self.set_rlimit_nofile n_descriptors
|
195
|
+
# Currently a no-op for Java.
|
196
|
+
end
|
197
|
+
def self.open_udp_socket server, port
|
198
|
+
@em.openUdpSocket server, port
|
199
|
+
end
|
200
|
+
def self.invoke_popen cmd
|
201
|
+
# TEMPORARILY unsupported until someone figures out how to do it.
|
202
|
+
raise "unsupported on this platform"
|
203
|
+
end
|
204
|
+
def self.read_keyboard
|
205
|
+
# TEMPORARILY unsupported until someone figures out how to do it.
|
206
|
+
raise "temporarily unsupported on this platform"
|
207
|
+
end
|
208
|
+
def self.set_max_timer_count num
|
209
|
+
# harmless no-op in Java. There's no built-in timer limit.
|
210
|
+
@max_timer_count = num
|
211
|
+
end
|
212
|
+
def self.get_max_timer_count
|
213
|
+
# harmless no-op in Java. There's no built-in timer limit.
|
214
|
+
@max_timer_count || 100_000
|
215
|
+
end
|
216
|
+
def self.library_type
|
217
|
+
:java
|
218
|
+
end
|
219
|
+
def self.get_peername sig
|
220
|
+
if peer = @em.getPeerName(sig)
|
221
|
+
Socket.pack_sockaddr_in(*peer)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
def self.get_sockname sig
|
225
|
+
if sockName = @em.getSockName(sig)
|
226
|
+
Socket.pack_sockaddr_in(*sockName)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
# @private
|
230
|
+
def self.attach_fd fileno, watch_mode
|
231
|
+
# 3Aug09: We could pass in the actual SocketChannel, but then it would be modified (set as non-blocking), and
|
232
|
+
# we would need some logic to make sure detach_fd below didn't clobber it. For now, we just always make a new
|
233
|
+
# SocketChannel for the underlying file descriptor
|
234
|
+
# if fileno.java_kind_of? SocketChannel
|
235
|
+
# ch = fileno
|
236
|
+
# ch.configureBlocking(false)
|
237
|
+
# fileno = nil
|
238
|
+
# elsif fileno.java_kind_of? java.nio.channels.Channel
|
239
|
+
|
240
|
+
if fileno.java_kind_of? java.nio.channels.Channel
|
241
|
+
field = fileno.getClass.getDeclaredField('fdVal')
|
242
|
+
field.setAccessible(true)
|
243
|
+
fileno = field.get(fileno)
|
244
|
+
else
|
245
|
+
raise ArgumentError, 'attach_fd requires Java Channel or POSIX fileno' unless fileno.is_a? Integer
|
246
|
+
end
|
247
|
+
|
248
|
+
if fileno == 0
|
249
|
+
raise "can't open STDIN as selectable in Java =("
|
250
|
+
elsif fileno.is_a? Integer
|
251
|
+
# 8Aug09: The following code is specific to the sun jvm's SocketChannelImpl. Is there a cross-platform
|
252
|
+
# way of implementing this? If so, also remember to update EventableSocketChannel#close and #cleanup
|
253
|
+
fd = FileDescriptor.new
|
254
|
+
fd.set_field 'fd', fileno
|
255
|
+
|
256
|
+
ch = SocketChannel.open
|
257
|
+
ch.configureBlocking(false)
|
258
|
+
ch.kill
|
259
|
+
ch.set_field 'fd', fd
|
260
|
+
ch.set_field 'fdVal', fileno
|
261
|
+
ch.set_field 'state', ch.get_field('ST_CONNECTED')
|
262
|
+
end
|
263
|
+
|
264
|
+
@em.attachChannel(ch,watch_mode)
|
265
|
+
end
|
266
|
+
def self.detach_fd sig
|
267
|
+
if ch = @em.detachChannel(sig)
|
268
|
+
ch.get_field 'fdVal'
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def self.set_notify_readable sig, mode
|
273
|
+
@em.setNotifyReadable(sig, mode)
|
274
|
+
end
|
275
|
+
def self.set_notify_writable sig, mode
|
276
|
+
@em.setNotifyWritable(sig, mode)
|
277
|
+
end
|
278
|
+
|
279
|
+
def self.is_notify_readable sig
|
280
|
+
@em.isNotifyReadable(sig)
|
281
|
+
end
|
282
|
+
def self.is_notify_writable sig
|
283
|
+
@em.isNotifyWritable(sig)
|
284
|
+
end
|
285
|
+
def self.get_connection_count
|
286
|
+
@em.getConnectionCount
|
287
|
+
end
|
288
|
+
|
289
|
+
def self.pause_connection(sig)
|
290
|
+
@em.pauseConnection(sig)
|
291
|
+
end
|
292
|
+
def self.resume_connection(sig)
|
293
|
+
@em.resumeConnection(sig)
|
294
|
+
end
|
295
|
+
def self.connection_paused?(sig)
|
296
|
+
@em.isConnectionPaused(sig)
|
297
|
+
end
|
298
|
+
def self._get_outbound_data_size(sig)
|
299
|
+
@em.getOutboundDataSize(sig)
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
def self.set_tls_parms(sig, params)
|
304
|
+
end
|
305
|
+
def self.start_tls(sig)
|
306
|
+
end
|
307
|
+
def self.send_file_data(sig, filename)
|
308
|
+
end
|
309
|
+
|
310
|
+
class Connection
|
311
|
+
def associate_callback_target sig
|
312
|
+
# No-op for the time being
|
313
|
+
end
|
314
|
+
def get_outbound_data_size
|
315
|
+
EM._get_outbound_data_size @signature
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rake/extensiontask'
|
6
|
+
require 'rake/javaextensiontask'
|
7
|
+
rescue LoadError => e
|
8
|
+
puts <<-MSG
|
9
|
+
rake-compiler gem seems to be missing. Please install it with
|
10
|
+
|
11
|
+
gem install rake-compiler
|
12
|
+
|
13
|
+
(add sudo if necessary).
|
14
|
+
MSG
|
15
|
+
end
|
16
|
+
|
17
|
+
Gem::PackageTask.new(GEMSPEC) do |pkg|
|
18
|
+
end
|
19
|
+
|
20
|
+
if RUBY_PLATFORM =~ /java/
|
21
|
+
Rake::JavaExtensionTask.new("rubyeventmachine", GEMSPEC) do |ext|
|
22
|
+
ext.ext_dir = 'java/src'
|
23
|
+
end
|
24
|
+
else
|
25
|
+
def setup_cross_compilation(ext)
|
26
|
+
unless RUBY_PLATFORM =~ /mswin|mingw/
|
27
|
+
ext.cross_compile = true
|
28
|
+
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def hack_cross_compilation(ext)
|
32
|
+
# inject 1.8/1.9 pure-ruby entry point
|
33
|
+
# HACK: add these dependencies to the task instead of using cross_compiling
|
34
|
+
if ext.cross_platform.is_a?(Array)
|
35
|
+
ext.cross_platform.each do |platform|
|
36
|
+
task = "native:#{GEMSPEC.name}:#{platform}"
|
37
|
+
if Rake::Task.task_defined?(task)
|
38
|
+
Rake::Task[task].prerequisites.unshift "lib/#{ext.name}.rb"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
em = Rake::ExtensionTask.new("rubyeventmachine", GEMSPEC) do |ext|
|
45
|
+
ext.ext_dir = 'ext'
|
46
|
+
ext.source_pattern = '*.{h,c,cpp}'
|
47
|
+
setup_cross_compilation(ext)
|
48
|
+
end
|
49
|
+
hack_cross_compilation em
|
50
|
+
|
51
|
+
ff = Rake::ExtensionTask.new("fastfilereaderext", GEMSPEC) do |ext|
|
52
|
+
ext.ext_dir = 'ext/fastfilereader'
|
53
|
+
ext.source_pattern = '*.{h,c,cpp}'
|
54
|
+
setup_cross_compilation(ext)
|
55
|
+
end
|
56
|
+
hack_cross_compilation ff
|
57
|
+
end
|
58
|
+
|
59
|
+
# Setup shim files that require 1.8 vs 1.9 extensions in win32 bin gems
|
60
|
+
%w[ rubyeventmachine fastfilereaderext ].each do |filename|
|
61
|
+
file("lib/#{filename}.rb") do |t|
|
62
|
+
File.open(t.name, 'wb') do |f|
|
63
|
+
f.write <<-eoruby
|
64
|
+
RUBY_VERSION =~ /(\\d+.\\d+)/
|
65
|
+
require "\#{$1}/#{File.basename(t.name, '.rb')}"
|
66
|
+
eoruby
|
67
|
+
end
|
68
|
+
at_exit{ FileUtils.rm t.name if File.exist?(t.name) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
task :cross_cxx do
|
73
|
+
ENV['CROSS_COMPILING'] = 'yes'
|
74
|
+
require 'rake/extensioncompiler'
|
75
|
+
ENV['CXX'] = "#{Rake::ExtensionCompiler.mingw_host}-g++"
|
76
|
+
end
|
77
|
+
|
78
|
+
if Rake::Task.task_defined?(:cross)
|
79
|
+
task :cross => 'lib/rubyeventmachine.rb'
|
80
|
+
task :cross => 'lib/fastfilereaderext.rb'
|
81
|
+
task :cross => :cross_cxx
|
82
|
+
end
|
83
|
+
|
84
|
+
def windows?; RUBY_PLATFORM =~ /mswin|mingw/; end
|
85
|
+
def sudo(cmd)
|
86
|
+
if windows? || (require 'etc'; Etc.getpwuid.uid == 0)
|
87
|
+
sh cmd
|
88
|
+
else
|
89
|
+
sh "sudo #{cmd}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
def gem_cmd(action, name, *args)
|
93
|
+
rb = Gem.ruby rescue nil
|
94
|
+
rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
|
95
|
+
sudo "#{rb} -r rubygems -e 'require %{rubygems/gem_runner}; Gem::GemRunner.new.run(%w{#{action} #{name} #{args.join(' ')}})'"
|
96
|
+
end
|
97
|
+
|
98
|
+
Rake::Task[:clean].enhance [:clobber_package]
|
99
|
+
|
100
|
+
# DevKit task following the example of Luis Lavena's test-ruby-c-extension
|
101
|
+
task :devkit do
|
102
|
+
begin
|
103
|
+
require "devkit"
|
104
|
+
rescue LoadError => e
|
105
|
+
abort "Failed to activate RubyInstaller's DevKit required for compilation."
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
if RUBY_PLATFORM =~ /mingw|mswin/ && ENV['GITHUB_ACTIONS'].nil?
|
110
|
+
Rake::Task['compile'].prerequisites.unshift 'devkit'
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "Build binary gems for Windows with rake-compiler-dock"
|
114
|
+
task 'gem:windows' do
|
115
|
+
require 'rake_compiler_dock'
|
116
|
+
RakeCompilerDock.sh <<-EOT
|
117
|
+
RUBY_CC_VERSION="${RUBY_CC_VERSION//1.9.2/}"
|
118
|
+
bundle && rake cross native gem
|
119
|
+
EOT
|
120
|
+
end
|
data/rakelib/test.rake
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new(:test_pure) do |t|
|
4
|
+
t.test_files = Dir.glob('tests/**/test_pure*.rb') + Dir.glob('tests/**/test_ssl*.rb')
|
5
|
+
t.warning = true
|
6
|
+
end
|
7
|
+
|
8
|
+
task :test_em_pure_ruby do
|
9
|
+
ENV['EM_PURE_RUBY'] = 'true'
|
10
|
+
Rake::Task['test_pure'].execute
|
11
|
+
end
|