eventmachine 1.0.0.beta.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/Gemfile +1 -0
- data/README +81 -0
- data/Rakefile +11 -0
- data/docs/COPYING +60 -0
- data/docs/ChangeLog +211 -0
- data/docs/DEFERRABLES +246 -0
- data/docs/EPOLL +141 -0
- data/docs/GNU +281 -0
- data/docs/INSTALL +13 -0
- data/docs/KEYBOARD +42 -0
- data/docs/LEGAL +25 -0
- data/docs/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/PURE_RUBY +75 -0
- data/docs/RELEASE_NOTES +94 -0
- data/docs/SMTP +4 -0
- data/docs/SPAWNED_PROCESSES +148 -0
- data/docs/TODO +8 -0
- data/eventmachine.gemspec +33 -0
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/ex_tick_loop_array.rb +15 -0
- data/examples/ex_tick_loop_counter.rb +32 -0
- data/examples/helper.rb +2 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +46 -0
- data/ext/cmain.cpp +838 -0
- data/ext/ed.cpp +1884 -0
- data/ext/ed.h +418 -0
- data/ext/em.cpp +2348 -0
- data/ext/em.h +228 -0
- data/ext/eventmachine.h +123 -0
- data/ext/extconf.rb +157 -0
- data/ext/fastfilereader/extconf.rb +85 -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 +1200 -0
- data/ext/ssl.cpp +460 -0
- data/ext/ssl.h +94 -0
- data/java/.classpath +8 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +571 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
- data/lib/em/buftok.rb +138 -0
- data/lib/em/callback.rb +26 -0
- data/lib/em/channel.rb +57 -0
- data/lib/em/connection.rb +569 -0
- data/lib/em/deferrable.rb +206 -0
- data/lib/em/file_watch.rb +54 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +270 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/process_watch.rb +44 -0
- data/lib/em/processes.rb +119 -0
- data/lib/em/protocols.rb +36 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +268 -0
- data/lib/em/protocols/httpclient2.rb +590 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +28 -0
- data/lib/em/protocols/linetext2.rb +161 -0
- data/lib/em/protocols/memcache.rb +323 -0
- data/lib/em/protocols/object_protocol.rb +45 -0
- data/lib/em/protocols/postgres3.rb +247 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +357 -0
- data/lib/em/protocols/smtpserver.rb +640 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +200 -0
- data/lib/em/protocols/tcptest.rb +53 -0
- data/lib/em/pure_ruby.rb +1013 -0
- data/lib/em/queue.rb +62 -0
- data/lib/em/spawnable.rb +85 -0
- data/lib/em/streamer.rb +130 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +57 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1548 -0
- data/lib/jeventmachine.rb +258 -0
- data/lib/rubyeventmachine.rb +2 -0
- data/setup.rb +1585 -0
- data/tasks/cpp.rake_example +77 -0
- data/tasks/doc.rake +30 -0
- data/tasks/package.rake +85 -0
- data/tasks/test.rake +6 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/test_attach.rb +136 -0
- data/tests/test_basic.rb +249 -0
- data/tests/test_channel.rb +64 -0
- data/tests/test_connection_count.rb +35 -0
- data/tests/test_defer.rb +49 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +160 -0
- data/tests/test_error_handler.rb +35 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_exc.rb +55 -0
- data/tests/test_file_watch.rb +49 -0
- data/tests/test_futures.rb +198 -0
- data/tests/test_get_sock_opt.rb +30 -0
- data/tests/test_handler_check.rb +37 -0
- data/tests/test_hc.rb +190 -0
- data/tests/test_httpclient.rb +227 -0
- data/tests/test_httpclient2.rb +154 -0
- data/tests/test_inactivity_timeout.rb +50 -0
- data/tests/test_kb.rb +60 -0
- data/tests/test_ltp.rb +190 -0
- data/tests/test_ltp2.rb +317 -0
- data/tests/test_next_tick.rb +133 -0
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_pause.rb +70 -0
- data/tests/test_pending_connect_timeout.rb +48 -0
- data/tests/test_process_watch.rb +50 -0
- data/tests/test_processes.rb +128 -0
- data/tests/test_proxy_connection.rb +144 -0
- data/tests/test_pure.rb +134 -0
- data/tests/test_queue.rb +44 -0
- data/tests/test_running.rb +42 -0
- data/tests/test_sasl.rb +72 -0
- data/tests/test_send_file.rb +251 -0
- data/tests/test_servers.rb +76 -0
- data/tests/test_smtpclient.rb +83 -0
- data/tests/test_smtpserver.rb +85 -0
- data/tests/test_spawn.rb +322 -0
- data/tests/test_ssl_args.rb +79 -0
- data/tests/test_ssl_methods.rb +50 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +160 -0
- data/tests/test_ud.rb +36 -0
- data/tests/testem.rb +31 -0
- metadata +240 -0
data/tests/test_ltp.rb
ADDED
@@ -0,0 +1,190 @@
|
|
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
|
+
|
28
|
+
require 'eventmachine'
|
29
|
+
require 'test/unit'
|
30
|
+
|
31
|
+
class TestLineAndTextProtocol < Test::Unit::TestCase
|
32
|
+
|
33
|
+
TestHost = "127.0.0.1"
|
34
|
+
TestPort = 8905
|
35
|
+
|
36
|
+
|
37
|
+
#--------------------------------------------------------------------
|
38
|
+
|
39
|
+
class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
|
40
|
+
def receive_line line
|
41
|
+
@line_buffer << line
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module StopClient
|
46
|
+
def set_receive_data(&blk)
|
47
|
+
@rdb = blk
|
48
|
+
end
|
49
|
+
|
50
|
+
def receive_data data
|
51
|
+
@rdb.call(data) if @rdb
|
52
|
+
end
|
53
|
+
|
54
|
+
def unbind
|
55
|
+
EM.add_timer(0.1) { EM.stop }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def setup_timeout(timeout = 4)
|
60
|
+
EM.schedule {
|
61
|
+
start_time = EM.current_time
|
62
|
+
EM.add_periodic_timer(0.01) {
|
63
|
+
raise "timeout" if EM.current_time - start_time >= timeout
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_simple_lines
|
69
|
+
lines_received = []
|
70
|
+
EventMachine.run {
|
71
|
+
EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
|
72
|
+
conn.instance_eval "@line_buffer = lines_received"
|
73
|
+
end
|
74
|
+
setup_timeout
|
75
|
+
|
76
|
+
EventMachine.connect TestHost, TestPort, StopClient do |c|
|
77
|
+
c.send_data "aaa\nbbb\r\nccc\n"
|
78
|
+
c.close_connection_after_writing
|
79
|
+
end
|
80
|
+
}
|
81
|
+
assert_equal( %w(aaa bbb ccc), lines_received )
|
82
|
+
end
|
83
|
+
|
84
|
+
#--------------------------------------------------------------------
|
85
|
+
|
86
|
+
class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
|
87
|
+
def receive_error text
|
88
|
+
@error_message << text
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_overlength_lines
|
93
|
+
lines_received = []
|
94
|
+
EventMachine.run {
|
95
|
+
EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
|
96
|
+
conn.instance_eval "@error_message = lines_received"
|
97
|
+
end
|
98
|
+
setup_timeout
|
99
|
+
|
100
|
+
EventMachine.connect TestHost, TestPort, StopClient do |c|
|
101
|
+
c.send_data "a" * (16*1024 + 1)
|
102
|
+
c.send_data "\n"
|
103
|
+
c.close_connection_after_writing
|
104
|
+
end
|
105
|
+
|
106
|
+
}
|
107
|
+
assert_equal( ["overlength line"], lines_received )
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
#--------------------------------------------------------------------
|
112
|
+
|
113
|
+
class LineAndTextTest < EventMachine::Protocols::LineAndTextProtocol
|
114
|
+
def post_init
|
115
|
+
end
|
116
|
+
def receive_line line
|
117
|
+
if line =~ /content-length:\s*(\d+)/i
|
118
|
+
@content_length = $1.to_i
|
119
|
+
elsif line.length == 0
|
120
|
+
set_binary_mode @content_length
|
121
|
+
end
|
122
|
+
end
|
123
|
+
def receive_binary_data text
|
124
|
+
send_data "received #{text.length} bytes"
|
125
|
+
close_connection_after_writing
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_lines_and_text
|
130
|
+
output = ''
|
131
|
+
lines_received = []
|
132
|
+
text_received = []
|
133
|
+
EventMachine.run {
|
134
|
+
EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
|
135
|
+
conn.instance_eval "@lines = lines_received; @text = text_received"
|
136
|
+
end
|
137
|
+
setup_timeout
|
138
|
+
|
139
|
+
EventMachine.connect TestHost, TestPort, StopClient do |c|
|
140
|
+
c.set_receive_data { |data| output << data }
|
141
|
+
c.send_data "Content-length: 400\n"
|
142
|
+
c.send_data "\n"
|
143
|
+
c.send_data "A" * 400
|
144
|
+
EM.add_timer(0.1) { c.close_connection_after_writing }
|
145
|
+
end
|
146
|
+
}
|
147
|
+
assert_equal( "received 400 bytes", output )
|
148
|
+
end
|
149
|
+
|
150
|
+
#--------------------------------------------------------------------
|
151
|
+
|
152
|
+
|
153
|
+
class BinaryTextTest < EventMachine::Protocols::LineAndTextProtocol
|
154
|
+
def post_init
|
155
|
+
end
|
156
|
+
def receive_line line
|
157
|
+
if line =~ /content-length:\s*(\d+)/i
|
158
|
+
set_binary_mode $1.to_i
|
159
|
+
else
|
160
|
+
raise "protocol error"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
def receive_binary_data text
|
164
|
+
send_data "received #{text.length} bytes"
|
165
|
+
close_connection_after_writing
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_binary_text
|
170
|
+
output = ''
|
171
|
+
lines_received = []
|
172
|
+
text_received = []
|
173
|
+
EventMachine.run {
|
174
|
+
EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
|
175
|
+
conn.instance_eval "@lines = lines_received; @text = text_received"
|
176
|
+
end
|
177
|
+
setup_timeout
|
178
|
+
|
179
|
+
EventMachine.connect TestHost, TestPort, StopClient do |c|
|
180
|
+
c.set_receive_data { |data| output << data }
|
181
|
+
c.send_data "Content-length: 10000\n"
|
182
|
+
c.send_data "A" * 10000
|
183
|
+
EM.add_timer(0.2) { c.close_connection_after_writing }
|
184
|
+
end
|
185
|
+
}
|
186
|
+
assert_equal( "received 10000 bytes", output )
|
187
|
+
end
|
188
|
+
|
189
|
+
#--------------------------------------------------------------------
|
190
|
+
end
|
data/tests/test_ltp2.rb
ADDED
@@ -0,0 +1,317 @@
|
|
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
|
+
|
28
|
+
$:.unshift "../lib"
|
29
|
+
require 'eventmachine'
|
30
|
+
require 'test/unit'
|
31
|
+
|
32
|
+
# TODO!!! Need tests for overlength headers and text bodies.
|
33
|
+
|
34
|
+
class TestLineText2 < Test::Unit::TestCase
|
35
|
+
|
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
|
111
|
+
Line 2
|
112
|
+
|
113
|
+
0000000000Line 3
|
114
|
+
Line 4
|
115
|
+
)
|
116
|
+
|
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
|
316
|
+
|
317
|
+
end
|