eventmachine-le 1.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.yardopts +7 -0
- data/GNU +281 -0
- data/LICENSE +60 -0
- data/README.md +80 -0
- data/Rakefile +19 -0
- data/eventmachine-le.gemspec +42 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +46 -0
- data/ext/cmain.cpp +841 -0
- data/ext/ed.cpp +1995 -0
- data/ext/ed.h +424 -0
- data/ext/em.cpp +2377 -0
- data/ext/em.h +243 -0
- data/ext/eventmachine.h +126 -0
- data/ext/extconf.rb +166 -0
- data/ext/fastfilereader/extconf.rb +94 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +347 -0
- data/ext/project.h +155 -0
- data/ext/rubymain.cpp +1269 -0
- data/ext/ssl.cpp +468 -0
- data/ext/ssl.h +94 -0
- data/lib/em/buftok.rb +110 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +64 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +728 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +313 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +279 -0
- data/lib/em/protocols/httpclient2.rb +600 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/linetext2.rb +161 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +365 -0
- data/lib/em/protocols/smtpserver.rb +663 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +202 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/queue.rb +71 -0
- data/lib/em/resolver.rb +195 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +106 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine-le.rb +10 -0
- data/lib/eventmachine.rb +1548 -0
- data/rakelib/cpp.rake_example +77 -0
- data/rakelib/package.rake +98 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/em_test_helper.rb +143 -0
- data/tests/test_attach.rb +148 -0
- data/tests/test_basic.rb +294 -0
- data/tests/test_channel.rb +62 -0
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +33 -0
- data/tests/test_defer.rb +18 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +134 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +65 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_get_sock_opt.rb +37 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +190 -0
- data/tests/test_httpclient2.rb +128 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_ipv4.rb +125 -0
- data/tests/test_ipv6.rb +131 -0
- data/tests/test_iterator.rb +110 -0
- data/tests/test_kb.rb +34 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +288 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +78 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +196 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +133 -0
- data/tests/test_proxy_connection.rb +168 -0
- data/tests/test_pure.rb +88 -0
- data/tests/test_queue.rb +50 -0
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +47 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +33 -0
- data/tests/test_set_sock_opt.rb +41 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +55 -0
- data/tests/test_smtpserver.rb +120 -0
- data/tests/test_spawn.rb +293 -0
- data/tests/test_ssl_args.rb +78 -0
- data/tests/test_ssl_methods.rb +48 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_threaded_resource.rb +55 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +180 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_udp46.rb +53 -0
- data/tests/test_unbind_reason.rb +48 -0
- metadata +390 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestSSLMethods < Test::Unit::TestCase
|
4
|
+
|
5
|
+
module ServerHandler
|
6
|
+
|
7
|
+
def post_init
|
8
|
+
start_tls
|
9
|
+
end
|
10
|
+
|
11
|
+
def ssl_handshake_completed
|
12
|
+
$server_called_back = true
|
13
|
+
$server_cert_value = get_peer_cert
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClientHandler
|
19
|
+
|
20
|
+
def post_init
|
21
|
+
start_tls
|
22
|
+
end
|
23
|
+
|
24
|
+
def ssl_handshake_completed
|
25
|
+
$client_called_back = true
|
26
|
+
$client_cert_value = get_peer_cert
|
27
|
+
EM.stop_event_loop
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_ssl_methods
|
33
|
+
$server_called_back, $client_called_back = false, false
|
34
|
+
$server_cert_value, $client_cert_value = nil, nil
|
35
|
+
|
36
|
+
EM.run {
|
37
|
+
EM.start_server("127.0.0.1", 9999, ServerHandler)
|
38
|
+
EM.connect("127.0.0.1", 9999, ClientHandler)
|
39
|
+
}
|
40
|
+
|
41
|
+
assert($server_called_back)
|
42
|
+
assert($client_called_back)
|
43
|
+
|
44
|
+
assert($server_cert_value.is_a?(NilClass))
|
45
|
+
assert($client_cert_value.is_a?(String))
|
46
|
+
end
|
47
|
+
|
48
|
+
end if EM.ssl?
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
if EM.ssl?
|
4
|
+
class TestSslVerify < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
$dir = File.dirname(File.expand_path(__FILE__)) + '/'
|
7
|
+
$cert_from_file = File.read($dir+'client.crt')
|
8
|
+
end
|
9
|
+
|
10
|
+
module Client
|
11
|
+
def connection_completed
|
12
|
+
start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
|
13
|
+
end
|
14
|
+
|
15
|
+
def ssl_handshake_completed
|
16
|
+
$client_handshake_completed = true
|
17
|
+
close_connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def unbind
|
21
|
+
EM.stop_event_loop
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module AcceptServer
|
26
|
+
def post_init
|
27
|
+
start_tls(:verify_peer => true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def ssl_verify_peer(cert)
|
31
|
+
$cert_from_server = cert
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def ssl_handshake_completed
|
36
|
+
$server_handshake_completed = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module DenyServer
|
41
|
+
def post_init
|
42
|
+
start_tls(:verify_peer => true)
|
43
|
+
end
|
44
|
+
|
45
|
+
def ssl_verify_peer(cert)
|
46
|
+
$cert_from_server = cert
|
47
|
+
# Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def ssl_handshake_completed
|
52
|
+
$server_handshake_completed = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_accept_server
|
57
|
+
$client_handshake_completed, $server_handshake_completed = false, false
|
58
|
+
EM.run {
|
59
|
+
EM.start_server("127.0.0.1", 16784, AcceptServer)
|
60
|
+
EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
|
61
|
+
}
|
62
|
+
|
63
|
+
assert_equal($cert_from_file, $cert_from_server)
|
64
|
+
assert($client_handshake_completed)
|
65
|
+
assert($server_handshake_completed)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_deny_server
|
69
|
+
$client_handshake_completed, $server_handshake_completed = false, false
|
70
|
+
EM.run {
|
71
|
+
EM.start_server("127.0.0.1", 16784, DenyServer)
|
72
|
+
EM.connect("127.0.0.1", 16784, Client)
|
73
|
+
}
|
74
|
+
|
75
|
+
assert_equal($cert_from_file, $cert_from_server)
|
76
|
+
assert(!$client_handshake_completed)
|
77
|
+
assert(!$server_handshake_completed)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
else
|
81
|
+
warn "EM built without SSL support, skipping tests in #{__FILE__}"
|
82
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestThreadedResource < Test::Unit::TestCase
|
4
|
+
def object
|
5
|
+
@object ||= {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def resource
|
9
|
+
@resource = EM::ThreadedResource.new do
|
10
|
+
object
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
resource.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_dispatch_completion
|
19
|
+
EM.run do
|
20
|
+
completion = resource.dispatch do |o|
|
21
|
+
o[:foo] = :bar
|
22
|
+
:foo
|
23
|
+
end
|
24
|
+
completion.callback do |result|
|
25
|
+
assert_equal :foo, result
|
26
|
+
EM.stop
|
27
|
+
end
|
28
|
+
end
|
29
|
+
assert_equal :bar, object[:foo]
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_dispatch_failure
|
33
|
+
completion = resource.dispatch do |o|
|
34
|
+
raise 'boom'
|
35
|
+
end
|
36
|
+
completion.errback do |error|
|
37
|
+
assert_kind_of RuntimeError, error
|
38
|
+
assert_equal 'boom', error.message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_dispatch_threading
|
43
|
+
main = Thread.current
|
44
|
+
resource.dispatch do |o|
|
45
|
+
o[:dispatch_thread] = Thread.current
|
46
|
+
end
|
47
|
+
assert_not_equal main, object[:dispatch_thread]
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_shutdown
|
51
|
+
# This test should get improved sometime. The method returning thread is
|
52
|
+
# NOT an api that will be maintained.
|
53
|
+
assert !resource.shutdown.alive?
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'em_test_helper'
|
3
|
+
|
4
|
+
class TestEmTickLoop < Test::Unit::TestCase
|
5
|
+
def test_em_tick_loop
|
6
|
+
i = 0
|
7
|
+
EM.tick_loop { i += 1; EM.stop if i == 10 }
|
8
|
+
EM.run { EM.add_timer(1) { EM.stop } }
|
9
|
+
assert_equal i, 10
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_tick_loop_on_stop
|
13
|
+
t = nil
|
14
|
+
tick_loop = EM.tick_loop { :stop }
|
15
|
+
tick_loop.on_stop { t = true }
|
16
|
+
EM.run { EM.next_tick { EM.stop } }
|
17
|
+
assert t
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_start_twice
|
21
|
+
i = 0
|
22
|
+
s = 0
|
23
|
+
tick_loop = EM.tick_loop { i += 1; :stop }
|
24
|
+
tick_loop.on_stop { s += 1; EM.stop }
|
25
|
+
EM.run { EM.next_tick { EM.stop } }
|
26
|
+
assert_equal 1, i
|
27
|
+
assert_equal 1, s
|
28
|
+
tick_loop.start
|
29
|
+
EM.run { EM.next_tick { EM.stop } }
|
30
|
+
assert_equal 2, i
|
31
|
+
assert_equal 1, s # stop callbacks are only called once
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_stop
|
35
|
+
i, s = 0, 0
|
36
|
+
tick_loop = EM.tick_loop { i += 1 }
|
37
|
+
tick_loop.on_stop { s += 1 }
|
38
|
+
EM.run { EM.next_tick { tick_loop.stop; EM.next_tick { EM.stop } } }
|
39
|
+
assert tick_loop.stopped?
|
40
|
+
assert_equal 1, i
|
41
|
+
assert_equal 1, s
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_immediate_stops
|
45
|
+
s = 0
|
46
|
+
tick_loop = EM::TickLoop.new { }
|
47
|
+
tick_loop.on_stop { s += 1 }
|
48
|
+
tick_loop.on_stop { s += 1 }
|
49
|
+
assert_equal 2, s
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_stopped
|
53
|
+
tick_loop = EM::TickLoop.new { }
|
54
|
+
assert tick_loop.stopped?
|
55
|
+
tick_loop.start
|
56
|
+
assert !tick_loop.stopped?
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestTimers < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_timer_with_block
|
6
|
+
x = false
|
7
|
+
EM.run {
|
8
|
+
EM::Timer.new(0) {
|
9
|
+
x = true
|
10
|
+
EM.stop
|
11
|
+
}
|
12
|
+
}
|
13
|
+
assert x
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_timer_with_proc
|
17
|
+
x = false
|
18
|
+
EM.run {
|
19
|
+
EM::Timer.new(0, proc {
|
20
|
+
x = true
|
21
|
+
EM.stop
|
22
|
+
})
|
23
|
+
}
|
24
|
+
assert x
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_timer_cancel
|
28
|
+
assert_nothing_raised do
|
29
|
+
EM.run {
|
30
|
+
timer = EM::Timer.new(0.01) { flunk "Timer was not cancelled." }
|
31
|
+
timer.cancel
|
32
|
+
|
33
|
+
EM.add_timer(0.02) { EM.stop }
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_periodic_timer
|
39
|
+
x = 0
|
40
|
+
EM.run {
|
41
|
+
EM::PeriodicTimer.new(0.01) do
|
42
|
+
x += 1
|
43
|
+
EM.stop if x == 4
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
assert_equal 4, x
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_periodic_timer
|
51
|
+
x = 0
|
52
|
+
EM.run {
|
53
|
+
t = EM.add_periodic_timer(0.01) do
|
54
|
+
x += 1
|
55
|
+
EM.stop if x == 4
|
56
|
+
end
|
57
|
+
assert t.respond_to?(:cancel)
|
58
|
+
}
|
59
|
+
assert_equal 4, x
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_periodic_timer_cancel
|
63
|
+
x = 0
|
64
|
+
EM.run {
|
65
|
+
pt = EM::PeriodicTimer.new(0.01) { x += 1 }
|
66
|
+
pt.cancel
|
67
|
+
EM::Timer.new(0.02) { EM.stop }
|
68
|
+
}
|
69
|
+
assert_equal 0, x
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_add_periodic_timer_cancel
|
73
|
+
x = 0
|
74
|
+
EM.run {
|
75
|
+
pt = EM.add_periodic_timer(0.01) { x += 1 }
|
76
|
+
EM.cancel_timer(pt)
|
77
|
+
EM.add_timer(0.02) { EM.stop }
|
78
|
+
}
|
79
|
+
assert_equal 0, x
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_periodic_timer_self_cancel
|
83
|
+
x = 0
|
84
|
+
EM.run {
|
85
|
+
pt = EM::PeriodicTimer.new(0) {
|
86
|
+
x += 1
|
87
|
+
if x == 4
|
88
|
+
pt.cancel
|
89
|
+
EM.stop
|
90
|
+
end
|
91
|
+
}
|
92
|
+
}
|
93
|
+
assert_equal 4, x
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_restartable_timer
|
97
|
+
x = false
|
98
|
+
EventMachine.run {
|
99
|
+
EventMachine::RestartableTimer.new(0.1) do
|
100
|
+
x = true
|
101
|
+
EventMachine.stop
|
102
|
+
end
|
103
|
+
}
|
104
|
+
assert x
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_add_restartable_timer
|
108
|
+
x = false
|
109
|
+
EventMachine.run {
|
110
|
+
rt = EventMachine.add_restartable_timer(0.1) { x = true }
|
111
|
+
assert rt.respond_to?(:restart)
|
112
|
+
EventMachine.stop
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_restart_restartable_timer
|
117
|
+
x = false
|
118
|
+
EventMachine.run {
|
119
|
+
EventMachine.add_timer(0.4) { x = 1 }
|
120
|
+
rt = EventMachine::RestartableTimer.new(0.3) do
|
121
|
+
x = true
|
122
|
+
end
|
123
|
+
EventMachine.add_timer(0.2) { rt.restart }
|
124
|
+
EventMachine.add_timer(0.6) { EventMachine.stop }
|
125
|
+
}
|
126
|
+
assert x == true
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_cannot_restart_already_fired_restartable_timer
|
130
|
+
x = false
|
131
|
+
EventMachine.run {
|
132
|
+
rt = EventMachine::RestartableTimer.new(0.1) do
|
133
|
+
x = true
|
134
|
+
end
|
135
|
+
EventMachine.add_timer(0.2) {
|
136
|
+
x = false
|
137
|
+
rt.restart
|
138
|
+
}
|
139
|
+
EventMachine.add_timer(0.4) { EventMachine.stop }
|
140
|
+
}
|
141
|
+
assert !x
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_restartable_timer_cancel
|
145
|
+
x = false
|
146
|
+
EventMachine.run {
|
147
|
+
rt = EventMachine::RestartableTimer.new(0.3) { x = true }
|
148
|
+
rt.cancel
|
149
|
+
EventMachine::Timer.new(0.1) { EventMachine.stop }
|
150
|
+
}
|
151
|
+
assert !x
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_add_restartable_timer_cancel
|
155
|
+
x = false
|
156
|
+
EventMachine.run {
|
157
|
+
rt = EventMachine.add_restartable_timer(0.2) { x = true }
|
158
|
+
EventMachine.cancel_timer(rt)
|
159
|
+
EventMachine.add_timer(0.3) { EventMachine.stop }
|
160
|
+
}
|
161
|
+
assert !x
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_cannot_restart_cancelled_restartable_timer
|
165
|
+
x = false
|
166
|
+
EventMachine.run {
|
167
|
+
rt = EventMachine::RestartableTimer.new(0.2) do
|
168
|
+
x = true
|
169
|
+
end
|
170
|
+
rt.cancel
|
171
|
+
EventMachine.add_timer(0.1) {
|
172
|
+
x = false
|
173
|
+
rt.restart
|
174
|
+
}
|
175
|
+
EventMachine.add_timer(0.4) { EventMachine.stop }
|
176
|
+
}
|
177
|
+
assert !x
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
data/tests/test_ud.rb
ADDED
data/tests/test_udp46.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestUDP46 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# this is a bit brittle. Maybe do not test for the actual error...
|
6
|
+
WANT_ALL = [
|
7
|
+
( RUBY_PLATFORM =~ /darwin1/ and # not an error in Linux (!?),
|
8
|
+
# strange handling in OSX 10.5.x (darwin9)
|
9
|
+
["::1", "::241.1.2.3", 5555, Errno::EHOSTUNREACH]),
|
10
|
+
["::1", "241.2.3.4", 5555,
|
11
|
+
(RUBY_PLATFORM =~ /linux/ ? Errno::ENETUNREACH : Errno::EINVAL)],
|
12
|
+
["127.0.0.1", "241.4.5.6", 5555,
|
13
|
+
(RUBY_PLATFORM =~ /linux/ ? Errno::EINVAL : Errno::ENETUNREACH)]
|
14
|
+
].compact
|
15
|
+
|
16
|
+
# Open a UDP socket listening on, say, ::1, and try to send a UDP
|
17
|
+
# datagram to IP address, say, ::241.1.2.3 (so no network route).
|
18
|
+
# Without the error handling fix, it makes EM close the UDP socket.
|
19
|
+
def test_udp_no_route
|
20
|
+
WANT_ALL.each do |want|
|
21
|
+
@@udp_socket_alive = false
|
22
|
+
@@udp_socket_unbind_cause = nil
|
23
|
+
@@error_came_in = false
|
24
|
+
|
25
|
+
EM.run do
|
26
|
+
|
27
|
+
EM::open_datagram_socket(want[0], next_port, EM::Connection) do |c|
|
28
|
+
c.send_error_handling = :ERRORHANDLING_REPORT
|
29
|
+
|
30
|
+
def c.unbind cause=nil
|
31
|
+
@@udp_socket_unbind_cause = cause
|
32
|
+
EM.stop
|
33
|
+
end
|
34
|
+
|
35
|
+
def c.receive_senderror(error, data)
|
36
|
+
@@error_came_in = [error, data]
|
37
|
+
end
|
38
|
+
|
39
|
+
c.send_datagram "no-route", want[1], want[2]
|
40
|
+
EM.add_timer(0.2) do
|
41
|
+
@@udp_socket_alive = true unless c.error?
|
42
|
+
EM.stop
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
assert @@udp_socket_alive, "UDP socket was killed (unbind cause: #{@@udp_socket_unbind_cause})"
|
49
|
+
assert_equal [want[3], [want[1], want[2].to_s]], @@error_came_in
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|