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,33 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestLineProtocol < Test::Unit::TestCase
|
4
|
+
class LineProtocolTestClass
|
5
|
+
include EM::Protocols::LineProtocol
|
6
|
+
|
7
|
+
def lines
|
8
|
+
@lines ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def receive_line(line)
|
12
|
+
lines << line
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@proto = LineProtocolTestClass.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_simple_split_line
|
21
|
+
@proto.receive_data("this is")
|
22
|
+
assert_equal([], @proto.lines)
|
23
|
+
|
24
|
+
@proto.receive_data(" a test\n")
|
25
|
+
assert_equal(["this is a test"], @proto.lines)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_simple_lines
|
29
|
+
@proto.receive_data("aaa\nbbb\r\nccc\nddd")
|
30
|
+
assert_equal(%w(aaa bbb ccc), @proto.lines)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/tests/test_ltp.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestLineAndTextProtocol < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class SimpleLineTest < EM::P::LineAndTextProtocol
|
6
|
+
def receive_line line
|
7
|
+
@line_buffer << line
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module StopClient
|
12
|
+
def set_receive_data(&blk)
|
13
|
+
@rdb = blk
|
14
|
+
end
|
15
|
+
|
16
|
+
def receive_data data
|
17
|
+
@rdb.call(data) if @rdb
|
18
|
+
end
|
19
|
+
|
20
|
+
def unbind
|
21
|
+
EM.add_timer(0.1) { EM.stop }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@port = next_port
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_simple_lines
|
30
|
+
lines_received = []
|
31
|
+
EM.run {
|
32
|
+
EM.start_server( "127.0.0.1", @port, SimpleLineTest ) do |conn|
|
33
|
+
conn.instance_eval "@line_buffer = lines_received"
|
34
|
+
end
|
35
|
+
setup_timeout
|
36
|
+
|
37
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
38
|
+
c.send_data "aaa\nbbb\r\nccc\n"
|
39
|
+
c.close_connection_after_writing
|
40
|
+
end
|
41
|
+
}
|
42
|
+
assert_equal( %w(aaa bbb ccc), lines_received )
|
43
|
+
end
|
44
|
+
|
45
|
+
#--------------------------------------------------------------------
|
46
|
+
|
47
|
+
class SimpleLineTest < EM::P::LineAndTextProtocol
|
48
|
+
def receive_error text
|
49
|
+
@error_message << text
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_overlength_lines
|
54
|
+
lines_received = []
|
55
|
+
EM.run {
|
56
|
+
EM.start_server( "127.0.0.1", @port, SimpleLineTest ) do |conn|
|
57
|
+
conn.instance_eval "@error_message = lines_received"
|
58
|
+
end
|
59
|
+
setup_timeout
|
60
|
+
|
61
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
62
|
+
c.send_data "a" * (16*1024 + 1)
|
63
|
+
c.send_data "\n"
|
64
|
+
c.close_connection_after_writing
|
65
|
+
end
|
66
|
+
|
67
|
+
}
|
68
|
+
assert_equal( ["overlength line"], lines_received )
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
#--------------------------------------------------------------------
|
73
|
+
|
74
|
+
class LineAndTextTest < EM::P::LineAndTextProtocol
|
75
|
+
def receive_line line
|
76
|
+
if line =~ /content-length:\s*(\d+)/i
|
77
|
+
@content_length = $1.to_i
|
78
|
+
elsif line.length == 0
|
79
|
+
set_binary_mode @content_length
|
80
|
+
end
|
81
|
+
end
|
82
|
+
def receive_binary_data text
|
83
|
+
send_data "received #{text.length} bytes"
|
84
|
+
close_connection_after_writing
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_lines_and_text
|
89
|
+
output = ''
|
90
|
+
EM.run {
|
91
|
+
EM.start_server( "127.0.0.1", @port, LineAndTextTest )
|
92
|
+
setup_timeout
|
93
|
+
|
94
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
95
|
+
c.set_receive_data { |data| output << data }
|
96
|
+
c.send_data "Content-length: 400\n"
|
97
|
+
c.send_data "\n"
|
98
|
+
c.send_data "A" * 400
|
99
|
+
EM.add_timer(0.1) { c.close_connection_after_writing }
|
100
|
+
end
|
101
|
+
}
|
102
|
+
assert_equal( "received 400 bytes", output )
|
103
|
+
end
|
104
|
+
|
105
|
+
#--------------------------------------------------------------------
|
106
|
+
|
107
|
+
|
108
|
+
class BinaryTextTest < EM::P::LineAndTextProtocol
|
109
|
+
def receive_line line
|
110
|
+
if line =~ /content-length:\s*(\d+)/i
|
111
|
+
set_binary_mode $1.to_i
|
112
|
+
else
|
113
|
+
raise "protocol error"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
def receive_binary_data text
|
117
|
+
send_data "received #{text.length} bytes"
|
118
|
+
close_connection_after_writing
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_binary_text
|
123
|
+
output = ''
|
124
|
+
EM.run {
|
125
|
+
EM.start_server( "127.0.0.1", @port, BinaryTextTest )
|
126
|
+
setup_timeout
|
127
|
+
|
128
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
129
|
+
c.set_receive_data { |data| output << data }
|
130
|
+
c.send_data "Content-length: 10000\n"
|
131
|
+
c.send_data "A" * 10000
|
132
|
+
EM.add_timer(0.1) { c.close_connection_after_writing }
|
133
|
+
end
|
134
|
+
}
|
135
|
+
assert_equal( "received 10000 bytes", output )
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
data/tests/test_ltp2.rb
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
# TODO!!! Need tests for overlength headers and text bodies.
|
4
|
+
|
5
|
+
class TestLineText2 < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# Run each of these tests two ways: passing in the whole test-dataset in one chunk,
|
8
|
+
# and passing it in one character at a time.
|
9
|
+
|
10
|
+
class Basic
|
11
|
+
include EM::Protocols::LineText2
|
12
|
+
attr_reader :lines
|
13
|
+
def receive_line line
|
14
|
+
(@lines ||= []) << line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def test_basic
|
18
|
+
testdata = "Line 1\nLine 2\r\nLine 3\n"
|
19
|
+
|
20
|
+
a = Basic.new
|
21
|
+
a.receive_data testdata
|
22
|
+
assert_equal( ["Line 1", "Line 2", "Line 3"], a.lines )
|
23
|
+
|
24
|
+
a = Basic.new
|
25
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
26
|
+
assert_equal( ["Line 1", "Line 2", "Line 3"], a.lines )
|
27
|
+
end
|
28
|
+
|
29
|
+
class ChangeDelimiter
|
30
|
+
include EM::Protocols::LineText2
|
31
|
+
attr_reader :lines
|
32
|
+
def initialize *args
|
33
|
+
super
|
34
|
+
@delim = "A"
|
35
|
+
set_delimiter @delim
|
36
|
+
end
|
37
|
+
def receive_line line
|
38
|
+
(@lines ||= []) << line
|
39
|
+
set_delimiter( @delim.succ! )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_change_delimiter
|
44
|
+
testdata = %Q(LineaALinebBLinecCLinedD)
|
45
|
+
|
46
|
+
a = ChangeDelimiter.new
|
47
|
+
a.receive_data testdata
|
48
|
+
assert_equal( ["Linea", "Lineb", "Linec", "Lined"], a.lines )
|
49
|
+
|
50
|
+
a = ChangeDelimiter.new
|
51
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
52
|
+
assert_equal( ["Linea", "Lineb", "Linec", "Lined"], a.lines )
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
#--
|
57
|
+
# Test two lines followed by an empty line, ten bytes of binary data, then
|
58
|
+
# two more lines.
|
59
|
+
|
60
|
+
class Binary
|
61
|
+
include EM::Protocols::LineText2
|
62
|
+
attr_reader :lines, :body
|
63
|
+
def initialize *args
|
64
|
+
super
|
65
|
+
@lines = []
|
66
|
+
@body = nil
|
67
|
+
end
|
68
|
+
def receive_line ln
|
69
|
+
if ln == ""
|
70
|
+
set_text_mode 10
|
71
|
+
else
|
72
|
+
@lines << ln
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def receive_binary_data data
|
76
|
+
@body = data
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_binary
|
81
|
+
testdata = %Q(Line 1
|
82
|
+
Line 2
|
83
|
+
|
84
|
+
0000000000Line 3
|
85
|
+
Line 4
|
86
|
+
)
|
87
|
+
|
88
|
+
a = Binary.new
|
89
|
+
a.receive_data testdata
|
90
|
+
assert_equal( ["Line 1", "Line 2", "Line 3", "Line 4"], a.lines)
|
91
|
+
assert_equal( "0000000000", a.body )
|
92
|
+
|
93
|
+
a = Binary.new
|
94
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
95
|
+
assert_equal( ["Line 1", "Line 2", "Line 3", "Line 4"], a.lines)
|
96
|
+
assert_equal( "0000000000", a.body )
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Test unsized binary data. The expectation is that each chunk of it
|
101
|
+
# will be passed to us as it it received.
|
102
|
+
class UnsizedBinary
|
103
|
+
include EM::Protocols::LineText2
|
104
|
+
attr_reader :n_calls, :body
|
105
|
+
def initialize *args
|
106
|
+
super
|
107
|
+
set_text_mode
|
108
|
+
end
|
109
|
+
def receive_binary_data data
|
110
|
+
@n_calls ||= 0
|
111
|
+
@n_calls += 1
|
112
|
+
(@body ||= "") << data
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_unsized_binary
|
117
|
+
testdata = "X\0" * 1000
|
118
|
+
|
119
|
+
a = UnsizedBinary.new
|
120
|
+
a.receive_data testdata
|
121
|
+
assert_equal( 1, a.n_calls )
|
122
|
+
assert_equal( testdata, a.body )
|
123
|
+
|
124
|
+
a = UnsizedBinary.new
|
125
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
126
|
+
assert_equal( 2000, a.n_calls )
|
127
|
+
assert_equal( testdata, a.body )
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
# Test binary data with a "throw back" into line-mode.
|
132
|
+
class ThrowBack
|
133
|
+
include EM::Protocols::LineText2
|
134
|
+
attr_reader :headers
|
135
|
+
def initialize *args
|
136
|
+
super
|
137
|
+
@headers = []
|
138
|
+
@n_bytes = 0
|
139
|
+
set_text_mode
|
140
|
+
end
|
141
|
+
def receive_binary_data data
|
142
|
+
wanted = 25 - @n_bytes
|
143
|
+
will_take = if data.length > wanted
|
144
|
+
data.length - wanted
|
145
|
+
else
|
146
|
+
data.length
|
147
|
+
end
|
148
|
+
@n_bytes += will_take
|
149
|
+
|
150
|
+
if @n_bytes == 25
|
151
|
+
set_line_mode( data[will_take..-1] )
|
152
|
+
end
|
153
|
+
end
|
154
|
+
def receive_line ln
|
155
|
+
@headers << ln
|
156
|
+
end
|
157
|
+
end
|
158
|
+
def test_throw_back
|
159
|
+
testdata = "Line\n" * 10
|
160
|
+
|
161
|
+
a = ThrowBack.new
|
162
|
+
a.receive_data testdata
|
163
|
+
assert_equal( ["Line"] * 5, a.headers )
|
164
|
+
|
165
|
+
a = ThrowBack.new
|
166
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
167
|
+
assert_equal( ["Line"] * 5, a.headers )
|
168
|
+
end
|
169
|
+
|
170
|
+
# Test multi-character line delimiters.
|
171
|
+
# Also note that the test data has a "tail" with no delimiter, that will be
|
172
|
+
# discarded, but cf. the BinaryTail test.
|
173
|
+
# TODO!!! This test doesn't work in the byte-by-byte case.
|
174
|
+
class Multichar
|
175
|
+
include EM::Protocols::LineText2
|
176
|
+
attr_reader :lines
|
177
|
+
def initialize *args
|
178
|
+
super
|
179
|
+
@lines = []
|
180
|
+
set_delimiter "012"
|
181
|
+
end
|
182
|
+
def receive_line ln
|
183
|
+
@lines << ln
|
184
|
+
end
|
185
|
+
end
|
186
|
+
def test_multichar
|
187
|
+
testdata = "Line012Line012Line012Line"
|
188
|
+
|
189
|
+
a = Multichar.new
|
190
|
+
a.receive_data testdata
|
191
|
+
assert_equal( ["Line"]*3, a.lines )
|
192
|
+
|
193
|
+
a = Multichar.new
|
194
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
195
|
+
# DOESN'T WORK in this case. Multi-character delimiters are broken.
|
196
|
+
#assert_equal( ["Line"]*3, a.lines )
|
197
|
+
end
|
198
|
+
|
199
|
+
# Test a binary "tail," when a sized binary transfer doesn't complete because
|
200
|
+
# of an unbind. We get a partial result.
|
201
|
+
class BinaryTail
|
202
|
+
include EM::Protocols::LineText2
|
203
|
+
attr_reader :data
|
204
|
+
def initialize *args
|
205
|
+
super
|
206
|
+
@data = ""
|
207
|
+
set_text_mode 1000
|
208
|
+
end
|
209
|
+
def receive_binary_data data
|
210
|
+
# we expect to get all the data in one chunk, even in the byte-by-byte case,
|
211
|
+
# because sized transfers by definition give us exactly one call to
|
212
|
+
# #receive_binary_data.
|
213
|
+
@data = data
|
214
|
+
end
|
215
|
+
end
|
216
|
+
def test_binary_tail
|
217
|
+
testdata = "0" * 500
|
218
|
+
|
219
|
+
a = BinaryTail.new
|
220
|
+
a.receive_data testdata
|
221
|
+
a.unbind
|
222
|
+
assert_equal( "0" * 500, a.data )
|
223
|
+
|
224
|
+
a = BinaryTail.new
|
225
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
226
|
+
a.unbind
|
227
|
+
assert_equal( "0" * 500, a.data )
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
# Test an end-of-binary call. Arrange to receive binary data but don't bother counting it
|
232
|
+
# as it comes. Rely on getting receive_end_of_binary_data to signal the transition back to
|
233
|
+
# line mode.
|
234
|
+
# At the present time, this isn't strictly necessary with sized binary chunks because by
|
235
|
+
# definition we accumulate them and make exactly one call to receive_binary_data, but
|
236
|
+
# we may want to support a mode in the future that would break up large chunks into multiple
|
237
|
+
# calls.
|
238
|
+
class LazyBinary
|
239
|
+
include EM::Protocols::LineText2
|
240
|
+
attr_reader :data, :end
|
241
|
+
def initialize *args
|
242
|
+
super
|
243
|
+
@data = ""
|
244
|
+
set_text_mode 1000
|
245
|
+
end
|
246
|
+
def receive_binary_data data
|
247
|
+
# we expect to get all the data in one chunk, even in the byte-by-byte case,
|
248
|
+
# because sized transfers by definition give us exactly one call to
|
249
|
+
# #receive_binary_data.
|
250
|
+
@data = data
|
251
|
+
end
|
252
|
+
def receive_end_of_binary_data
|
253
|
+
@end = true
|
254
|
+
end
|
255
|
+
end
|
256
|
+
def test_receive_end_of_binary_data
|
257
|
+
testdata = "_" * 1000
|
258
|
+
a = LazyBinary.new
|
259
|
+
testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) }
|
260
|
+
assert_equal( "_" * 1000, a.data )
|
261
|
+
assert( a.end )
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
# This tests a bug fix in which calling set_text_mode failed when called
|
266
|
+
# inside receive_binary_data.
|
267
|
+
#
|
268
|
+
class BinaryPair
|
269
|
+
include EM::Protocols::LineText2
|
270
|
+
attr_reader :sizes
|
271
|
+
def initialize *args
|
272
|
+
super
|
273
|
+
set_text_mode 1
|
274
|
+
@sizes = []
|
275
|
+
end
|
276
|
+
def receive_binary_data dt
|
277
|
+
@sizes << dt.length
|
278
|
+
set_text_mode( (dt.length == 1) ? 2 : 1 )
|
279
|
+
end
|
280
|
+
end
|
281
|
+
def test_binary_pairs
|
282
|
+
test_data = "123" * 5
|
283
|
+
a = BinaryPair.new
|
284
|
+
a.receive_data test_data
|
285
|
+
assert_equal( [1,2,1,2,1,2,1,2,1,2], a.sizes )
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|