eventmachine 1.0.9.1-java → 1.2.0.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +2 -2
- data/ext/cmain.cpp +77 -5
- data/ext/ed.cpp +112 -42
- data/ext/ed.h +27 -13
- data/ext/em.cpp +105 -163
- data/ext/em.h +10 -7
- data/ext/eventmachine.h +13 -1
- data/ext/extconf.rb +23 -14
- data/ext/fastfilereader/extconf.rb +1 -2
- data/ext/fastfilereader/rubymain.cpp +6 -6
- data/ext/project.h +9 -4
- data/ext/rubymain.cpp +155 -36
- data/ext/ssl.cpp +157 -13
- data/ext/ssl.h +7 -2
- data/lib/em/channel.rb +5 -0
- data/lib/em/completion.rb +2 -2
- data/lib/em/connection.rb +61 -3
- data/lib/em/iterator.rb +26 -5
- data/lib/em/pool.rb +1 -1
- data/lib/em/protocols/line_and_text.rb +1 -1
- data/lib/em/pure_ruby.rb +6 -1
- data/lib/em/queue.rb +16 -7
- data/lib/em/resolver.rb +46 -23
- data/lib/em/threaded_resource.rb +2 -2
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +59 -42
- data/lib/rubyeventmachine.jar +0 -0
- data/rakelib/package.rake +23 -1
- data/tests/dhparam.pem +13 -0
- data/tests/em_test_helper.rb +79 -0
- data/tests/test_basic.rb +17 -26
- data/tests/test_channel.rb +14 -1
- data/tests/test_connection_write.rb +2 -2
- data/tests/test_defer.rb +17 -0
- data/tests/test_epoll.rb +1 -1
- data/tests/test_fork.rb +75 -0
- data/tests/test_ipv4.rb +125 -0
- data/tests/test_ipv6.rb +131 -0
- data/tests/test_iterator.rb +18 -0
- data/tests/test_many_fds.rb +1 -1
- data/tests/test_queue.rb +14 -0
- data/tests/test_resolver.rb +23 -0
- data/tests/test_set_sock_opt.rb +2 -0
- data/tests/test_ssl_dhparam.rb +83 -0
- data/tests/test_ssl_ecdh_curve.rb +79 -0
- data/tests/test_ssl_extensions.rb +49 -0
- data/tests/test_ssl_methods.rb +19 -0
- data/tests/test_ssl_protocols.rb +246 -0
- data/tests/test_ssl_verify.rb +44 -0
- data/tests/test_system.rb +4 -0
- data/tests/test_unbind_reason.rb +5 -1
- metadata +101 -20
- data/.gitignore +0 -21
- data/.travis.yml +0 -22
- data/.yardopts +0 -7
- data/Gemfile +0 -2
- data/Rakefile +0 -20
- data/eventmachine.gemspec +0 -38
- data/rakelib/cpp.rake_example +0 -77
data/tests/test_basic.rb
CHANGED
@@ -93,15 +93,28 @@ class TestBasic < Test::Unit::TestCase
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
96
|
+
def test_unbind_error_during_stop
|
97
97
|
assert_raises( UnbindError::ERR ) {
|
98
98
|
EM.run {
|
99
99
|
EM.start_server "127.0.0.1", @port
|
100
|
-
EM.connect "127.0.0.1", @port, UnbindError
|
100
|
+
EM.connect "127.0.0.1", @port, UnbindError do
|
101
|
+
EM.stop
|
102
|
+
end
|
101
103
|
}
|
102
104
|
}
|
103
105
|
end
|
104
106
|
|
107
|
+
def test_unbind_error
|
108
|
+
EM.run {
|
109
|
+
EM.error_handler do |e|
|
110
|
+
assert(e.is_a?(UnbindError::ERR))
|
111
|
+
EM.stop
|
112
|
+
end
|
113
|
+
EM.start_server "127.0.0.1", @port
|
114
|
+
EM.connect "127.0.0.1", @port, UnbindError
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
105
118
|
module BrsTestSrv
|
106
119
|
def receive_data data
|
107
120
|
$received << data
|
@@ -131,6 +144,8 @@ class TestBasic < Test::Unit::TestCase
|
|
131
144
|
end
|
132
145
|
|
133
146
|
def test_bind_connect
|
147
|
+
pend('FIXME: this test is broken on Windows') if windows?
|
148
|
+
|
134
149
|
local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
|
135
150
|
|
136
151
|
bind_port = next_port
|
@@ -244,30 +259,6 @@ class TestBasic < Test::Unit::TestCase
|
|
244
259
|
assert_equal 1, num_close_scheduled
|
245
260
|
end
|
246
261
|
|
247
|
-
def test_fork_safe
|
248
|
-
omit_if(jruby?)
|
249
|
-
omit_if(rbx?, 'Omitting test on Rubinius because it hangs for unknown reasons')
|
250
|
-
|
251
|
-
read, write = IO.pipe
|
252
|
-
EM.run do
|
253
|
-
fork do
|
254
|
-
write.puts "forked"
|
255
|
-
EM.run do
|
256
|
-
EM.next_tick do
|
257
|
-
write.puts "EM ran"
|
258
|
-
EM.stop
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
EM.stop
|
263
|
-
end
|
264
|
-
assert_equal "forked\n", read.readline
|
265
|
-
assert_equal "EM ran\n", read.readline
|
266
|
-
ensure
|
267
|
-
read.close rescue nil
|
268
|
-
write.close rescue nil
|
269
|
-
end
|
270
|
-
|
271
262
|
def test_error_handler_idempotent # issue 185
|
272
263
|
errors = []
|
273
264
|
ticks = []
|
data/tests/test_channel.rb
CHANGED
@@ -59,4 +59,17 @@ class TestEMChannel < Test::Unit::TestCase
|
|
59
59
|
|
60
60
|
assert_equal [1,2,3], out
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
def test_channel_num_subscribers
|
64
|
+
subs = 0
|
65
|
+
EM.run do
|
66
|
+
c = EM::Channel.new
|
67
|
+
c.subscribe { |v| s = v }
|
68
|
+
c.subscribe { |v| s = v }
|
69
|
+
EM.next_tick { EM.stop }
|
70
|
+
subs = c.num_subscribers
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_equal subs, 2
|
74
|
+
end
|
75
|
+
end
|
data/tests/test_defer.rb
CHANGED
@@ -15,4 +15,21 @@ class TestDefer < Test::Unit::TestCase
|
|
15
15
|
assert_equal( n, n_times )
|
16
16
|
end
|
17
17
|
|
18
|
+
def test_errbacks
|
19
|
+
iterations = 20
|
20
|
+
callback_parameter = rand(100)
|
21
|
+
callback_parameters = []
|
22
|
+
callback_op = proc { callback_parameter }
|
23
|
+
callback = proc { |result| callback_parameters << result }
|
24
|
+
errback_parameter = Exception.new
|
25
|
+
errback_parameters = []
|
26
|
+
errback_op = proc { raise errback_parameter }
|
27
|
+
errback = proc { |error| errback_parameters << error }
|
28
|
+
EventMachine.run do
|
29
|
+
(1..iterations).each { |index| EventMachine.defer(index.even? ? callback_op : errback_op, callback, errback) }
|
30
|
+
EventMachine.add_periodic_timer(0.1) { EventMachine.stop if EventMachine.defers_finished? }
|
31
|
+
end
|
32
|
+
assert_equal(callback_parameters.select { |parameter| parameter == callback_parameter }.length, iterations * 0.5)
|
33
|
+
assert_equal(errback_parameters.select{ |parameter| parameter == errback_parameter }.length, iterations * 0.5)
|
34
|
+
end
|
18
35
|
end
|
data/tests/test_epoll.rb
CHANGED
data/tests/test_fork.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestFork < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_fork_safe
|
6
|
+
omit_if(jruby?)
|
7
|
+
omit_if(windows?)
|
8
|
+
|
9
|
+
fork_pid = nil
|
10
|
+
read, write = IO.pipe
|
11
|
+
EM.run do
|
12
|
+
fork_pid = fork do
|
13
|
+
write.puts "forked"
|
14
|
+
EM.run do
|
15
|
+
EM.next_tick do
|
16
|
+
write.puts "EM ran"
|
17
|
+
EM.stop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
EM.stop
|
22
|
+
end
|
23
|
+
|
24
|
+
sleep 0.1
|
25
|
+
begin
|
26
|
+
Timeout::timeout 1 do
|
27
|
+
assert_equal "forked\n", read.readline
|
28
|
+
assert_equal "EM ran\n", read.readline
|
29
|
+
end
|
30
|
+
rescue Timeout::Error
|
31
|
+
Process.kill 'TERM', fork_pid
|
32
|
+
flunk "Timeout waiting for next_tick in new fork reactor"
|
33
|
+
end
|
34
|
+
ensure
|
35
|
+
read.close rescue nil
|
36
|
+
write.close rescue nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fork_reactor
|
40
|
+
omit_if(jruby?)
|
41
|
+
omit_if(windows?)
|
42
|
+
|
43
|
+
fork_pid = nil
|
44
|
+
read, write = IO.pipe
|
45
|
+
EM.run do
|
46
|
+
EM.defer do
|
47
|
+
write.puts Process.pid
|
48
|
+
EM.defer do
|
49
|
+
EM.stop
|
50
|
+
end
|
51
|
+
end
|
52
|
+
fork_pid = EM.fork_reactor do
|
53
|
+
EM.defer do
|
54
|
+
write.puts Process.pid
|
55
|
+
EM.stop
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
sleep 0.1
|
61
|
+
begin
|
62
|
+
Timeout::timeout 1 do
|
63
|
+
assert_equal Process.pid.to_s, read.readline.chomp
|
64
|
+
assert_equal fork_pid.to_s, read.readline.chomp
|
65
|
+
end
|
66
|
+
rescue Timeout::Error
|
67
|
+
Process.kill 'TERM', fork_pid
|
68
|
+
flunk "Timeout waiting for deferred block in fork_reactor"
|
69
|
+
end
|
70
|
+
ensure
|
71
|
+
read.close rescue nil
|
72
|
+
write.close rescue nil
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/tests/test_ipv4.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
class TestIPv4 < Test::Unit::TestCase
|
5
|
+
|
6
|
+
if Test::Unit::TestCase.public_ipv4?
|
7
|
+
|
8
|
+
# Tries to connect to www.google.com port 80 via TCP.
|
9
|
+
# Timeout in 2 seconds.
|
10
|
+
def test_ipv4_tcp_client
|
11
|
+
conn = nil
|
12
|
+
setup_timeout(2)
|
13
|
+
|
14
|
+
EM.run do
|
15
|
+
conn = EM::connect("www.google.com", 80) do |c|
|
16
|
+
def c.connected
|
17
|
+
@connected
|
18
|
+
end
|
19
|
+
|
20
|
+
def c.connection_completed
|
21
|
+
@connected = true
|
22
|
+
EM.stop
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert conn.connected
|
28
|
+
end
|
29
|
+
|
30
|
+
# Runs a TCP server in the local IPv4 address, connects to it and sends a specific data.
|
31
|
+
# Timeout in 2 seconds.
|
32
|
+
def test_ipv4_tcp_local_server
|
33
|
+
@@received_data = nil
|
34
|
+
@local_port = next_port
|
35
|
+
setup_timeout(2)
|
36
|
+
|
37
|
+
EM.run do
|
38
|
+
EM::start_server(@@public_ipv4, @local_port) do |s|
|
39
|
+
def s.receive_data data
|
40
|
+
@@received_data = data
|
41
|
+
EM.stop
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
EM::connect(@@public_ipv4, @local_port) do |c|
|
46
|
+
c.send_data "ipv4/tcp"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal "ipv4/tcp", @@received_data
|
51
|
+
end
|
52
|
+
|
53
|
+
# Runs a UDP server in the local IPv4 address, connects to it and sends a specific data.
|
54
|
+
# Timeout in 2 seconds.
|
55
|
+
def test_ipv4_udp_local_server
|
56
|
+
@@received_data = nil
|
57
|
+
@local_port = next_port
|
58
|
+
setup_timeout(2)
|
59
|
+
|
60
|
+
EM.run do
|
61
|
+
EM::open_datagram_socket(@@public_ipv4, @local_port) do |s|
|
62
|
+
def s.receive_data data
|
63
|
+
@@received_data = data
|
64
|
+
EM.stop
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
EM::open_datagram_socket(@@public_ipv4, next_port) do |c|
|
69
|
+
c.send_datagram "ipv4/udp", @@public_ipv4, @local_port
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_equal "ipv4/udp", @@received_data
|
74
|
+
end
|
75
|
+
|
76
|
+
# Try to connect via TCP to an invalid IPv4. EM.connect should raise
|
77
|
+
# EM::ConnectionError.
|
78
|
+
def test_tcp_connect_to_invalid_ipv4
|
79
|
+
invalid_ipv4 = "9.9:9"
|
80
|
+
|
81
|
+
EM.run do
|
82
|
+
begin
|
83
|
+
error = nil
|
84
|
+
EM.connect(invalid_ipv4, 1234)
|
85
|
+
rescue => e
|
86
|
+
error = e
|
87
|
+
ensure
|
88
|
+
EM.stop
|
89
|
+
assert_equal EM::ConnectionError, (error && error.class)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Try to send a UDP datagram to an invalid IPv4. EM.send_datagram should raise
|
95
|
+
# EM::ConnectionError.
|
96
|
+
def test_udp_send_datagram_to_invalid_ipv4
|
97
|
+
invalid_ipv4 = "9.9:9"
|
98
|
+
|
99
|
+
EM.run do
|
100
|
+
begin
|
101
|
+
error = nil
|
102
|
+
EM.open_datagram_socket(@@public_ipv4, next_port) do |c|
|
103
|
+
c.send_datagram "hello", invalid_ipv4, 1234
|
104
|
+
end
|
105
|
+
rescue => e
|
106
|
+
error = e
|
107
|
+
ensure
|
108
|
+
EM.stop
|
109
|
+
assert_equal EM::ConnectionError, (error && error.class)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
else
|
116
|
+
warn "no IPv4 in this host, skipping tests in #{__FILE__}"
|
117
|
+
|
118
|
+
# Because some rubies will complain if a TestCase class has no tests
|
119
|
+
def test_ipv4_unavailable
|
120
|
+
assert true
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
data/tests/test_ipv6.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestIPv6 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
if Test::Unit::TestCase.public_ipv6?
|
6
|
+
|
7
|
+
# Tries to connect to ipv6.google.com (2607:f8b0:4010:800::1006) port 80 via TCP.
|
8
|
+
# Timeout in 6 seconds.
|
9
|
+
def test_ipv6_tcp_client_with_ipv6_google_com
|
10
|
+
conn = nil
|
11
|
+
setup_timeout(6)
|
12
|
+
|
13
|
+
EM.run do
|
14
|
+
conn = EM::connect("2607:f8b0:4010:800::1006", 80) do |c|
|
15
|
+
def c.connected
|
16
|
+
@connected
|
17
|
+
end
|
18
|
+
|
19
|
+
def c.unbind(reason)
|
20
|
+
warn "unbind: #{reason.inspect}" if reason # XXX at least find out why it failed
|
21
|
+
end
|
22
|
+
|
23
|
+
def c.connection_completed
|
24
|
+
@connected = true
|
25
|
+
EM.stop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
assert conn.connected
|
31
|
+
end
|
32
|
+
|
33
|
+
# Runs a TCP server in the local IPv6 address, connects to it and sends a specific data.
|
34
|
+
# Timeout in 2 seconds.
|
35
|
+
def test_ipv6_tcp_local_server
|
36
|
+
@@received_data = nil
|
37
|
+
@local_port = next_port
|
38
|
+
setup_timeout(2)
|
39
|
+
|
40
|
+
EM.run do
|
41
|
+
EM.start_server(@@public_ipv6, @local_port) do |s|
|
42
|
+
def s.receive_data data
|
43
|
+
@@received_data = data
|
44
|
+
EM.stop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
EM::connect(@@public_ipv6, @local_port) do |c|
|
49
|
+
def c.unbind(reason)
|
50
|
+
warn "unbind: #{reason.inspect}" if reason # XXX at least find out why it failed
|
51
|
+
end
|
52
|
+
c.send_data "ipv6/tcp"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_equal "ipv6/tcp", @@received_data
|
57
|
+
end
|
58
|
+
|
59
|
+
# Runs a UDP server in the local IPv6 address, connects to it and sends a specific data.
|
60
|
+
# Timeout in 2 seconds.
|
61
|
+
def test_ipv6_udp_local_server
|
62
|
+
@@received_data = nil
|
63
|
+
@local_port = next_port
|
64
|
+
setup_timeout(2)
|
65
|
+
|
66
|
+
EM.run do
|
67
|
+
EM.open_datagram_socket(@@public_ipv6, @local_port) do |s|
|
68
|
+
def s.receive_data data
|
69
|
+
@@received_data = data
|
70
|
+
EM.stop
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
EM.open_datagram_socket(@@public_ipv6, next_port) do |c|
|
75
|
+
c.send_datagram "ipv6/udp", @@public_ipv6, @local_port
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_equal "ipv6/udp", @@received_data
|
80
|
+
end
|
81
|
+
|
82
|
+
# Try to connect via TCP to an invalid IPv6. EM.connect should raise
|
83
|
+
# EM::ConnectionError.
|
84
|
+
def test_tcp_connect_to_invalid_ipv6
|
85
|
+
invalid_ipv6 = "1:A"
|
86
|
+
|
87
|
+
EM.run do
|
88
|
+
begin
|
89
|
+
error = nil
|
90
|
+
EM.connect(invalid_ipv6, 1234)
|
91
|
+
rescue => e
|
92
|
+
error = e
|
93
|
+
ensure
|
94
|
+
EM.stop
|
95
|
+
assert_equal EM::ConnectionError, (error && error.class)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Try to send a UDP datagram to an invalid IPv6. EM.send_datagram should raise
|
101
|
+
# EM::ConnectionError.
|
102
|
+
def test_udp_send_datagram_to_invalid_ipv6
|
103
|
+
invalid_ipv6 = "1:A"
|
104
|
+
|
105
|
+
EM.run do
|
106
|
+
begin
|
107
|
+
error = nil
|
108
|
+
EM.open_datagram_socket(@@public_ipv6, next_port) do |c|
|
109
|
+
c.send_datagram "hello", invalid_ipv6, 1234
|
110
|
+
end
|
111
|
+
rescue => e
|
112
|
+
error = e
|
113
|
+
ensure
|
114
|
+
EM.stop
|
115
|
+
assert_equal EM::ConnectionError, (error && error.class)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
else
|
122
|
+
warn "no IPv6 in this host, skipping tests in #{__FILE__}"
|
123
|
+
|
124
|
+
# Because some rubies will complain if a TestCase class has no tests.
|
125
|
+
def test_ipv6_unavailable
|
126
|
+
assert true
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|