eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/{docs/README → README} +21 -13
- data/Rakefile +14 -4
- data/docs/DEFERRABLES +0 -5
- data/docs/INSTALL +2 -4
- data/docs/LEGAL +1 -1
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
- data/docs/PURE_RUBY +0 -2
- data/docs/RELEASE_NOTES +0 -2
- data/docs/SMTP +0 -7
- data/docs/SPAWNED_PROCESSES +0 -4
- data/docs/TODO +0 -2
- data/eventmachine.gemspec +41 -32
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/helper.rb +2 -0
- data/ext/cmain.cpp +685 -586
- data/ext/cplusplus.cpp +15 -6
- data/ext/ed.cpp +1732 -1522
- data/ext/ed.h +407 -380
- data/ext/em.cpp +2263 -1937
- data/ext/em.h +223 -186
- data/ext/eventmachine.h +111 -98
- data/ext/eventmachine_cpp.h +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/kb.cpp +81 -82
- data/ext/pipe.cpp +349 -351
- data/ext/project.h +21 -0
- data/ext/rubymain.cpp +1047 -847
- data/ext/ssl.cpp +38 -1
- data/ext/ssl.h +5 -1
- data/java/src/com/rubyeventmachine/Application.java +7 -3
- data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
- data/lib/{protocols → em}/buftok.rb +16 -5
- data/lib/em/callback.rb +26 -0
- data/lib/em/channel.rb +57 -0
- data/lib/em/connection.rb +505 -0
- data/lib/em/deferrable.rb +144 -165
- data/lib/em/file_watch.rb +54 -0
- data/lib/em/future.rb +24 -25
- data/lib/em/messages.rb +1 -1
- data/lib/em/process_watch.rb +44 -0
- data/lib/em/processes.rb +119 -113
- data/lib/em/protocols.rb +35 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +263 -0
- data/lib/em/protocols/httpclient2.rb +582 -0
- data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
- data/lib/em/protocols/linetext2.rb +160 -0
- data/lib/{protocols → em/protocols}/memcache.rb +37 -7
- data/lib/em/protocols/object_protocol.rb +39 -0
- data/lib/em/protocols/postgres3.rb +247 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +331 -0
- data/lib/em/protocols/smtpserver.rb +547 -0
- data/lib/em/protocols/stomp.rb +200 -0
- data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
- data/lib/em/queue.rb +61 -0
- data/lib/em/spawnable.rb +53 -56
- data/lib/em/streamer.rb +92 -74
- data/lib/em/timers.rb +55 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1636 -1926
- data/lib/evma.rb +1 -1
- data/lib/jeventmachine.rb +106 -101
- data/lib/pr_eventmachine.rb +47 -36
- data/tasks/project.rake +2 -1
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/test_attach.rb +18 -0
- data/tests/test_basic.rb +285 -231
- data/tests/test_channel.rb +63 -0
- data/tests/test_connection_count.rb +2 -2
- data/tests/test_epoll.rb +162 -163
- data/tests/test_errors.rb +36 -36
- data/tests/test_exc.rb +22 -25
- data/tests/test_file_watch.rb +49 -0
- data/tests/test_futures.rb +77 -93
- data/tests/test_hc.rb +2 -2
- data/tests/test_httpclient.rb +55 -52
- data/tests/test_httpclient2.rb +153 -155
- data/tests/test_inactivity_timeout.rb +30 -0
- data/tests/test_kb.rb +8 -9
- data/tests/test_ltp2.rb +274 -277
- data/tests/test_next_tick.rb +135 -109
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +128 -95
- data/tests/test_proxy_connection.rb +92 -0
- data/tests/test_pure.rb +1 -5
- data/tests/test_queue.rb +44 -0
- data/tests/test_running.rb +9 -14
- data/tests/test_sasl.rb +32 -34
- data/tests/test_send_file.rb +175 -176
- data/tests/test_servers.rb +37 -41
- data/tests/test_smtpserver.rb +47 -55
- data/tests/test_spawn.rb +284 -291
- data/tests/test_ssl_args.rb +1 -1
- data/tests/test_ssl_methods.rb +1 -1
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_timers.rb +81 -88
- data/tests/test_ud.rb +0 -7
- data/tests/testem.rb +1 -1
- metadata +52 -36
- data/lib/em/eventable.rb +0 -39
- data/lib/eventmachine_version.rb +0 -31
- data/lib/protocols/header_and_content.rb +0 -129
- data/lib/protocols/httpcli2.rb +0 -803
- data/lib/protocols/httpclient.rb +0 -270
- data/lib/protocols/linetext2.rb +0 -161
- data/lib/protocols/postgres.rb +0 -261
- data/lib/protocols/saslauth.rb +0 -179
- data/lib/protocols/smtpclient.rb +0 -308
- data/lib/protocols/smtpserver.rb +0 -556
- data/lib/protocols/stomp.rb +0 -153
- data/tests/test_eventables.rb +0 -77
data/tests/test_attach.rb
CHANGED
@@ -80,4 +80,22 @@ class TestAttach < Test::Unit::TestCase
|
|
80
80
|
|
81
81
|
assert_equal $read, "ghi\n"
|
82
82
|
end
|
83
|
+
|
84
|
+
module PipeReader
|
85
|
+
def receive_data data
|
86
|
+
$read = data
|
87
|
+
EM.stop
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_read_write_pipe
|
92
|
+
EM.run{
|
93
|
+
$r, $w = IO.pipe
|
94
|
+
EM.attach $r, PipeReader
|
95
|
+
writer = EM.attach($w)
|
96
|
+
writer.send_data 'ghi'
|
97
|
+
}
|
98
|
+
|
99
|
+
assert_equal $read, "ghi"
|
100
|
+
end
|
83
101
|
end
|
data/tests/test_basic.rb
CHANGED
@@ -1,231 +1,285 @@
|
|
1
|
-
# $Id$
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 8 April 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
|
-
|
27
|
-
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
28
|
-
require 'eventmachine'
|
29
|
-
require '
|
30
|
-
|
31
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
EventMachine.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
# the loop
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
#
|
162
|
-
# This
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
# method
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
# (
|
176
|
-
#
|
177
|
-
#
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
#
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
$
|
219
|
-
|
220
|
-
|
221
|
-
EM::start_server TestHost, TestPort, BrsTestSrv
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
1
|
+
# $Id$
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 8 April 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
|
+
|
27
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
28
|
+
require 'eventmachine'
|
29
|
+
require 'socket'
|
30
|
+
require 'test/unit'
|
31
|
+
|
32
|
+
class TestBasic < Test::Unit::TestCase
|
33
|
+
|
34
|
+
def setup
|
35
|
+
assert(!EM.reactor_running?)
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
assert(!EM.reactor_running?)
|
40
|
+
end
|
41
|
+
|
42
|
+
#-------------------------------------
|
43
|
+
|
44
|
+
def test_libtype
|
45
|
+
lt = EventMachine.library_type
|
46
|
+
em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
|
47
|
+
|
48
|
+
# Running from test runner, under jruby.
|
49
|
+
if RUBY_PLATFORM == 'java'
|
50
|
+
unless em_lib == :pure_ruby
|
51
|
+
assert_equal( :java, lt )
|
52
|
+
return
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
case em_lib
|
57
|
+
when :pure_ruby
|
58
|
+
assert_equal( :pure_ruby, lt )
|
59
|
+
when :extension
|
60
|
+
assert_equal( :extension, lt )
|
61
|
+
when :java
|
62
|
+
assert_equal( :java, lt )
|
63
|
+
else
|
64
|
+
# Running from jruby as a standalone test.
|
65
|
+
if RUBY_PLATFORM == 'java'
|
66
|
+
assert_equal( :java, lt )
|
67
|
+
else
|
68
|
+
assert_equal( :extension, lt )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
#-------------------------------------
|
74
|
+
|
75
|
+
|
76
|
+
def test_em
|
77
|
+
EventMachine.run {
|
78
|
+
EventMachine.add_timer 0 do
|
79
|
+
EventMachine.stop
|
80
|
+
end
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
#-------------------------------------
|
85
|
+
|
86
|
+
def test_timer
|
87
|
+
n = 0
|
88
|
+
EventMachine.run {
|
89
|
+
EventMachine.add_periodic_timer(0.1) {
|
90
|
+
n += 1
|
91
|
+
EventMachine.stop if n == 2
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
#-------------------------------------
|
97
|
+
|
98
|
+
# This test once threw an already-running exception.
|
99
|
+
module Trivial
|
100
|
+
def post_init
|
101
|
+
EventMachine.stop
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_server
|
106
|
+
EventMachine.run {
|
107
|
+
EventMachine.start_server "localhost", 9000, Trivial
|
108
|
+
EventMachine.connect "localhost", 9000
|
109
|
+
}
|
110
|
+
assert( true ) # make sure it halts
|
111
|
+
end
|
112
|
+
|
113
|
+
#--------------------------------------
|
114
|
+
|
115
|
+
# EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
|
116
|
+
# the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
|
117
|
+
# even after the supplied block completes.
|
118
|
+
def test_run_block
|
119
|
+
assert !EM.reactor_running?
|
120
|
+
a = nil
|
121
|
+
EM.run_block { a = "Worked" }
|
122
|
+
assert a
|
123
|
+
assert !EM.reactor_running?
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
#--------------------------------------
|
128
|
+
|
129
|
+
# TODO! This is an unfinished edge case.
|
130
|
+
# EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers.
|
131
|
+
# A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure
|
132
|
+
# block in EM::run). But if EM is processing an unbind request, the release_machine call
|
133
|
+
# will cause a segmentation fault.
|
134
|
+
#
|
135
|
+
|
136
|
+
TestHost = "127.0.0.1"
|
137
|
+
TestPort = 9070
|
138
|
+
|
139
|
+
class UnbindError < EM::Connection
|
140
|
+
def initialize *args
|
141
|
+
super
|
142
|
+
end
|
143
|
+
def connection_completed
|
144
|
+
close_connection_after_writing
|
145
|
+
end
|
146
|
+
def unbind
|
147
|
+
raise "Blooey"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def xxx_test_unbind_error
|
152
|
+
assert_raises( RuntimeError ) {
|
153
|
+
EM.run {
|
154
|
+
EM.start_server TestHost, TestPort
|
155
|
+
EM.connect TestHost, TestPort, UnbindError
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
#------------------------------------
|
161
|
+
#
|
162
|
+
# TODO. This is an unfinished bug fix.
|
163
|
+
# This case was originally reported by Dan Aquino. If you throw a Ruby exception
|
164
|
+
# in a post_init handler, it gets rethrown as a confusing reactor exception.
|
165
|
+
# The problem is in eventmachine.rb, which calls post_init within the private
|
166
|
+
# initialize method of the EM::Connection class. This happens in both the EM::connect
|
167
|
+
# method and in the code that responds to connection-accepted events.
|
168
|
+
# What happens is that we instantiate the new connection object, which calls
|
169
|
+
# initialize, and then after initialize returns, we stick the new connection object
|
170
|
+
# into EM's @conns hashtable.
|
171
|
+
# But the problem is that Connection::initialize calls #post_init before it returns,
|
172
|
+
# and this may be user-written code that may throw an uncaught Ruby exception.
|
173
|
+
# If that happens, the reactor will abort, and it will then try to run down open
|
174
|
+
# connections. Because @conns never got a chance to properly reflect the new connection
|
175
|
+
# (because initialize never returned), we throw a ConnectionNotBound error
|
176
|
+
# (eventmachine.rb line 1080).
|
177
|
+
# When the bug is fixed, activate this test case.
|
178
|
+
#
|
179
|
+
|
180
|
+
class PostInitError < EM::Connection
|
181
|
+
def post_init
|
182
|
+
aaa bbb # should produce a Ruby exception
|
183
|
+
end
|
184
|
+
end
|
185
|
+
# This test causes issues, the machine becomes unreleasable after
|
186
|
+
# release_machine suffers an exception in event_callback.
|
187
|
+
def xxx_test_post_init_error
|
188
|
+
assert_raises( EventMachine::ConnectionNotBound ) {
|
189
|
+
EM.run {
|
190
|
+
EM::Timer.new(1) {EM.stop}
|
191
|
+
EM.start_server TestHost, TestPort
|
192
|
+
EM.connect TestHost, TestPort, PostInitError
|
193
|
+
}
|
194
|
+
}
|
195
|
+
EM.run {
|
196
|
+
EM.stop
|
197
|
+
}
|
198
|
+
assert !EM.reactor_running?
|
199
|
+
end
|
200
|
+
|
201
|
+
module BrsTestSrv
|
202
|
+
def receive_data data
|
203
|
+
$received << data
|
204
|
+
end
|
205
|
+
def unbind
|
206
|
+
EM.stop
|
207
|
+
end
|
208
|
+
end
|
209
|
+
module BrsTestCli
|
210
|
+
def post_init
|
211
|
+
send_data $sent
|
212
|
+
close_connection_after_writing
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# From ticket #50
|
217
|
+
def test_byte_range_send
|
218
|
+
$received = ''
|
219
|
+
$sent = (0..255).to_a.pack('C*')
|
220
|
+
EM::run {
|
221
|
+
EM::start_server TestHost, TestPort, BrsTestSrv
|
222
|
+
EM::connect TestHost, TestPort, BrsTestCli
|
223
|
+
|
224
|
+
EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
|
225
|
+
}
|
226
|
+
assert_equal($sent, $received)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_bind_connect
|
230
|
+
local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
|
231
|
+
|
232
|
+
bind_port = rand(33333)+1025
|
233
|
+
|
234
|
+
test = self
|
235
|
+
EM.run do
|
236
|
+
EM.start_server(TestHost, TestPort, Module.new do
|
237
|
+
define_method :post_init do
|
238
|
+
begin
|
239
|
+
test.assert_equal bind_port, Socket.unpack_sockaddr_in(get_peername).first
|
240
|
+
test.assert_equal local_ip, Socket.unpack_sockaddr_in(get_peername).last
|
241
|
+
ensure
|
242
|
+
EM.stop_event_loop
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end)
|
246
|
+
EM.bind_connect local_ip, bind_port, TestHost, TestPort
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_reactor_thread?
|
251
|
+
assert !EM.reactor_thread?
|
252
|
+
EM.run { assert EM.reactor_thread?; EM.stop }
|
253
|
+
assert !EM.reactor_thread?
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_schedule_on_reactor_thread
|
257
|
+
x = false
|
258
|
+
EM.run do
|
259
|
+
EM.schedule { x = true }
|
260
|
+
EM.stop
|
261
|
+
end
|
262
|
+
assert x
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_schedule_from_thread
|
266
|
+
x = false
|
267
|
+
assert !x
|
268
|
+
EM.run do
|
269
|
+
Thread.new { EM.schedule { x = true } }.join
|
270
|
+
EM.stop
|
271
|
+
end
|
272
|
+
assert x
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_set_heartbeat_interval
|
276
|
+
interval = 0.5
|
277
|
+
EM.run {
|
278
|
+
EM.set_heartbeat_interval interval
|
279
|
+
$interval = EM.get_heartbeat_interval
|
280
|
+
EM.stop
|
281
|
+
}
|
282
|
+
assert_equal(interval, $interval)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|