sensu-em 2.4.0-x86-mingw32

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 +21 -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/Rakefile +20 -0
  11. data/docs/DocumentationGuidesIndex.md +27 -0
  12. data/docs/GettingStarted.md +521 -0
  13. data/docs/old/ChangeLog +211 -0
  14. data/docs/old/DEFERRABLES +246 -0
  15. data/docs/old/EPOLL +141 -0
  16. data/docs/old/INSTALL +13 -0
  17. data/docs/old/KEYBOARD +42 -0
  18. data/docs/old/LEGAL +25 -0
  19. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  20. data/docs/old/PURE_RUBY +75 -0
  21. data/docs/old/RELEASE_NOTES +94 -0
  22. data/docs/old/SMTP +4 -0
  23. data/docs/old/SPAWNED_PROCESSES +148 -0
  24. data/docs/old/TODO +8 -0
  25. data/eventmachine.gemspec +37 -0
  26. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  27. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  28. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  29. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  30. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  31. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  32. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  33. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  34. data/examples/old/ex_channel.rb +43 -0
  35. data/examples/old/ex_queue.rb +2 -0
  36. data/examples/old/ex_tick_loop_array.rb +15 -0
  37. data/examples/old/ex_tick_loop_counter.rb +32 -0
  38. data/examples/old/helper.rb +2 -0
  39. data/ext/binder.cpp +124 -0
  40. data/ext/binder.h +46 -0
  41. data/ext/cmain.cpp +887 -0
  42. data/ext/ed.cpp +1992 -0
  43. data/ext/ed.h +424 -0
  44. data/ext/em.cpp +2352 -0
  45. data/ext/em.h +253 -0
  46. data/ext/eventmachine.h +128 -0
  47. data/ext/extconf.rb +179 -0
  48. data/ext/fastfilereader/extconf.rb +103 -0
  49. data/ext/fastfilereader/mapper.cpp +214 -0
  50. data/ext/fastfilereader/mapper.h +59 -0
  51. data/ext/fastfilereader/rubymain.cpp +127 -0
  52. data/ext/kb.cpp +79 -0
  53. data/ext/page.cpp +107 -0
  54. data/ext/page.h +51 -0
  55. data/ext/pipe.cpp +347 -0
  56. data/ext/project.h +161 -0
  57. data/ext/rubymain.cpp +1318 -0
  58. data/ext/ssl.cpp +476 -0
  59. data/ext/ssl.h +95 -0
  60. data/java/.classpath +6 -0
  61. data/java/.gitignore +1 -0
  62. data/java/.project +17 -0
  63. data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
  64. data/java/src/com/rubyeventmachine/EmReactor.java +531 -0
  65. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  66. data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
  67. data/java/src/com/rubyeventmachine/EventCode.java +26 -0
  68. data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
  69. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +179 -0
  70. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
  71. data/java/src/com/rubyeventmachine/SslBox.java +311 -0
  72. data/lib/em/buftok.rb +110 -0
  73. data/lib/em/callback.rb +58 -0
  74. data/lib/em/channel.rb +64 -0
  75. data/lib/em/completion.rb +304 -0
  76. data/lib/em/connection.rb +716 -0
  77. data/lib/em/deferrable.rb +210 -0
  78. data/lib/em/deferrable/pool.rb +2 -0
  79. data/lib/em/file_watch.rb +73 -0
  80. data/lib/em/future.rb +61 -0
  81. data/lib/em/iterator.rb +231 -0
  82. data/lib/em/messages.rb +66 -0
  83. data/lib/em/pool.rb +151 -0
  84. data/lib/em/process_watch.rb +45 -0
  85. data/lib/em/processes.rb +123 -0
  86. data/lib/em/protocols.rb +37 -0
  87. data/lib/em/protocols/header_and_content.rb +138 -0
  88. data/lib/em/protocols/httpclient.rb +279 -0
  89. data/lib/em/protocols/httpclient2.rb +600 -0
  90. data/lib/em/protocols/line_and_text.rb +125 -0
  91. data/lib/em/protocols/line_protocol.rb +29 -0
  92. data/lib/em/protocols/linetext2.rb +161 -0
  93. data/lib/em/protocols/memcache.rb +331 -0
  94. data/lib/em/protocols/object_protocol.rb +46 -0
  95. data/lib/em/protocols/postgres3.rb +246 -0
  96. data/lib/em/protocols/saslauth.rb +175 -0
  97. data/lib/em/protocols/smtpclient.rb +365 -0
  98. data/lib/em/protocols/smtpserver.rb +643 -0
  99. data/lib/em/protocols/socks4.rb +66 -0
  100. data/lib/em/protocols/stomp.rb +205 -0
  101. data/lib/em/protocols/tcptest.rb +54 -0
  102. data/lib/em/pure_ruby.rb +1017 -0
  103. data/lib/em/queue.rb +71 -0
  104. data/lib/em/resolver.rb +209 -0
  105. data/lib/em/spawnable.rb +84 -0
  106. data/lib/em/streamer.rb +118 -0
  107. data/lib/em/threaded_resource.rb +90 -0
  108. data/lib/em/tick_loop.rb +85 -0
  109. data/lib/em/timers.rb +61 -0
  110. data/lib/em/version.rb +3 -0
  111. data/lib/eventmachine.rb +1553 -0
  112. data/lib/fastfilereaderext.rb +2 -0
  113. data/lib/jeventmachine.rb +321 -0
  114. data/lib/rubyeventmachine.rb +2 -0
  115. data/rakelib/cpp.rake_example +77 -0
  116. data/rakelib/package.rake +98 -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 +300 -0
@@ -0,0 +1,2 @@
1
+ RUBY_VERSION =~ /(\d+.\d+)/
2
+ require "#{$1}/fastfilereaderext"
@@ -0,0 +1,321 @@
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
+ require 'openssl'
34
+
35
+ java_import java.io.FileDescriptor
36
+ java_import java.nio.channels.SocketChannel
37
+ java_import java.lang.reflect.Field
38
+
39
+ module JavaFields
40
+ def set_field(key, value)
41
+ field = getClass.getDeclaredField(key)
42
+ field.setAccessible(true)
43
+ if field.getType.toString == 'int'
44
+ field.setInt(self, value)
45
+ else
46
+ field.set(self, value)
47
+ end
48
+ end
49
+
50
+ def get_field(key)
51
+ field = getClass.getDeclaredField(key)
52
+ field.setAccessible(true)
53
+ field.get(self)
54
+ end
55
+ end
56
+
57
+ FileDescriptor.send :include, JavaFields
58
+ SocketChannel.send :include, JavaFields
59
+
60
+ module EventMachine
61
+ # TODO: These event numbers are defined in way too many places.
62
+ # DRY them up.
63
+ # @private
64
+ TimerFired = 100
65
+ # @private
66
+ ConnectionData = 101
67
+ # @private
68
+ ConnectionUnbound = 102
69
+ # @private
70
+ ConnectionAccepted = 103
71
+ # @private
72
+ ConnectionCompleted = 104
73
+ # @private
74
+ LoopbreakSignalled = 105
75
+ # @private
76
+ ConnectionNotifyReadable = 106
77
+ # @private
78
+ ConnectionNotifyWritable = 107
79
+ # @private
80
+ SslHandshakeCompleted = 108
81
+ # @private
82
+ SslVerify = 109
83
+
84
+ # Exceptions that are defined in rubymain.cpp
85
+ class ConnectionError < RuntimeError; end
86
+ class ConnectionNotBound < RuntimeError; end
87
+ class UnknownTimerFired < RuntimeError; end
88
+ class Unsupported < RuntimeError; end
89
+
90
+ def self.initialize_event_machine
91
+ @em = com.rubyeventmachine.EmReactor.new do |sig, event, buf, data|
92
+ s = String.from_java_bytes(buf.array[buf.position...buf.limit]) if buf
93
+ EventMachine::event_callback sig, event.int_value, s || data
94
+ nil
95
+ end
96
+ end
97
+ def self.release_machine
98
+ @em = nil
99
+ end
100
+ def self.add_oneshot_timer interval
101
+ @em.installOneshotTimer interval
102
+ end
103
+ def self.run_machine
104
+ @em.run
105
+ end
106
+ def self.stop
107
+ @em.stop
108
+ end
109
+ def self.start_tcp_server server, port
110
+ @em.startTcpServer server, port
111
+ end
112
+ def self.stop_tcp_server sig
113
+ @em.stopTcpServer sig
114
+ end
115
+ def self.start_unix_server filename
116
+ # TEMPORARILY unsupported until someone figures out how to do it.
117
+ raise "unsupported on this platform"
118
+ end
119
+ def self.send_data sig, data, length
120
+ @em.sendData sig, data.to_java_bytes
121
+ end
122
+ def self.send_datagram sig, data, length, address, port
123
+ @em.sendDatagram sig, data.to_java_bytes, length, address, port
124
+ end
125
+ def self.connect_server server, port
126
+ bind_connect_server nil, nil, server, port
127
+ end
128
+ def self.bind_connect_server bind_addr, bind_port, server, port
129
+ @em.connectTcpServer bind_addr, bind_port.to_i, server, port
130
+ end
131
+ def self.close_connection sig, after_writing
132
+ @em.closeConnection sig, after_writing
133
+ end
134
+ def self.set_comm_inactivity_timeout sig, interval
135
+ @em.setCommInactivityTimeout sig, interval
136
+ end
137
+ def self.set_pending_connect_timeout sig, val
138
+ end
139
+ def self.set_heartbeat_interval val
140
+ end
141
+ def self.start_tls sig
142
+ @em.startTls sig
143
+ end
144
+ def self.ssl?
145
+ true
146
+ end
147
+ def self.ssl_verify_peer conn, der_data
148
+ data = OpenSSL::X509::Certificate.new(der_data).to_pem
149
+ @em.acceptSslPeer conn.signature if conn.ssl_verify_peer data
150
+ end
151
+ def self.get_peer_cert sig
152
+ der_data = @em.getPeerCert sig
153
+ OpenSSL::X509::Certificate.new(String.from_java_bytes(der_data)).to_pem
154
+ end
155
+ def self.signal_loopbreak
156
+ @em.signalLoopbreak
157
+ end
158
+ def self.set_timer_quantum q
159
+ @em.setTimerQuantum q
160
+ end
161
+ def self.epoll
162
+ # Epoll is a no-op for Java.
163
+ # The latest Java versions run epoll when possible in NIO.
164
+ end
165
+ def self.epoll= val
166
+ end
167
+ def self.kqueue
168
+ end
169
+ def self.kqueue= val
170
+ end
171
+ def self.epoll?
172
+ false
173
+ end
174
+ def self.kqueue?
175
+ false
176
+ end
177
+ def self.set_rlimit_nofile n_descriptors
178
+ # Currently a no-op for Java.
179
+ end
180
+ def self.open_udp_socket server, port
181
+ @em.openUdpSocket server, port
182
+ end
183
+ def self.invoke_popen cmd
184
+ # TEMPORARILY unsupported until someone figures out how to do it.
185
+ raise "unsupported on this platform"
186
+ end
187
+ def self.read_keyboard
188
+ # TEMPORARILY unsupported until someone figures out how to do it.
189
+ raise "temporarily unsupported on this platform"
190
+ end
191
+ def self.set_max_timer_count num
192
+ # harmless no-op in Java. There's no built-in timer limit.
193
+ @max_timer_count = num
194
+ end
195
+ def self.get_max_timer_count
196
+ # harmless no-op in Java. There's no built-in timer limit.
197
+ @max_timer_count || 100_000
198
+ end
199
+ def self.library_type
200
+ :java
201
+ end
202
+ def self.get_peername sig
203
+ if peer = @em.getPeerName(sig)
204
+ Socket.pack_sockaddr_in(*peer)
205
+ end
206
+ end
207
+ def self.get_sockname sig
208
+ if sockName = @em.getSockName(sig)
209
+ Socket.pack_sockaddr_in(*sockName)
210
+ end
211
+ end
212
+ # @private
213
+ def self.attach_fd fileno, watch_mode
214
+ # 3Aug09: We could pass in the actual SocketChannel, but then it would be modified (set as non-blocking), and
215
+ # we would need some logic to make sure detach_fd below didn't clobber it. For now, we just always make a new
216
+ # SocketChannel for the underlying file descriptor
217
+ # if fileno.java_kind_of? SocketChannel
218
+ # ch = fileno
219
+ # ch.configureBlocking(false)
220
+ # fileno = nil
221
+ # elsif fileno.java_kind_of? java.nio.channels.Channel
222
+
223
+ if fileno.java_kind_of? java.nio.channels.Channel
224
+ field = fileno.getClass.getDeclaredField('fdVal')
225
+ field.setAccessible(true)
226
+ fileno = field.get(fileno)
227
+ else
228
+ raise ArgumentError, 'attach_fd requires Java Channel or POSIX fileno' unless fileno.is_a? Fixnum
229
+ end
230
+
231
+ if fileno == 0
232
+ raise "can't open STDIN as selectable in Java =("
233
+ elsif fileno.is_a? Fixnum
234
+ # 8Aug09: The following code is specific to the sun jvm's SocketChannelImpl. Is there a cross-platform
235
+ # way of implementing this? If so, also remember to update EventableSocketChannel#close and #cleanup
236
+ fd = FileDescriptor.new
237
+ fd.set_field 'fd', fileno
238
+
239
+ ch = SocketChannel.open
240
+ ch.configureBlocking(false)
241
+ ch.kill
242
+ ch.set_field 'fd', fd
243
+ ch.set_field 'fdVal', fileno
244
+ ch.set_field 'state', ch.get_field('ST_CONNECTED')
245
+ end
246
+
247
+ @em.attachChannel(ch,watch_mode)
248
+ end
249
+ def self.detach_fd sig
250
+ if ch = @em.detachChannel(sig)
251
+ ch.get_field 'fdVal'
252
+ end
253
+ end
254
+
255
+ def self.set_notify_readable sig, mode
256
+ @em.setNotifyReadable(sig, mode)
257
+ end
258
+ def self.set_notify_writable sig, mode
259
+ @em.setNotifyWritable(sig, mode)
260
+ end
261
+
262
+ def self.is_notify_readable sig
263
+ @em.isNotifyReadable(sig)
264
+ end
265
+ def self.is_notify_writable sig
266
+ @em.isNotifyWritable(sig)
267
+ end
268
+ def self.get_connection_count
269
+ @em.getConnectionCount
270
+ end
271
+
272
+ def self.set_tls_parms(sig, privkeyfile, certchainfile, verify_peer, use_tls, cipher_list)
273
+ keystore = KeyStoreBuilder.create privkeyfile, certchainfile unless (privkeyfile.empty? or certchainfile.empty?)
274
+ @em.setTlsParms(sig, keystore, (!!verify_peer))
275
+ end
276
+ def self.send_file_data(sig, filename)
277
+ end
278
+
279
+ class Connection
280
+ def associate_callback_target sig
281
+ # No-op for the time being
282
+ end
283
+ end
284
+ end
285
+
286
+ module KeyStoreBuilder
287
+ require 'bouncy-castle-java'
288
+ java_import java.io.FileReader
289
+ java_import java.io.FileInputStream
290
+ java_import java.security.cert.Certificate
291
+ java_import java.security.cert.CertificateFactory
292
+ java_import java.security.KeyStore
293
+ java_import java.security.Security
294
+ java_import org.bouncycastle.openssl.PEMReader
295
+ java_import org.bouncycastle.jce.provider.BouncyCastleProvider
296
+ @name = 'em_java_tls_key' # TODO - find a correct value, or whether it even really matters.
297
+ @initialized = false
298
+
299
+ def self.init
300
+ unless @initialized
301
+ Security.add_provider BouncyCastleProvider.new
302
+ @initialized = true
303
+ end
304
+ end
305
+
306
+ def self.create(privkeyfile, certchainfile)
307
+ self.init
308
+
309
+ key_reader = FileReader.new privkeyfile
310
+ key_pair = PEMReader.new(key_reader).read_object
311
+
312
+ cert_stream = FileInputStream.new certchainfile
313
+ certs = CertificateFactory.get_instance('X.509', 'BC').generate_certificates cert_stream
314
+
315
+ store = KeyStore.get_instance 'PKCS12', 'BC'
316
+ store.load nil, nil
317
+ store.set_key_entry @name, key_pair.get_private, nil, certs.to_array(Certificate[certs.size].new)
318
+
319
+ store
320
+ end
321
+ end
@@ -0,0 +1,2 @@
1
+ RUBY_VERSION =~ /(\d+.\d+)/
2
+ require "#{$1}/rubyeventmachine"
@@ -0,0 +1,77 @@
1
+ # EventMachine C++ Rakefile Stab Case
2
+ # TODO : track header files as a build dependency...
3
+ # TODO : cross platform support
4
+ # TODO : configure style functionality
5
+ namespace :cpp do
6
+
7
+ require 'rake/clean'
8
+
9
+ # *nix only atm...
10
+ module Cpp
11
+ class <<self
12
+ def cpp; "g++"; end
13
+ def archive; "ar"; end
14
+ def compile file, output, includes=nil, flags=nil
15
+ sh %{#{cpp} #{file} #{includes} #{flags} -c -o #{output}}
16
+ end
17
+ def link file, output, libs=nil, flags=nil
18
+ sh %{#{cpp} #{file} #{libs} #{flags} -o #{output}}
19
+ end
20
+ def static output, files
21
+ sh %{#{archive} cr #{output} #{files}}
22
+ end
23
+ end
24
+ end
25
+
26
+ module EmConfig
27
+ Path = ENV['EVENTMACHINE_SOURCE'] || 'ext'
28
+ Sources = FileList["#{Path}/*.cpp"]
29
+ Sources.delete_if { |s| /ruby/ =~ s }
30
+ Compiled = Sources.sub(%r{^#{Path}/(.*)\.cpp}, "#{Path}/\\1.o")
31
+
32
+ Flags = "-O2 -pipe -fno-common -DOS_UNIX -DWITHOUT_SSL"
33
+ Includes = ""
34
+ Libs = ''
35
+ end
36
+ CLEAN.include(EmConfig::Compiled)
37
+
38
+ rule %r{^#{EmConfig::Path}/.*\.o$} => [proc { |targ|
39
+ targ.sub(%r{^#{EmConfig::Path}/(.*)\.o$}, "#{EmConfig::Path}/\\1.cpp")
40
+ }] do |t|
41
+ Cpp.compile t.source, t.name, EmConfig::Includes, EmConfig::Flags
42
+ end
43
+
44
+ file "#{EmConfig::Path}/libeventmachine.a" => EmConfig::Compiled do |t|
45
+ Cpp.static t.name, EmConfig::Compiled
46
+ end
47
+ CLEAN.include("#{EmConfig::Path}/libeventmachine.a")
48
+
49
+ module AppConfig
50
+ Appname = 'echo_em'
51
+ Sources = FileList['*.cpp']
52
+ Compiled = Sources.sub(%r{^(.*)\.cpp}, '\\1.o')
53
+
54
+ Flags = ["", EmConfig::Flags].join(' ')
55
+ Includes = ["-I. -I#{EmConfig::Path}", EmConfig::Includes].join(' ')
56
+ Libs = ["-L#{EmConfig::Path} -leventmachine", EmConfig::Libs].join(' ')
57
+ end
58
+ CLEAN.include(AppConfig::Compiled)
59
+ CLEAN.include(AppConfig::Appname)
60
+
61
+ rule %r{^.*\.o$} => [proc { |targ|
62
+ targ.sub(%r{^(.*)\.o$}, '\\1.cpp')
63
+ }] do |t|
64
+ Cpp.compile t.source, t.name, AppConfig::Includes, AppConfig::Flags
65
+ end
66
+
67
+ file AppConfig::Appname => ["#{EmConfig::Path}/libeventmachine.a", AppConfig::Compiled] do |t|
68
+ Cpp.link AppConfig::Compiled, t.name, AppConfig::Libs, AppConfig::Flags
69
+ end
70
+
71
+ task :build => AppConfig::Appname
72
+
73
+ task :run => AppConfig::Appname do
74
+ sh "./#{AppConfig::Appname}"
75
+ end
76
+
77
+ end
@@ -0,0 +1,98 @@
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', 'x86-mswin32-60']
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.exists?(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]