crusher-eventmachine 0.12.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/README +81 -0
  2. data/Rakefile +370 -0
  3. data/docs/COPYING +60 -0
  4. data/docs/ChangeLog +211 -0
  5. data/docs/DEFERRABLES +246 -0
  6. data/docs/EPOLL +141 -0
  7. data/docs/GNU +281 -0
  8. data/docs/INSTALL +13 -0
  9. data/docs/KEYBOARD +42 -0
  10. data/docs/LEGAL +25 -0
  11. data/docs/LIGHTWEIGHT_CONCURRENCY +130 -0
  12. data/docs/PURE_RUBY +75 -0
  13. data/docs/RELEASE_NOTES +94 -0
  14. data/docs/SMTP +4 -0
  15. data/docs/SPAWNED_PROCESSES +148 -0
  16. data/docs/TODO +8 -0
  17. data/eventmachine.gemspec +40 -0
  18. data/examples/ex_channel.rb +43 -0
  19. data/examples/ex_queue.rb +2 -0
  20. data/examples/ex_tick_loop_array.rb +15 -0
  21. data/examples/ex_tick_loop_counter.rb +32 -0
  22. data/examples/helper.rb +2 -0
  23. data/ext/binder.cpp +124 -0
  24. data/ext/binder.h +46 -0
  25. data/ext/cmain.cpp +852 -0
  26. data/ext/cplusplus.cpp +202 -0
  27. data/ext/ed.cpp +1884 -0
  28. data/ext/ed.h +418 -0
  29. data/ext/em.cpp +2377 -0
  30. data/ext/em.h +239 -0
  31. data/ext/emwin.cpp +300 -0
  32. data/ext/emwin.h +94 -0
  33. data/ext/epoll.cpp +26 -0
  34. data/ext/epoll.h +25 -0
  35. data/ext/eventmachine.h +124 -0
  36. data/ext/eventmachine_cpp.h +96 -0
  37. data/ext/extconf.rb +150 -0
  38. data/ext/fastfilereader/extconf.rb +85 -0
  39. data/ext/fastfilereader/mapper.cpp +214 -0
  40. data/ext/fastfilereader/mapper.h +59 -0
  41. data/ext/fastfilereader/rubymain.cpp +127 -0
  42. data/ext/files.cpp +94 -0
  43. data/ext/files.h +65 -0
  44. data/ext/kb.cpp +79 -0
  45. data/ext/page.cpp +107 -0
  46. data/ext/page.h +51 -0
  47. data/ext/pipe.cpp +347 -0
  48. data/ext/project.h +157 -0
  49. data/ext/rubymain.cpp +1215 -0
  50. data/ext/sigs.cpp +89 -0
  51. data/ext/sigs.h +32 -0
  52. data/ext/ssl.cpp +460 -0
  53. data/ext/ssl.h +94 -0
  54. data/java/.classpath +8 -0
  55. data/java/.project +17 -0
  56. data/java/src/com/rubyeventmachine/EmReactor.java +571 -0
  57. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  58. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  59. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  60. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  61. data/java/src/com/rubyeventmachine/application/Application.java +194 -0
  62. data/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  63. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  64. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  65. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  66. data/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  67. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  68. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  69. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  70. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  71. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  72. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  73. data/lib/em/buftok.rb +138 -0
  74. data/lib/em/callback.rb +26 -0
  75. data/lib/em/channel.rb +57 -0
  76. data/lib/em/connection.rb +569 -0
  77. data/lib/em/deferrable.rb +206 -0
  78. data/lib/em/file_watch.rb +54 -0
  79. data/lib/em/future.rb +61 -0
  80. data/lib/em/iterator.rb +270 -0
  81. data/lib/em/messages.rb +66 -0
  82. data/lib/em/process_watch.rb +44 -0
  83. data/lib/em/processes.rb +119 -0
  84. data/lib/em/protocols.rb +36 -0
  85. data/lib/em/protocols/header_and_content.rb +138 -0
  86. data/lib/em/protocols/httpclient.rb +276 -0
  87. data/lib/em/protocols/httpclient2.rb +590 -0
  88. data/lib/em/protocols/line_and_text.rb +125 -0
  89. data/lib/em/protocols/linetext2.rb +161 -0
  90. data/lib/em/protocols/memcache.rb +323 -0
  91. data/lib/em/protocols/object_protocol.rb +45 -0
  92. data/lib/em/protocols/postgres3.rb +247 -0
  93. data/lib/em/protocols/saslauth.rb +175 -0
  94. data/lib/em/protocols/smtpclient.rb +357 -0
  95. data/lib/em/protocols/smtpserver.rb +640 -0
  96. data/lib/em/protocols/socks4.rb +66 -0
  97. data/lib/em/protocols/stomp.rb +200 -0
  98. data/lib/em/protocols/tcptest.rb +53 -0
  99. data/lib/em/pure_ruby.rb +1019 -0
  100. data/lib/em/queue.rb +62 -0
  101. data/lib/em/spawnable.rb +85 -0
  102. data/lib/em/streamer.rb +130 -0
  103. data/lib/em/tick_loop.rb +85 -0
  104. data/lib/em/timers.rb +57 -0
  105. data/lib/em/version.rb +3 -0
  106. data/lib/eventmachine.rb +1540 -0
  107. data/lib/evma.rb +32 -0
  108. data/lib/evma/callback.rb +32 -0
  109. data/lib/evma/container.rb +75 -0
  110. data/lib/evma/factory.rb +77 -0
  111. data/lib/evma/protocol.rb +87 -0
  112. data/lib/evma/reactor.rb +48 -0
  113. data/lib/jeventmachine.rb +257 -0
  114. data/setup.rb +1585 -0
  115. data/tasks/cpp.rake_example +77 -0
  116. data/tests/client.crt +31 -0
  117. data/tests/client.key +51 -0
  118. data/tests/test_attach.rb +136 -0
  119. data/tests/test_basic.rb +249 -0
  120. data/tests/test_channel.rb +63 -0
  121. data/tests/test_connection_count.rb +35 -0
  122. data/tests/test_defer.rb +49 -0
  123. data/tests/test_deferrable.rb +35 -0
  124. data/tests/test_epoll.rb +160 -0
  125. data/tests/test_error_handler.rb +35 -0
  126. data/tests/test_errors.rb +82 -0
  127. data/tests/test_exc.rb +55 -0
  128. data/tests/test_file_watch.rb +49 -0
  129. data/tests/test_futures.rb +198 -0
  130. data/tests/test_get_sock_opt.rb +30 -0
  131. data/tests/test_handler_check.rb +37 -0
  132. data/tests/test_hc.rb +190 -0
  133. data/tests/test_httpclient.rb +227 -0
  134. data/tests/test_httpclient2.rb +154 -0
  135. data/tests/test_inactivity_timeout.rb +50 -0
  136. data/tests/test_kb.rb +60 -0
  137. data/tests/test_ltp.rb +190 -0
  138. data/tests/test_ltp2.rb +317 -0
  139. data/tests/test_next_tick.rb +133 -0
  140. data/tests/test_object_protocol.rb +37 -0
  141. data/tests/test_pause.rb +70 -0
  142. data/tests/test_pending_connect_timeout.rb +48 -0
  143. data/tests/test_process_watch.rb +50 -0
  144. data/tests/test_processes.rb +128 -0
  145. data/tests/test_proxy_connection.rb +144 -0
  146. data/tests/test_pure.rb +134 -0
  147. data/tests/test_queue.rb +44 -0
  148. data/tests/test_running.rb +42 -0
  149. data/tests/test_sasl.rb +72 -0
  150. data/tests/test_send_file.rb +251 -0
  151. data/tests/test_servers.rb +76 -0
  152. data/tests/test_smtpclient.rb +83 -0
  153. data/tests/test_smtpserver.rb +85 -0
  154. data/tests/test_spawn.rb +322 -0
  155. data/tests/test_ssl_args.rb +79 -0
  156. data/tests/test_ssl_methods.rb +50 -0
  157. data/tests/test_ssl_verify.rb +82 -0
  158. data/tests/test_tick_loop.rb +59 -0
  159. data/tests/test_timers.rb +160 -0
  160. data/tests/test_ud.rb +36 -0
  161. data/tests/testem.rb +31 -0
  162. metadata +251 -0
data/README ADDED
@@ -0,0 +1,81 @@
1
+ = RUBY/EventMachine
2
+
3
+ Homepage:: http://rubyeventmachine.com
4
+ Rubyforge Page:: http://rubyforge.org/projects/eventmachine
5
+ Google Group:: http://groups.google.com/group/eventmachine
6
+ RDoc:: http://eventmachine.rubyforge.org
7
+ IRC:: #eventmachine on irc.freenode.net
8
+ Copyright:: (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Email:: gmail address: garbagecat10
10
+
11
+ EventMachine is copyrighted free software made available under the terms
12
+ of either the GPL or Ruby's License. See the file COPYING for full licensing
13
+ information.
14
+ See EventMachine and EventMachine::Connection for documentation and
15
+ usage examples.
16
+
17
+ EventMachine implements a fast, single-threaded engine for arbitrary network
18
+ communications. It's extremely easy to use in Ruby. EventMachine wraps all
19
+ interactions with IP sockets, allowing programs to concentrate on the
20
+ implementation of network protocols. It can be used to create both network
21
+ servers and clients. To create a server or client, a Ruby program only needs
22
+ to specify the IP address and port, and provide a Module that implements the
23
+ communications protocol. Implementations of several standard network protocols
24
+ are provided with the package, primarily to serve as examples. The real goal
25
+ of EventMachine is to enable programs to easily interface with other programs
26
+ using TCP/IP, especially if custom protocols are required.
27
+
28
+ A Ruby program uses EventMachine by registering the addresses and ports of
29
+ network servers and clients, and then entering an event-handling loop.
30
+ EventMachine contains glue code in Ruby which will execute callbacks to
31
+ user-supplied code for all significant events occurring in the clients
32
+ and servers. These events include connection acceptance, startup, data-receipt,
33
+ shutdown, and timer events. Arbitrary processing can be performed by user code
34
+ during event callbacks, including sending data to one or more remote network
35
+ peers, startup and shutdown of network connections, and installation of new
36
+ event handlers.
37
+
38
+ The EventMachine implements a very familiar model for network programming.
39
+ It emphasizes: 1) the maximum possible isolation of user code from network
40
+ objects like sockets; 2) maximum performance and scalability; and 3) extreme
41
+ ease-of-use for user code. It attempts to provide a higher-level interface
42
+ than similar projects which expose a variety of low-level event-handling
43
+ and networking objects to Ruby programs.
44
+
45
+ The design and implementation of EventMachine grows out of nearly ten years
46
+ of experience writing high-performance, high-scaling network server applications.
47
+ We have taken particular account of the challenges and lessons described as
48
+ the "C10K problem" by Dan Kegel and others.
49
+
50
+ EventMachine consists of an extension library written in C++ (which can be
51
+ accessed from languages other than Ruby), and a Ruby module which can be dropped
52
+ into user programs. On most platforms, EventMachine uses the
53
+ <tt>select(2)</tt> system call,
54
+ so it will run on a large range of Unix-like systems and on Microsoft
55
+ Windows with good performance and scalability. On Linux 2.6 kernels, EventMachine
56
+ automatically configures itself to use <tt>epoll(4)</tt> instead of
57
+ <tt>select(2),</tt> so scalability on that platform can be significantly
58
+ improved.
59
+
60
+ Here's a fully-functional echo server written with EventMachine:
61
+
62
+ require 'eventmachine'
63
+
64
+ module EchoServer
65
+ def post_init
66
+ puts "-- someone connected to the echo server!"
67
+ end
68
+
69
+ def receive_data data
70
+ send_data ">>>you sent: #{data}"
71
+ close_connection if data =~ /quit/i
72
+ end
73
+
74
+ def unbind
75
+ puts "-- someone disconnected from the echo server!"
76
+ end
77
+ end
78
+
79
+ EventMachine::run {
80
+ EventMachine::start_server "127.0.0.1", 8081, EchoServer
81
+ }
data/Rakefile ADDED
@@ -0,0 +1,370 @@
1
+ #!/usr/bin/env rake
2
+ #--
3
+ # Ruby/EventMachine
4
+ # http://rubyeventmachine.com
5
+ # Copyright (C) 2006-07 by Francis Cianfrocca
6
+ #
7
+ # This program is copyrighted free software. You may use it under
8
+ # the terms of either the GPL or Ruby's License. See the file
9
+ # COPYING in the EventMachine distribution for full licensing
10
+ # information.
11
+ #
12
+ # $Id$
13
+ #++
14
+
15
+ ### OLD RAKE: ###
16
+ # # The tasks and external gemspecs we used to generate binary gems are now
17
+ # # obsolete. Use Patrick Hurley's gembuilder to build binary gems for any
18
+ # # desired platform.
19
+ # # To build a binary gem on Win32, ensure that the include and lib paths
20
+ # # both contain the proper references to OPENSSL. Use the static version
21
+ # # of the libraries, not the dynamic, otherwise we expose the user to a
22
+ # # runtime dependency.
23
+ #
24
+ # # To build a binary gem for win32, first build rubyeventmachine.so
25
+ # # using VC6 outside of the build tree (the normal way: ruby extconf.rb,
26
+ # # and then nmake). Then copy rubyeventmachine.so into the lib directory,
27
+ # # and run rake gemwin32.
28
+ #
29
+
30
+ require 'rubygems' unless defined?(Gem)
31
+ require 'rake' unless defined?(Rake)
32
+
33
+ Package = false # Build zips and tarballs?
34
+ Dir.glob('tasks/*.rake').each { |r| Rake.application.add_import r }
35
+
36
+ MAKE = ENV['MAKE'] || if RUBY_PLATFORM =~ /mswin/ # mingw uses make.
37
+ 'nmake'
38
+ else
39
+ 'make'
40
+ end
41
+
42
+ desc "Build gemspec, then build eventmachine, then run tests."
43
+ task :default => [:build, :test]
44
+
45
+ desc "Build extension (or EVENTMACHINE_LIBRARY) and place in lib"
46
+ build_task = 'ext:build'
47
+ build_task = 'java:build' if RUBY_PLATFORM =~ /java/
48
+ task :build => build_task do |t|
49
+ Dir.glob('{ext,java/src,ext/fastfilereader}/*.{so,bundle,dll,jar}').each do |f|
50
+ mv f, "lib"
51
+ end
52
+ end
53
+
54
+ task :dummy_build
55
+
56
+ require 'rake/testtask'
57
+ Rake::TestTask.new(:test) do |t|
58
+ t.pattern = 'tests/**/test_*.rb'
59
+ t.warning = true
60
+ end
61
+
62
+ # Basic clean definition, this is enhanced by imports aswell.
63
+ task :clean do
64
+ chdir 'ext' do
65
+ sh "#{MAKE} clean" if test ?e, 'Makefile'
66
+ end
67
+ chdir 'ext/fastfilereader' do
68
+ sh "#{MAKE} clean" if test ?e, 'Makefile'
69
+ end
70
+ Dir.glob('**/Makefile').each { |file| rm file }
71
+ Dir.glob('**/*.{o,so,bundle,class,jar,dll,log}').each { |file| rm file }
72
+ Dir.glob('ext/**/conftest.dSYM').each{ |file| rm_rf file }
73
+ end
74
+
75
+ Spec = Gem::Specification.new do |s|
76
+ s.name = "eventmachine"
77
+ s.summary = "Ruby/EventMachine library"
78
+ s.platform = Gem::Platform::RUBY
79
+
80
+ s.has_rdoc = true
81
+ s.rdoc_options = %w(--title EventMachine --main README --line-numbers -x lib/em/version -x lib/emva -x lib/evma/ -x lib/jeventmachine)
82
+ s.extra_rdoc_files = Dir['README,docs/*']
83
+
84
+ excludes = %w(.gitignore)
85
+ s.files = `git ls-files`.split("\n") - excludes rescue Errno::ENOENT
86
+
87
+ s.require_path = 'lib'
88
+
89
+ # TODO / XXX - should we enable this? rubygems fails the install if anything
90
+ # is broken. What we could do is CI submission, though, and always terminate
91
+ # with a positive code...
92
+ # s.test_file = "tests/testem.rb"
93
+
94
+ # XXX Using rake to compile extensions breaks when you have multiple ruby installations
95
+ # and your path isn't set. We can switch back to this once the Gem.exec patch is merged.
96
+ # s.extensions = "Rakefile"
97
+ s.extensions = ["ext/extconf.rb", "ext/fastfilereader/extconf.rb"]
98
+
99
+ s.author = "Francis Cianfrocca"
100
+ s.email = "garbagecat10@gmail.com"
101
+ s.rubyforge_project = 'eventmachine'
102
+ s.homepage = "http://rubyeventmachine.com"
103
+
104
+ # Pulled in from readme, as code to pull from readme was not working!
105
+ # Might be worth removing as no one seems to use gem info anyway.
106
+ s.description = <<-EOD
107
+ EventMachine implements a fast, single-threaded engine for arbitrary network
108
+ communications. It's extremely easy to use in Ruby. EventMachine wraps all
109
+ interactions with IP sockets, allowing programs to concentrate on the
110
+ implementation of network protocols. It can be used to create both network
111
+ servers and clients. To create a server or client, a Ruby program only needs
112
+ to specify the IP address and port, and provide a Module that implements the
113
+ communications protocol. Implementations of several standard network protocols
114
+ are provided with the package, primarily to serve as examples. The real goal
115
+ of EventMachine is to enable programs to easily interface with other programs
116
+ using TCP/IP, especially if custom protocols are required.
117
+ EOD
118
+
119
+ require 'lib/em/version'
120
+ s.version = EventMachine::VERSION
121
+ end
122
+
123
+ if RUBY_PLATFORM =~ /mswin/
124
+ Spec.platform = 'x86-mswin32-60'
125
+ Spec.files += %w[ lib/rubyeventmachine.so lib/fastfilereaderext.so ]
126
+ Spec.extensions = nil
127
+ elsif RUBY_PLATFORM =~ /java/
128
+ Spec.platform = 'java'
129
+ Spec.files += %w[ lib/em_reactor.jar ]
130
+ Spec.extensions = nil
131
+ end
132
+
133
+ # this is a hack right now, it requires installing msysgit in the global path so it can use tar/curl/etc.
134
+ namespace :win32 do
135
+ task :check_git do
136
+ unless `git` =~ /rebase/
137
+ raise 'git not found, install msys git into the GLOBAL PATH: http://msysgit.googlecode.com/files/Git-1.6.2-preview20090308.exe'
138
+ end
139
+ end
140
+
141
+ task :check_vc6 do
142
+ begin
143
+ raise unless `nmake 2>&1` =~ /Microsoft/
144
+ rescue
145
+ raise 'VC6 not found, please run c:\vc\setvc.bat vc6'
146
+ end
147
+ end
148
+
149
+ task :check_perl do
150
+ unless `perl --version` =~ /ActiveState/
151
+ raise 'ActiveState perl required to build OpenSSL: http://downloads.activestate.com/ActivePerl/Windows/5.10/ActivePerl-5.10.0.1004-MSWin32-x86-287188.msi'
152
+ end
153
+ end
154
+
155
+ task :build_openssl => [:check_git, :check_perl, :check_vc6] do
156
+ mkdir_p 'build'
157
+ chdir 'build' do
158
+ unless File.exists?('openssl-0.9.8j')
159
+ sh 'curl http://www.openssl.org/source/openssl-0.9.8j.tar.gz > openssl.tar.gz'
160
+ sh 'tar zxvf openssl.tar.gz' rescue nil # fails because of symlinks
161
+ end
162
+
163
+ mkdir_p 'local'
164
+ chdir 'openssl-0.9.8j' do
165
+ sh "perl Configure VC-WIN32 --prefix=\"../local/\""
166
+ sh 'ms\do_ms.bat'
167
+ sh 'nmake -f ms\nt.mak install'
168
+ end
169
+
170
+ chdir '../ext' do
171
+ sh 'git clean -fd .'
172
+ end
173
+
174
+ mv 'local/include/openssl', '../ext/'
175
+ mv 'local/lib/ssleay32.lib', '../ext/'
176
+ mv 'local/lib/libeay32.lib', '../ext/'
177
+ end
178
+ end
179
+
180
+ desc "build binary win32 gem"
181
+ task :gem => :build_openssl do
182
+ Rake::Task['build'].invoke
183
+ Rake::Task['gem'].invoke
184
+ end
185
+ end
186
+
187
+ namespace :ext do
188
+ ext_sources = FileList['ext/*.{h,cpp,rb,c}']
189
+ ffr_sources = FileList['ext/fastfilereader/*.{h,cpp,rb}']
190
+ file ext_extconf = 'ext/extconf.rb'
191
+ file ffr_extconf = 'ext/fastfilereader/extconf.rb'
192
+ ext_libname = "lib/rubyeventmachine.#{Config::CONFIG['DLEXT']}"
193
+ ffr_libname = "lib/fastfilereaderext.#{Config::CONFIG['DLEXT']}"
194
+
195
+ file ext_libname => ext_sources + ['ext/Makefile'] do
196
+ chdir('ext') { sh MAKE }
197
+ end
198
+
199
+ file ffr_libname => ffr_sources + ['ext/fastfilereader/Makefile'] do
200
+ chdir('ext/fastfilereader') { sh MAKE }
201
+ end
202
+
203
+ desc "Build C++ extension"
204
+ task :build => [:make]
205
+
206
+ task :make => ext_libname
207
+ task :make => ffr_libname
208
+
209
+ file 'ext/Makefile' => ext_extconf do
210
+ chdir 'ext' do
211
+ ruby 'extconf.rb'
212
+ end
213
+ end
214
+
215
+ file 'ext/fastfilereader/Makefile' => ffr_extconf do
216
+ chdir 'ext/fastfilereader' do
217
+ ruby 'extconf.rb'
218
+ end
219
+ end
220
+ end
221
+
222
+ namespace :java do
223
+ # This task creates the JRuby JAR file and leaves it in the lib directory.
224
+ # This step is required before executing the jgem task.
225
+ desc "Build java extension"
226
+ task :build => [:jar] do |t|
227
+ mv 'java/em_reactor.jar', 'lib/'
228
+ end
229
+
230
+ task :compile do
231
+ chdir('java') do
232
+ mkdir_p "build"
233
+ sh 'javac src/com/rubyeventmachine/*.java -d build'
234
+ end
235
+ end
236
+
237
+ task :jar => [:compile] do
238
+ chdir('java/build') do
239
+ sh "jar -cf ../em_reactor.jar com/rubyeventmachine/*.class"
240
+ end
241
+ end
242
+
243
+ desc "build a java binary gem"
244
+ task :gem => :build do
245
+ Spec.platform = 'java'
246
+ Spec.files += %w[ lib/em_reactor.jar ]
247
+ Spec.extensions = nil
248
+
249
+ Rake::Task['gem'].invoke
250
+ end
251
+ end
252
+
253
+ namespace :osx do
254
+ desc "Build OSX binary gem"
255
+ task :gem do
256
+ Spec.platform = RUBY_PLATFORM.sub(/darwin.+$/, 'darwin')
257
+ Spec.files += %w[ lib/rubyeventmachine.bundle lib/fastfilereaderext.bundle ]
258
+ Spec.extensions = nil
259
+
260
+ Rake::Task['build'].invoke
261
+ Rake::Task['gem'].invoke
262
+ end
263
+
264
+ # XXX gcc will still prefer the shared libssl on the system, so we need to hack the extconf
265
+ # XXX to use the static library to make this actually work
266
+ task :static_gem => [:build_openssl, :gem]
267
+
268
+ task :build_openssl do
269
+ mkdir_p 'build'
270
+ chdir 'build' do
271
+ unless File.exists?('openssl-0.9.8j')
272
+ sh 'curl http://www.openssl.org/source/openssl-0.9.8j.tar.gz > openssl-0.9.8j.tar.gz'
273
+ sh 'tar zxvf openssl-0.9.8j.tar.gz'
274
+ end
275
+
276
+ mkdir_p 'local'
277
+ chdir 'openssl-0.9.8j' do
278
+ local_dir = File.expand_path(File.join(File.dirname(__FILE__),'build','local'))
279
+ sh "./config --prefix=#{local_dir}"
280
+ sh 'make'
281
+ sh 'make install'
282
+ end
283
+
284
+ chdir '../ext' do
285
+ sh 'git clean -fd .'
286
+ end
287
+
288
+ mv 'local/include/openssl', '../ext/'
289
+ mv 'local/lib/libssl.a', '../ext/'
290
+ mv 'local/lib/libcrypto.a', '../ext/'
291
+ end
292
+ end
293
+ end
294
+
295
+ require 'rake/clean'
296
+
297
+ rdoc_task_type = begin
298
+ require 'rdoc/task'
299
+ RDoc::Task
300
+ rescue LoadError
301
+ require 'rake/rdoctask'
302
+ Rake::RDocTask
303
+ end
304
+ df = begin; require 'rdoc/rdoc'; require 'rdoc/generator/darkfish'; true; rescue LoadError; end
305
+ rdtask = rdoc_task_type.new do |rd|
306
+ rd.title = Spec.name
307
+ rd.rdoc_dir = 'rdoc'
308
+ rd.main = "README"
309
+ rd.rdoc_files.include("lib/**/*.rb", *Spec.extra_rdoc_files)
310
+ rd.rdoc_files.exclude(*%w(lib/em/version lib/emva lib/evma/ lib/pr_eventmachine lib/jeventmachine))
311
+ rd.template = 'darkfish' if df
312
+ end
313
+ Rake::Task[:clean].enhance [:clobber_rdoc]
314
+
315
+ desc 'Generate and open documentation'
316
+ task :docs => :rdoc do
317
+ case RUBY_PLATFORM
318
+ when /darwin/ ; sh 'open rdoc/index.html'
319
+ when /mswin|mingw/ ; sh 'start rdoc\index.html'
320
+ else
321
+ sh 'firefox rdoc/index.html'
322
+ end
323
+ end
324
+
325
+ def windows?; RUBY_PLATFORM =~ /mswin|mingw/; end
326
+ def sudo(cmd)
327
+ if windows? || (require 'etc'; Etc.getpwuid.uid == 0)
328
+ sh cmd
329
+ else
330
+ sh "sudo #{cmd}"
331
+ end
332
+ end
333
+ def gem_cmd(action, name, *args)
334
+ rb = Gem.ruby rescue nil
335
+ rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
336
+ sudo "#{rb} -r rubygems -e 'require %{rubygems/gem_runner}; Gem::GemRunner.new.run(%w{#{action} #{name} #{args.join(' ')}})'"
337
+ end
338
+
339
+ begin
340
+ require 'rubygems/package_task'
341
+ Gem::PackageTask
342
+ rescue LoadError
343
+ require 'rake/gempackagetask'
344
+ Rake::GemPackageTask
345
+ end.new(Spec) do |pkg|
346
+ pkg.need_tar, pkg.need_tar_gz, pkg.need_zip = true, true, true if Package
347
+ pkg.gem_spec = Spec
348
+ end
349
+
350
+ Rake::Task[:clean].enhance [:clobber_package]
351
+
352
+ namespace :gem do
353
+ desc 'Install gem (and sudo if required)'
354
+ task :install => :package do
355
+ gem_cmd(:install, "pkg/#{Spec.name}-#{Spec.version}.gem")
356
+ end
357
+
358
+ desc 'Uninstall gem (and sudo if required)'
359
+ task :uninstall do
360
+ gem_cmd(:uninstall, "#{Spec.name}", "-v=#{Spec.version}")
361
+ end
362
+
363
+ desc "Generate new gemspec"
364
+ task :spec => :clobber do
365
+ open("eventmachine.gemspec", 'w') { |f| f.write Spec.to_ruby }
366
+ end
367
+ end
368
+
369
+ task :clobber => :clean
370
+ task :test => :build