eventmachine 0.12.6-java → 0.12.8-java
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 +5 -3
- 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 +17 -8
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/helper.rb +2 -0
- data/ext/cmain.cpp +119 -20
- data/ext/cplusplus.cpp +15 -6
- data/ext/ed.cpp +303 -93
- data/ext/ed.h +49 -22
- data/ext/em.cpp +368 -42
- data/ext/em.h +43 -6
- data/ext/eventmachine.h +21 -8
- data/ext/eventmachine_cpp.h +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/kb.cpp +1 -2
- data/ext/pipe.cpp +1 -3
- data/ext/project.h +21 -0
- data/ext/rubymain.cpp +232 -32
- 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 +58 -52
- 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 +1008 -1298
- 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 +108 -54
- data/tests/test_channel.rb +63 -0
- data/tests/test_connection_count.rb +2 -2
- data/tests/test_epoll.rb +109 -110
- 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 +110 -112
- 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 +91 -65
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +56 -23
- 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_httpclient2.rb
CHANGED
@@ -29,127 +29,125 @@ require 'eventmachine'
|
|
29
29
|
require 'test/unit'
|
30
30
|
|
31
31
|
class TestHttpClient2 < Test::Unit::TestCase
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
EM.run {
|
52
|
-
EM.start_server Localhost, Localport, TestServer
|
53
|
-
http1 = EM::P::HttpClient2.connect Localhost, Localport
|
54
|
-
http2 = EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
|
55
|
-
EM.stop
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
def test_bad_port
|
61
|
-
EM.run {
|
62
|
-
EM.start_server Localhost, Localport, TestServer
|
63
|
-
assert_raises( ArgumentError ) {
|
64
|
-
EM::P::HttpClient2.connect Localhost, "xxx"
|
65
|
-
}
|
66
|
-
EM.stop
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_bad_server
|
71
|
-
err = nil
|
72
|
-
EM.run {
|
73
|
-
http = EM::P::HttpClient2.connect Localhost, 9999
|
74
|
-
d = http.get "/"
|
75
|
-
d.errback { err = true; d.internal_error; EM.stop }
|
76
|
-
}
|
77
|
-
assert(err)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_get
|
81
|
-
content = nil
|
82
|
-
EM.run {
|
83
|
-
http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
|
84
|
-
d = http.get "/"
|
85
|
-
d.callback {
|
86
|
-
content = d.content
|
87
|
-
EM.stop
|
88
|
-
}
|
89
|
-
}
|
90
|
-
assert(content)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Not a pipelined request because we wait for one response before we request the next.
|
94
|
-
def test_get_multiple
|
95
|
-
content = nil
|
96
|
-
EM.run {
|
97
|
-
http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
|
98
|
-
d = http.get "/"
|
99
|
-
d.callback {
|
100
|
-
e = http.get "/"
|
101
|
-
e.callback {
|
102
|
-
content = e.content
|
103
|
-
EM.stop
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
assert(content)
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_get_pipeline
|
111
|
-
headers, headers2 = nil, nil
|
112
|
-
EM.run {
|
113
|
-
http = EM::P::HttpClient2.connect "www.microsoft.com", 80
|
114
|
-
d = http.get("/")
|
115
|
-
d.callback {
|
116
|
-
headers = d.headers
|
117
|
-
}
|
118
|
-
e = http.get("/")
|
119
|
-
e.callback {
|
120
|
-
headers2 = e.headers
|
121
|
-
}
|
122
|
-
EM::Timer.new(1) {EM.stop}
|
123
|
-
}
|
124
|
-
assert(headers)
|
125
|
-
assert(headers2)
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
def test_authheader
|
130
|
-
EM.run {
|
131
|
-
EM.start_server Localhost, Localport, TestServer
|
132
|
-
http = EM::P::HttpClient2.connect Localhost, 18842
|
133
|
-
d = http.get :url=>"/", :authorization=>"Basic xxx"
|
134
|
-
d.callback {EM.stop}
|
135
|
-
d.errback {EM.stop}
|
136
|
-
}
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_https_get
|
140
|
-
d = nil
|
32
|
+
Localhost = "127.0.0.1"
|
33
|
+
Localport = 9801
|
34
|
+
|
35
|
+
def setup
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
class TestServer < EM::Connection
|
43
|
+
end
|
44
|
+
|
45
|
+
# #connect returns an object which has made a connection to an HTTP server
|
46
|
+
# and exposes methods for making HTTP requests on that connection.
|
47
|
+
# #connect can take either a pair of parameters (a host and a port),
|
48
|
+
# or a single parameter which is a Hash.
|
49
|
+
#
|
50
|
+
def test_connect
|
141
51
|
EM.run {
|
142
|
-
|
52
|
+
EM.start_server Localhost, Localport, TestServer
|
53
|
+
http1 = EM::P::HttpClient2.connect Localhost, Localport
|
54
|
+
http2 = EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
|
55
|
+
EM.stop
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def test_bad_port
|
61
|
+
EM.run {
|
62
|
+
EM.start_server Localhost, Localport, TestServer
|
63
|
+
assert_raises( ArgumentError ) {
|
64
|
+
EM::P::HttpClient2.connect Localhost, "xxx"
|
65
|
+
}
|
66
|
+
EM.stop
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_bad_server
|
71
|
+
err = nil
|
72
|
+
EM.run {
|
73
|
+
http = EM::P::HttpClient2.connect Localhost, 9999
|
74
|
+
d = http.get "/"
|
75
|
+
d.errback { err = true; d.internal_error; EM.stop }
|
76
|
+
}
|
77
|
+
assert(err)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_get
|
81
|
+
content = nil
|
82
|
+
EM.run {
|
83
|
+
http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
|
143
84
|
d = http.get "/"
|
144
85
|
d.callback {
|
86
|
+
content = d.content
|
145
87
|
EM.stop
|
146
88
|
}
|
147
89
|
}
|
148
|
-
|
90
|
+
assert(content)
|
149
91
|
end
|
150
92
|
|
93
|
+
# Not a pipelined request because we wait for one response before we request the next.
|
94
|
+
# XXX this test is broken because it sends the second request to the first connection
|
95
|
+
# XXX right before the connection closes
|
96
|
+
def _test_get_multiple
|
97
|
+
content = nil
|
98
|
+
EM.run {
|
99
|
+
http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
|
100
|
+
d = http.get "/"
|
101
|
+
d.callback {
|
102
|
+
e = http.get "/"
|
103
|
+
e.callback {
|
104
|
+
content = e.content
|
105
|
+
EM.stop
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
assert(content)
|
110
|
+
end
|
151
111
|
|
112
|
+
def test_get_pipeline
|
113
|
+
headers, headers2 = nil, nil
|
114
|
+
EM.run {
|
115
|
+
http = EM::P::HttpClient2.connect "www.microsoft.com", 80
|
116
|
+
d = http.get("/")
|
117
|
+
d.callback {
|
118
|
+
headers = d.headers
|
119
|
+
}
|
120
|
+
e = http.get("/")
|
121
|
+
e.callback {
|
122
|
+
headers2 = e.headers
|
123
|
+
}
|
124
|
+
EM::Timer.new(1) {EM.stop}
|
125
|
+
}
|
126
|
+
assert(headers)
|
127
|
+
assert(headers2)
|
128
|
+
end
|
152
129
|
|
153
|
-
end
|
154
130
|
|
131
|
+
def test_authheader
|
132
|
+
EM.run {
|
133
|
+
EM.start_server Localhost, Localport, TestServer
|
134
|
+
http = EM::P::HttpClient2.connect Localhost, 18842
|
135
|
+
d = http.get :url=>"/", :authorization=>"Basic xxx"
|
136
|
+
d.callback {EM.stop}
|
137
|
+
d.errback {EM.stop}
|
138
|
+
}
|
139
|
+
end
|
155
140
|
|
141
|
+
def test_https_get
|
142
|
+
d = nil
|
143
|
+
EM.run {
|
144
|
+
http = EM::P::HttpClient2.connect :host => 'www.amazon.com', :port => 443, :ssl => true
|
145
|
+
d = http.get "/"
|
146
|
+
d.callback {
|
147
|
+
EM.stop
|
148
|
+
}
|
149
|
+
}
|
150
|
+
assert_equal(200, d.status)
|
151
|
+
end if EM.ssl?
|
152
|
+
|
153
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.unshift "../lib"
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestInactivityTimeout < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_default
|
8
|
+
$timeout = nil
|
9
|
+
EM.run {
|
10
|
+
c = EM.connect("127.0.0.1", 54321)
|
11
|
+
$timeout = c.comm_inactivity_timeout
|
12
|
+
EM.stop
|
13
|
+
}
|
14
|
+
|
15
|
+
assert_equal(0.0, $timeout)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_with_set
|
19
|
+
$timeout = nil
|
20
|
+
EM.run {
|
21
|
+
c = EM.connect("127.0.0.1", 54321)
|
22
|
+
c.comm_inactivity_timeout = 2.5
|
23
|
+
$timeout = c.comm_inactivity_timeout
|
24
|
+
EM.stop
|
25
|
+
}
|
26
|
+
|
27
|
+
assert_equal(2.5, $timeout)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/tests/test_kb.rb
CHANGED
@@ -37,10 +37,10 @@ class TestKeyboardEvents < Test::Unit::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
module KbHandler
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
include EM::Protocols::LineText2
|
41
|
+
def receive_line d
|
42
|
+
EM::stop if d == "STOP"
|
43
|
+
end
|
44
44
|
end
|
45
45
|
|
46
46
|
# This test doesn't actually do anything useful but is here to
|
@@ -51,11 +51,10 @@ class TestKeyboardEvents < Test::Unit::TestCase
|
|
51
51
|
# When someone figures that out, then we can make this a real test.
|
52
52
|
#
|
53
53
|
def test_kb
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
EM.run {
|
55
|
+
EM.open_keyboard KbHandler
|
56
|
+
EM::Timer.new(1) { EM.stop }
|
57
|
+
} if $stdout.tty? # don't run the test unless it stands a chance of validity.
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
61
|
-
|
data/tests/test_ltp2.rb
CHANGED
@@ -33,288 +33,285 @@ require 'test/unit'
|
|
33
33
|
|
34
34
|
class TestLineText2 < Test::Unit::TestCase
|
35
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
testdata = %Q(Line 1
|
36
|
+
# Run each of these tests two ways: passing in the whole test-dataset in one chunk,
|
37
|
+
# and passing it in one character at a time.
|
38
|
+
|
39
|
+
class Basic
|
40
|
+
include EM::Protocols::LineText2
|
41
|
+
attr_reader :lines
|
42
|
+
def receive_line line
|
43
|
+
(@lines ||= []) << line
|
44
|
+
end
|
45
|
+
end
|
46
|
+
def test_basic
|
47
|
+
testdata = "Line 1\nLine 2\r\nLine 3\n"
|
48
|
+
|
49
|
+
a = Basic.new
|
50
|
+
a.receive_data testdata
|
51
|
+
assert_equal( ["Line 1", "Line 2", "Line 3"], a.lines )
|
52
|
+
|
53
|
+
a = Basic.new
|
54
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
55
|
+
assert_equal( ["Line 1", "Line 2", "Line 3"], a.lines )
|
56
|
+
end
|
57
|
+
|
58
|
+
class ChangeDelimiter
|
59
|
+
include EM::Protocols::LineText2
|
60
|
+
attr_reader :lines
|
61
|
+
def initialize *args
|
62
|
+
super
|
63
|
+
@delim = "A"
|
64
|
+
set_delimiter @delim
|
65
|
+
end
|
66
|
+
def receive_line line
|
67
|
+
(@lines ||= []) << line
|
68
|
+
set_delimiter( @delim.succ! )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_change_delimiter
|
73
|
+
testdata = %Q(LineaALinebBLinecCLinedD)
|
74
|
+
|
75
|
+
a = ChangeDelimiter.new
|
76
|
+
a.receive_data testdata
|
77
|
+
assert_equal( ["Linea", "Lineb", "Linec", "Lined"], a.lines )
|
78
|
+
|
79
|
+
a = ChangeDelimiter.new
|
80
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
81
|
+
assert_equal( ["Linea", "Lineb", "Linec", "Lined"], a.lines )
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
#--
|
86
|
+
# Test two lines followed by an empty line, ten bytes of binary data, then
|
87
|
+
# two more lines.
|
88
|
+
|
89
|
+
class Binary
|
90
|
+
include EM::Protocols::LineText2
|
91
|
+
attr_reader :lines, :body
|
92
|
+
def initialize *args
|
93
|
+
super
|
94
|
+
@lines = []
|
95
|
+
@body = nil
|
96
|
+
end
|
97
|
+
def receive_line ln
|
98
|
+
if ln == ""
|
99
|
+
set_text_mode 10
|
100
|
+
else
|
101
|
+
@lines << ln
|
102
|
+
end
|
103
|
+
end
|
104
|
+
def receive_binary_data data
|
105
|
+
@body = data
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_binary
|
110
|
+
testdata = %Q(Line 1
|
112
111
|
Line 2
|
113
112
|
|
114
113
|
0000000000Line 3
|
115
114
|
Line 4
|
116
115
|
)
|
117
116
|
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
end
|
117
|
+
a = Binary.new
|
118
|
+
a.receive_data testdata
|
119
|
+
assert_equal( ["Line 1", "Line 2", "Line 3", "Line 4"], a.lines)
|
120
|
+
assert_equal( "0000000000", a.body )
|
121
|
+
|
122
|
+
a = Binary.new
|
123
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
124
|
+
assert_equal( ["Line 1", "Line 2", "Line 3", "Line 4"], a.lines)
|
125
|
+
assert_equal( "0000000000", a.body )
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
# Test unsized binary data. The expectation is that each chunk of it
|
130
|
+
# will be passed to us as it it received.
|
131
|
+
class UnsizedBinary
|
132
|
+
include EM::Protocols::LineText2
|
133
|
+
attr_reader :n_calls, :body
|
134
|
+
def initialize *args
|
135
|
+
super
|
136
|
+
set_text_mode
|
137
|
+
end
|
138
|
+
def receive_binary_data data
|
139
|
+
@n_calls ||= 0
|
140
|
+
@n_calls += 1
|
141
|
+
(@body ||= "") << data
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_unsized_binary
|
146
|
+
testdata = "X\0" * 1000
|
147
|
+
|
148
|
+
a = UnsizedBinary.new
|
149
|
+
a.receive_data testdata
|
150
|
+
assert_equal( 1, a.n_calls )
|
151
|
+
assert_equal( testdata, a.body )
|
152
|
+
|
153
|
+
a = UnsizedBinary.new
|
154
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
155
|
+
assert_equal( 2000, a.n_calls )
|
156
|
+
assert_equal( testdata, a.body )
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
# Test binary data with a "throw back" into line-mode.
|
161
|
+
class ThrowBack
|
162
|
+
include EM::Protocols::LineText2
|
163
|
+
attr_reader :headers
|
164
|
+
def initialize *args
|
165
|
+
super
|
166
|
+
@headers = []
|
167
|
+
@n_bytes = 0
|
168
|
+
set_text_mode
|
169
|
+
end
|
170
|
+
def receive_binary_data data
|
171
|
+
wanted = 25 - @n_bytes
|
172
|
+
will_take = if data.length > wanted
|
173
|
+
data.length - wanted
|
174
|
+
else
|
175
|
+
data.length
|
176
|
+
end
|
177
|
+
@n_bytes += will_take
|
178
|
+
|
179
|
+
if @n_bytes == 25
|
180
|
+
set_line_mode( data[will_take..-1] )
|
181
|
+
end
|
182
|
+
end
|
183
|
+
def receive_line ln
|
184
|
+
@headers << ln
|
185
|
+
end
|
186
|
+
end
|
187
|
+
def test_throw_back
|
188
|
+
testdata = "Line\n" * 10
|
189
|
+
|
190
|
+
a = ThrowBack.new
|
191
|
+
a.receive_data testdata
|
192
|
+
assert_equal( ["Line"] * 5, a.headers )
|
193
|
+
|
194
|
+
a = ThrowBack.new
|
195
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
196
|
+
assert_equal( ["Line"] * 5, a.headers )
|
197
|
+
end
|
198
|
+
|
199
|
+
# Test multi-character line delimiters.
|
200
|
+
# Also note that the test data has a "tail" with no delimiter, that will be
|
201
|
+
# discarded, but cf. the BinaryTail test.
|
202
|
+
# TODO!!! This test doesn't work in the byte-by-byte case.
|
203
|
+
class Multichar
|
204
|
+
include EM::Protocols::LineText2
|
205
|
+
attr_reader :lines
|
206
|
+
def initialize *args
|
207
|
+
super
|
208
|
+
@lines = []
|
209
|
+
set_delimiter "012"
|
210
|
+
end
|
211
|
+
def receive_line ln
|
212
|
+
@lines << ln
|
213
|
+
end
|
214
|
+
end
|
215
|
+
def test_multichar
|
216
|
+
testdata = "Line012Line012Line012Line"
|
217
|
+
|
218
|
+
a = Multichar.new
|
219
|
+
a.receive_data testdata
|
220
|
+
assert_equal( ["Line"]*3, a.lines )
|
221
|
+
|
222
|
+
a = Multichar.new
|
223
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
224
|
+
# DOESN'T WORK in this case. Multi-character delimiters are broken.
|
225
|
+
#assert_equal( ["Line"]*3, a.lines )
|
226
|
+
end
|
227
|
+
|
228
|
+
# Test a binary "tail," when a sized binary transfer doesn't complete because
|
229
|
+
# of an unbind. We get a partial result.
|
230
|
+
class BinaryTail
|
231
|
+
include EM::Protocols::LineText2
|
232
|
+
attr_reader :data
|
233
|
+
def initialize *args
|
234
|
+
super
|
235
|
+
@data = ""
|
236
|
+
set_text_mode 1000
|
237
|
+
end
|
238
|
+
def receive_binary_data data
|
239
|
+
# we expect to get all the data in one chunk, even in the byte-by-byte case,
|
240
|
+
# because sized transfers by definition give us exactly one call to
|
241
|
+
# #receive_binary_data.
|
242
|
+
@data = data
|
243
|
+
end
|
244
|
+
end
|
245
|
+
def test_binary_tail
|
246
|
+
testdata = "0" * 500
|
247
|
+
|
248
|
+
a = BinaryTail.new
|
249
|
+
a.receive_data testdata
|
250
|
+
a.unbind
|
251
|
+
assert_equal( "0" * 500, a.data )
|
252
|
+
|
253
|
+
a = BinaryTail.new
|
254
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
255
|
+
a.unbind
|
256
|
+
assert_equal( "0" * 500, a.data )
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
# Test an end-of-binary call. Arrange to receive binary data but don't bother counting it
|
261
|
+
# as it comes. Rely on getting receive_end_of_binary_data to signal the transition back to
|
262
|
+
# line mode.
|
263
|
+
# At the present time, this isn't strictly necessary with sized binary chunks because by
|
264
|
+
# definition we accumulate them and make exactly one call to receive_binary_data, but
|
265
|
+
# we may want to support a mode in the future that would break up large chunks into multiple
|
266
|
+
# calls.
|
267
|
+
class LazyBinary
|
268
|
+
include EM::Protocols::LineText2
|
269
|
+
attr_reader :data, :end
|
270
|
+
def initialize *args
|
271
|
+
super
|
272
|
+
@data = ""
|
273
|
+
set_text_mode 1000
|
274
|
+
end
|
275
|
+
def receive_binary_data data
|
276
|
+
# we expect to get all the data in one chunk, even in the byte-by-byte case,
|
277
|
+
# because sized transfers by definition give us exactly one call to
|
278
|
+
# #receive_binary_data.
|
279
|
+
@data = data
|
280
|
+
end
|
281
|
+
def receive_end_of_binary_data
|
282
|
+
@end = true
|
283
|
+
end
|
284
|
+
end
|
285
|
+
def test_receive_end_of_binary_data
|
286
|
+
testdata = "_" * 1000
|
287
|
+
a = LazyBinary.new
|
288
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
289
|
+
assert_equal( "_" * 1000, a.data )
|
290
|
+
assert( a.end )
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
# This tests a bug fix in which calling set_text_mode failed when called
|
295
|
+
# inside receive_binary_data.
|
296
|
+
#
|
297
|
+
class BinaryPair
|
298
|
+
include EM::Protocols::LineText2
|
299
|
+
attr_reader :sizes
|
300
|
+
def initialize *args
|
301
|
+
super
|
302
|
+
set_text_mode 1
|
303
|
+
@sizes = []
|
304
|
+
end
|
305
|
+
def receive_binary_data dt
|
306
|
+
@sizes << dt.length
|
307
|
+
set_text_mode( (dt.length == 1) ? 2 : 1 )
|
308
|
+
end
|
309
|
+
end
|
310
|
+
def test_binary_pairs
|
311
|
+
test_data = "123" * 5
|
312
|
+
a = BinaryPair.new
|
313
|
+
a.receive_data test_data
|
314
|
+
assert_equal( [1,2,1,2,1,2,1,2,1,2], a.sizes )
|
315
|
+
end
|
318
316
|
|
319
317
|
end
|
320
|
-
|