eventmachine 0.12.8-x86-mswin32-60 → 0.12.10-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -13
- data/Rakefile +374 -264
- data/eventmachine.gemspec +4 -5
- data/ext/binder.cpp +125 -126
- data/ext/binder.h +46 -48
- data/ext/cmain.cpp +184 -42
- data/ext/cplusplus.cpp +202 -202
- data/ext/ed.cpp +242 -81
- data/ext/ed.h +39 -22
- data/ext/em.cpp +127 -108
- data/ext/em.h +27 -18
- data/ext/emwin.cpp +3 -3
- data/ext/eventmachine.h +49 -38
- data/ext/eventmachine_cpp.h +96 -96
- data/ext/extconf.rb +147 -132
- data/ext/fastfilereader/extconf.rb +82 -76
- data/ext/project.h +151 -140
- data/ext/rubymain.cpp +222 -103
- data/ext/ssl.cpp +460 -460
- data/ext/ssl.h +94 -94
- data/java/src/com/rubyeventmachine/EmReactor.java +570 -423
- data/java/src/com/rubyeventmachine/EventableChannel.java +69 -57
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -171
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -244
- data/java/src/com/rubyeventmachine/{Application.java → application/Application.java} +194 -200
- data/java/src/com/rubyeventmachine/{Connection.java → application/Connection.java} +74 -74
- data/java/src/com/rubyeventmachine/{ConnectionFactory.java → application/ConnectionFactory.java} +36 -36
- data/java/src/com/rubyeventmachine/{DefaultConnectionFactory.java → application/DefaultConnectionFactory.java} +46 -46
- data/java/src/com/rubyeventmachine/{PeriodicTimer.java → application/PeriodicTimer.java} +38 -38
- data/java/src/com/rubyeventmachine/{Timer.java → application/Timer.java} +54 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -108
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -146
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -74
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -89
- data/lib/em/connection.rb +71 -12
- data/lib/em/deferrable.rb +191 -186
- data/lib/em/protocols.rb +36 -35
- data/lib/em/protocols/httpclient2.rb +590 -582
- data/lib/em/protocols/line_and_text.rb +125 -126
- data/lib/em/protocols/linetext2.rb +161 -160
- data/lib/em/protocols/object_protocol.rb +45 -39
- data/lib/em/protocols/smtpclient.rb +357 -331
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/queue.rb +60 -60
- data/lib/em/timers.rb +56 -55
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +125 -169
- data/lib/jeventmachine.rb +257 -142
- data/tasks/{cpp.rake → cpp.rake_example} +76 -76
- data/tests/test_attach.rb +125 -100
- data/tests/test_basic.rb +1 -2
- data/tests/test_connection_count.rb +34 -44
- data/tests/test_epoll.rb +0 -2
- data/tests/test_get_sock_opt.rb +30 -0
- data/tests/test_httpclient2.rb +3 -3
- data/tests/test_inactivity_timeout.rb +21 -1
- data/tests/test_ltp.rb +182 -188
- data/tests/test_next_tick.rb +0 -2
- data/tests/test_pause.rb +70 -0
- data/tests/test_pending_connect_timeout.rb +48 -0
- data/tests/test_ssl_args.rb +78 -67
- data/tests/test_timers.rb +162 -141
- metadata +13 -11
- data/tasks/project.rake +0 -79
- data/tasks/tests.rake +0 -193
data/lib/jeventmachine.rb
CHANGED
@@ -1,142 +1,257 @@
|
|
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 'em_reactor'
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
def
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
def self.
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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 'em_reactor'
|
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
|
+
TimerFired = 100
|
63
|
+
ConnectionData = 101
|
64
|
+
ConnectionUnbound = 102
|
65
|
+
ConnectionAccepted = 103
|
66
|
+
ConnectionCompleted = 104
|
67
|
+
LoopbreakSignalled = 105
|
68
|
+
ConnectionNotifyReadable = 106
|
69
|
+
ConnectionNotifyWritable = 107
|
70
|
+
SslHandshakeCompleted = 108
|
71
|
+
|
72
|
+
# Exceptions that are defined in rubymain.cpp
|
73
|
+
class ConnectionNotBound < RuntimeError; end
|
74
|
+
class UnknownTimerFired < RuntimeError; end
|
75
|
+
class Unsupported < RuntimeError; end
|
76
|
+
|
77
|
+
# This thunk class used to be called EM, but that caused conflicts with
|
78
|
+
# the alias "EM" for module EventMachine. (FC, 20Jun08)
|
79
|
+
class JEM < com.rubyeventmachine.EmReactor
|
80
|
+
def eventCallback a1, a2, a3, a4
|
81
|
+
s = String.from_java_bytes(a3.array[a3.position...a3.limit]) if a3
|
82
|
+
EventMachine::event_callback a1, a2, s || a4
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
# class Connection < com.rubyeventmachine.Connection
|
87
|
+
# def associate_callback_target sig
|
88
|
+
# # No-op for the time being.
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
def self.initialize_event_machine
|
92
|
+
@em = JEM.new
|
93
|
+
end
|
94
|
+
def self.release_machine
|
95
|
+
@em = nil
|
96
|
+
end
|
97
|
+
def self.add_oneshot_timer interval
|
98
|
+
@em.installOneshotTimer interval
|
99
|
+
end
|
100
|
+
def self.run_machine
|
101
|
+
@em.run
|
102
|
+
end
|
103
|
+
def self.stop
|
104
|
+
@em.stop
|
105
|
+
end
|
106
|
+
def self.start_tcp_server server, port
|
107
|
+
@em.startTcpServer server, port
|
108
|
+
end
|
109
|
+
def self.stop_tcp_server sig
|
110
|
+
@em.stopTcpServer sig
|
111
|
+
end
|
112
|
+
def self.start_unix_server filename
|
113
|
+
# TEMPORARILY unsupported until someone figures out how to do it.
|
114
|
+
raise "unsupported on this platform"
|
115
|
+
end
|
116
|
+
def self.send_data sig, data, length
|
117
|
+
@em.sendData sig, data.to_java_bytes
|
118
|
+
end
|
119
|
+
def self.send_datagram sig, data, length, address, port
|
120
|
+
@em.sendDatagram sig, data, length, address, port
|
121
|
+
end
|
122
|
+
def self.connect_server server, port
|
123
|
+
bind_connect_server nil, nil, server, port
|
124
|
+
end
|
125
|
+
def self.bind_connect_server bind_addr, bind_port, server, port
|
126
|
+
@em.connectTcpServer bind_addr, bind_port.to_i, server, port
|
127
|
+
end
|
128
|
+
def self.close_connection sig, after_writing
|
129
|
+
@em.closeConnection sig, after_writing
|
130
|
+
end
|
131
|
+
def self.set_comm_inactivity_timeout sig, interval
|
132
|
+
@em.setCommInactivityTimeout sig, interval
|
133
|
+
end
|
134
|
+
def self.start_tls sig
|
135
|
+
@em.startTls sig
|
136
|
+
end
|
137
|
+
def self.ssl?
|
138
|
+
false
|
139
|
+
end
|
140
|
+
def self.signal_loopbreak
|
141
|
+
@em.signalLoopbreak
|
142
|
+
end
|
143
|
+
def self.set_timer_quantum q
|
144
|
+
@em.setTimerQuantum q
|
145
|
+
end
|
146
|
+
def self.epoll
|
147
|
+
# Epoll is a no-op for Java.
|
148
|
+
# The latest Java versions run epoll when possible in NIO.
|
149
|
+
end
|
150
|
+
def self.epoll= val
|
151
|
+
end
|
152
|
+
def self.kqueue
|
153
|
+
end
|
154
|
+
def self.kqueue= val
|
155
|
+
end
|
156
|
+
def self.epoll?
|
157
|
+
false
|
158
|
+
end
|
159
|
+
def self.kqueue?
|
160
|
+
false
|
161
|
+
end
|
162
|
+
def self.set_rlimit_nofile n_descriptors
|
163
|
+
# Currently a no-op for Java.
|
164
|
+
end
|
165
|
+
def self.open_udp_socket server, port
|
166
|
+
@em.openUdpSocket server, port
|
167
|
+
end
|
168
|
+
def self.invoke_popen cmd
|
169
|
+
# TEMPORARILY unsupported until someone figures out how to do it.
|
170
|
+
raise "unsupported on this platform"
|
171
|
+
end
|
172
|
+
def self.read_keyboard
|
173
|
+
# TEMPORARILY unsupported until someone figures out how to do it.
|
174
|
+
raise "temporarily unsupported on this platform"
|
175
|
+
end
|
176
|
+
def self.set_max_timer_count num
|
177
|
+
# harmless no-op in Java. There's no built-in timer limit.
|
178
|
+
@max_timer_count = num
|
179
|
+
end
|
180
|
+
def self.get_max_timer_count
|
181
|
+
# harmless no-op in Java. There's no built-in timer limit.
|
182
|
+
@max_timer_count || 100_000
|
183
|
+
end
|
184
|
+
def self.library_type
|
185
|
+
:java
|
186
|
+
end
|
187
|
+
def self.get_peername sig
|
188
|
+
if peer = @em.getPeerName(sig)
|
189
|
+
Socket.pack_sockaddr_in *peer
|
190
|
+
end
|
191
|
+
end
|
192
|
+
def self.attach_fd fileno, watch_mode
|
193
|
+
# 3Aug09: We could pass in the actual SocketChannel, but then it would be modified (set as non-blocking), and
|
194
|
+
# we would need some logic to make sure detach_fd below didn't clobber it. For now, we just always make a new
|
195
|
+
# SocketChannel for the underlying file descriptor
|
196
|
+
# if fileno.java_kind_of? SocketChannel
|
197
|
+
# ch = fileno
|
198
|
+
# ch.configureBlocking(false)
|
199
|
+
# fileno = nil
|
200
|
+
# elsif fileno.java_kind_of? java.nio.channels.Channel
|
201
|
+
|
202
|
+
if fileno.java_kind_of? java.nio.channels.Channel
|
203
|
+
field = fileno.getClass.getDeclaredField('fdVal')
|
204
|
+
field.setAccessible(true)
|
205
|
+
fileno = field.get(fileno)
|
206
|
+
else
|
207
|
+
raise ArgumentError, 'attach_fd requires Java Channel or POSIX fileno' unless fileno.is_a? Fixnum
|
208
|
+
end
|
209
|
+
|
210
|
+
if fileno == 0
|
211
|
+
raise "can't open STDIN as selectable in Java =("
|
212
|
+
elsif fileno.is_a? Fixnum
|
213
|
+
# 8Aug09: The following code is specific to the sun jvm's SocketChannelImpl. Is there a cross-platform
|
214
|
+
# way of implementing this? If so, also remember to update EventableSocketChannel#close and #cleanup
|
215
|
+
fd = FileDescriptor.new
|
216
|
+
fd.set_field 'fd', fileno
|
217
|
+
|
218
|
+
ch = SocketChannel.open
|
219
|
+
ch.configureBlocking(false)
|
220
|
+
ch.kill
|
221
|
+
ch.set_field 'fd', fd
|
222
|
+
ch.set_field 'fdVal', fileno
|
223
|
+
ch.set_field 'state', ch.get_field('ST_CONNECTED')
|
224
|
+
end
|
225
|
+
|
226
|
+
@em.attachChannel(ch,watch_mode)
|
227
|
+
end
|
228
|
+
def self.detach_fd sig
|
229
|
+
if ch = @em.detachChannel(sig)
|
230
|
+
ch.get_field 'fdVal'
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.set_notify_readable sig, mode
|
235
|
+
@em.setNotifyReadable(sig, mode)
|
236
|
+
end
|
237
|
+
def self.set_notify_writable sig, mode
|
238
|
+
@em.setNotifyWritable(sig, mode)
|
239
|
+
end
|
240
|
+
|
241
|
+
def self.is_notify_readable sig
|
242
|
+
@em.isNotifyReadable(sig)
|
243
|
+
end
|
244
|
+
def self.is_notify_writable sig
|
245
|
+
@em.isNotifyWritable(sig)
|
246
|
+
end
|
247
|
+
def self.get_connection_count
|
248
|
+
@em.getConnectionCount
|
249
|
+
end
|
250
|
+
|
251
|
+
class Connection
|
252
|
+
def associate_callback_target sig
|
253
|
+
# No-op for the time being
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
@@ -1,77 +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
|
-
|
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
77
|
end
|