eventmachine 0.12.0-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +60 -0
- data/DEFERRABLES +138 -0
- data/EPOLL +141 -0
- data/GNU +281 -0
- data/KEYBOARD +38 -0
- data/LEGAL +25 -0
- data/LIGHTWEIGHT_CONCURRENCY +72 -0
- data/PURE_RUBY +77 -0
- data/README +74 -0
- data/RELEASE_NOTES +96 -0
- data/SMTP +9 -0
- data/SPAWNED_PROCESSES +93 -0
- data/TODO +10 -0
- data/ext/Makefile +180 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +527 -0
- data/ext/cplusplus.cpp +172 -0
- data/ext/ed.cpp +1442 -0
- data/ext/ed.h +351 -0
- data/ext/em.cpp +1781 -0
- data/ext/em.h +167 -0
- data/ext/emwin.cpp +300 -0
- data/ext/emwin.h +94 -0
- data/ext/epoll.cpp +26 -0
- data/ext/epoll.h +25 -0
- data/ext/eventmachine.h +83 -0
- data/ext/eventmachine_cpp.h +94 -0
- data/ext/extconf.rb +203 -0
- data/ext/files.cpp +94 -0
- data/ext/files.h +65 -0
- data/ext/kb.cpp +368 -0
- data/ext/mkmf.log +129 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +327 -0
- data/ext/project.h +119 -0
- data/ext/rubyeventmachine-i386-mswin32.def +2 -0
- data/ext/rubyeventmachine-i386-mswin32.exp +0 -0
- data/ext/rubyeventmachine-i386-mswin32.lib +0 -0
- data/ext/rubyeventmachine-i386-mswin32.pdb +0 -0
- data/ext/rubyeventmachine.so +0 -0
- data/ext/rubymain.cpp +630 -0
- data/ext/sigs.cpp +89 -0
- data/ext/sigs.h +32 -0
- data/ext/ssl.cpp +408 -0
- data/ext/ssl.h +86 -0
- data/ext/vc60.pdb +0 -0
- data/lib/em/deferrable.rb +208 -0
- data/lib/em/eventable.rb +39 -0
- data/lib/em/future.rb +62 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +88 -0
- data/lib/em/streamer.rb +112 -0
- data/lib/eventmachine.rb +1621 -0
- data/lib/eventmachine_version.rb +31 -0
- data/lib/evma.rb +32 -0
- data/lib/evma/callback.rb +32 -0
- data/lib/evma/container.rb +75 -0
- data/lib/evma/factory.rb +77 -0
- data/lib/evma/protocol.rb +87 -0
- data/lib/evma/reactor.rb +48 -0
- data/lib/jeventmachine.rb +106 -0
- data/lib/pr_eventmachine.rb +1011 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +123 -0
- data/lib/protocols/httpcli2.rb +784 -0
- data/lib/protocols/httpclient.rb +253 -0
- data/lib/protocols/line_and_text.rb +122 -0
- data/lib/protocols/linetext2.rb +145 -0
- data/lib/protocols/saslauth.rb +179 -0
- data/lib/protocols/smtpclient.rb +308 -0
- data/lib/protocols/smtpserver.rb +543 -0
- data/lib/protocols/stomp.rb +127 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/lib/rubyeventmachine.so +0 -0
- data/tests/test_basic.rb +142 -0
- data/tests/test_defer.rb +63 -0
- data/tests/test_epoll.rb +168 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_eventables.rb +78 -0
- data/tests/test_exc.rb +58 -0
- data/tests/test_futures.rb +214 -0
- data/tests/test_hc.rb +221 -0
- data/tests/test_httpclient.rb +194 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_kb.rb +61 -0
- data/tests/test_ltp.rb +190 -0
- data/tests/test_ltp2.rb +261 -0
- data/tests/test_next_tick.rb +58 -0
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +128 -0
- data/tests/test_running.rb +47 -0
- data/tests/test_sasl.rb +73 -0
- data/tests/test_send_file.rb +238 -0
- data/tests/test_servers.rb +90 -0
- data/tests/test_smtpclient.rb +81 -0
- data/tests/test_smtpserver.rb +93 -0
- data/tests/test_spawn.rb +329 -0
- data/tests/test_timers.rb +138 -0
- data/tests/test_ud.rb +43 -0
- data/tests/testem.rb +5 -0
- metadata +170 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
# $Id: test_httpclient.rb 668 2008-01-04 23:00:34Z blackhedd $
|
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
|
+
$:.unshift "../lib"
|
28
|
+
require 'eventmachine'
|
29
|
+
require 'test/unit'
|
30
|
+
|
31
|
+
class TestHttpClient < Test::Unit::TestCase
|
32
|
+
|
33
|
+
Localhost = "127.0.0.1"
|
34
|
+
Localport = 9801
|
35
|
+
|
36
|
+
def setup
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown
|
40
|
+
end
|
41
|
+
|
42
|
+
#-------------------------------------
|
43
|
+
|
44
|
+
def test_http_client
|
45
|
+
ok = false
|
46
|
+
EventMachine.run {
|
47
|
+
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
|
48
|
+
c.callback {
|
49
|
+
ok = true
|
50
|
+
EventMachine.stop
|
51
|
+
}
|
52
|
+
c.errback {EventMachine.stop} # necessary, otherwise a failure blocks the test suite forever.
|
53
|
+
}
|
54
|
+
assert ok
|
55
|
+
end
|
56
|
+
|
57
|
+
#-------------------------------------
|
58
|
+
|
59
|
+
def test_http_client_1
|
60
|
+
ok = false
|
61
|
+
EventMachine.run {
|
62
|
+
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
|
63
|
+
c.callback {ok = true; EventMachine.stop}
|
64
|
+
c.errback {EventMachine.stop}
|
65
|
+
}
|
66
|
+
assert ok
|
67
|
+
end
|
68
|
+
|
69
|
+
#-------------------------------------
|
70
|
+
|
71
|
+
def test_http_client_2
|
72
|
+
ok = false
|
73
|
+
EventMachine.run {
|
74
|
+
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
|
75
|
+
c.callback {|result|
|
76
|
+
ok = true;
|
77
|
+
EventMachine.stop
|
78
|
+
}
|
79
|
+
c.errback {EventMachine.stop}
|
80
|
+
}
|
81
|
+
assert ok
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
#-----------------------------------------
|
86
|
+
|
87
|
+
# Test a server that returns a page with a zero content-length.
|
88
|
+
# This caused an early version of the HTTP client not to generate a response,
|
89
|
+
# causing this test to hang. Observe, there was no problem with responses
|
90
|
+
# lacking a content-length, just when the content-length was zero.
|
91
|
+
#
|
92
|
+
class EmptyContent < EventMachine::Connection
|
93
|
+
def initialize *args
|
94
|
+
super
|
95
|
+
end
|
96
|
+
def receive_data data
|
97
|
+
send_data "HTTP/1.0 404 ...\r\nContent-length: 0\r\n\r\n"
|
98
|
+
close_connection_after_writing
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_http_empty_content
|
103
|
+
ok = false
|
104
|
+
EventMachine.run {
|
105
|
+
EventMachine.start_server "127.0.0.1", 9701, EmptyContent
|
106
|
+
c = EventMachine::Protocols::HttpClient.send :request, :host => "127.0.0.1", :port => 9701
|
107
|
+
c.callback {|result|
|
108
|
+
ok = true
|
109
|
+
EventMachine.stop
|
110
|
+
}
|
111
|
+
}
|
112
|
+
assert ok
|
113
|
+
end
|
114
|
+
|
115
|
+
#---------------------------------------
|
116
|
+
|
117
|
+
class PostContent < EventMachine::Protocols::LineAndTextProtocol
|
118
|
+
def initialize *args
|
119
|
+
super
|
120
|
+
@lines = []
|
121
|
+
end
|
122
|
+
def receive_line line
|
123
|
+
if line.length > 0
|
124
|
+
@lines << line
|
125
|
+
else
|
126
|
+
process_headers
|
127
|
+
end
|
128
|
+
end
|
129
|
+
def receive_binary_data data
|
130
|
+
@post_content = data
|
131
|
+
send_response
|
132
|
+
end
|
133
|
+
def process_headers
|
134
|
+
if @lines.first =~ /\APOST ([^\s]+) HTTP\/1.1\Z/
|
135
|
+
@uri = $1.dup
|
136
|
+
else
|
137
|
+
raise "bad request"
|
138
|
+
end
|
139
|
+
@lines.each {|line|
|
140
|
+
if line =~ /\AContent-length:\s*(\d+)\Z/i
|
141
|
+
@content_length = $1.dup.to_i
|
142
|
+
elsif line =~ /\AContent-type:\s*(\d+)\Z/i
|
143
|
+
@content_type = $1.dup
|
144
|
+
end
|
145
|
+
}
|
146
|
+
|
147
|
+
raise "invalid content length" unless @content_length
|
148
|
+
set_binary_mode @content_length
|
149
|
+
end
|
150
|
+
def send_response
|
151
|
+
send_data "HTTP/1.1 200 ...\r\nConnection: close\r\nContent-length: 10\r\nContent-type: text/html\r\n\r\n0123456789"
|
152
|
+
close_connection_after_writing
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# TODO, this is WRONG. The handler is asserting an HTTP 1.1 request, but the client
|
157
|
+
# is sending a 1.0 request. Gotta fix the client
|
158
|
+
def test_post
|
159
|
+
response = nil
|
160
|
+
EventMachine.run {
|
161
|
+
EventMachine.start_server Localhost, Localport, PostContent
|
162
|
+
EventMachine.add_timer(2) {raise "timed out"}
|
163
|
+
c = EventMachine::Protocols::HttpClient.request :host=>Localhost,
|
164
|
+
:port=>Localport, :method=>:post, :request=>"/aaa", :content=>"XYZ",
|
165
|
+
:content_type=>"text/plain"
|
166
|
+
c.callback {|r|
|
167
|
+
response = r
|
168
|
+
EventMachine.stop
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
assert_equal( 200, response[:status] )
|
173
|
+
assert_equal( "0123456789", response[:content] )
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
# TODO, need a more intelligent cookie tester.
|
178
|
+
# In fact, this whole test-harness needs a beefier server implementation.
|
179
|
+
def test_cookie
|
180
|
+
ok = false
|
181
|
+
EM.run {
|
182
|
+
c = EM::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80, :cookie=>"aaa=bbb"
|
183
|
+
c.callback {|result|
|
184
|
+
ok = true;
|
185
|
+
EventMachine.stop
|
186
|
+
}
|
187
|
+
c.errback {EventMachine.stop}
|
188
|
+
}
|
189
|
+
assert ok
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# $Id: test_httpclient2.rb 668 2008-01-04 23:00:34Z blackhedd $
|
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
|
+
$:.unshift "../lib"
|
28
|
+
require 'eventmachine'
|
29
|
+
require 'test/unit'
|
30
|
+
|
31
|
+
class TestHttpClient2 < Test::Unit::TestCase
|
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
|
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_raise( ArgumentError ) {
|
64
|
+
EM::P::HttpClient2.connect Localhost, "xxx"
|
65
|
+
}
|
66
|
+
EM.stop
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_bad_server
|
71
|
+
EM.run {
|
72
|
+
http = EM::P::HttpClient2.connect Localhost, 9999
|
73
|
+
d = http.get "/"
|
74
|
+
d.errback {p d.internal_error; EM.stop }
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_get
|
79
|
+
EM.run {
|
80
|
+
http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
|
81
|
+
d = http.get "/"
|
82
|
+
d.callback {
|
83
|
+
p d.content
|
84
|
+
EM.stop
|
85
|
+
}
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
# Not a pipelined request because we wait for one response before we request the next.
|
90
|
+
def test_get_multiple
|
91
|
+
EM.run {
|
92
|
+
http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
|
93
|
+
d = http.get "/"
|
94
|
+
d.callback {
|
95
|
+
e = http.get "/"
|
96
|
+
e.callback {
|
97
|
+
p e.content
|
98
|
+
EM.stop
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_get_pipeline
|
105
|
+
EM.run {
|
106
|
+
http = EM::P::HttpClient2.connect "www.microsoft.com", 80
|
107
|
+
d = http.get("/")
|
108
|
+
d.callback {
|
109
|
+
p d.headers
|
110
|
+
}
|
111
|
+
e = http.get("/")
|
112
|
+
e.callback {
|
113
|
+
p e.headers
|
114
|
+
}
|
115
|
+
EM::Timer.new(1) {EM.stop}
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_authheader
|
121
|
+
EM.run {
|
122
|
+
EM.start_server Localhost, Localport, TestServer
|
123
|
+
http = EM::P::HttpClient2.connect Localhost, 18842
|
124
|
+
d = http.get :url=>"/", :authorization=>"Basic xxx"
|
125
|
+
d.callback {EM.stop}
|
126
|
+
d.errback {EM.stop}
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
data/tests/test_kb.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# $Id: test_kb.rb 668 2008-01-04 23:00:34Z blackhedd $
|
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
|
+
$:.unshift "../lib"
|
28
|
+
require 'eventmachine'
|
29
|
+
require 'test/unit'
|
30
|
+
|
31
|
+
class TestKeyboardEvents < Test::Unit::TestCase
|
32
|
+
|
33
|
+
def setup
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
end
|
38
|
+
|
39
|
+
module KbHandler
|
40
|
+
include EM::Protocols::LineText2
|
41
|
+
def receive_line d
|
42
|
+
EM::stop if d == "STOP"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# This test doesn't actually do anything useful but is here to
|
47
|
+
# illustrate the usage. If you removed the timer and ran this test
|
48
|
+
# by itself on a console, and then typed into the console, it would
|
49
|
+
# work.
|
50
|
+
# I don't know how to get the test harness to simulate actual keystrokes.
|
51
|
+
# When someone figures that out, then we can make this a real test.
|
52
|
+
#
|
53
|
+
def test_kb
|
54
|
+
EM.run {
|
55
|
+
EM.open_keyboard KbHandler
|
56
|
+
EM::Timer.new(1) { EM.stop }
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
data/tests/test_ltp.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
# $Id: test_ltp.rb 668 2008-01-04 23:00:34Z blackhedd $
|
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 'socket'
|
31
|
+
require 'test/unit'
|
32
|
+
|
33
|
+
class TestLineAndTextProtocol < Test::Unit::TestCase
|
34
|
+
|
35
|
+
TestHost = "127.0.0.1"
|
36
|
+
TestPort = 8905
|
37
|
+
|
38
|
+
|
39
|
+
#--------------------------------------------------------------------
|
40
|
+
|
41
|
+
class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
|
42
|
+
def receive_line line
|
43
|
+
@line_buffer << line
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_simple_lines
|
48
|
+
# THIS TEST CURRENTLY FAILS IN JRUBY.
|
49
|
+
assert( RUBY_PLATFORM !~ /java/ )
|
50
|
+
|
51
|
+
lines_received = []
|
52
|
+
Thread.abort_on_exception = true
|
53
|
+
EventMachine.run {
|
54
|
+
EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
|
55
|
+
conn.instance_eval "@line_buffer = lines_received"
|
56
|
+
end
|
57
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
58
|
+
EventMachine.defer proc {
|
59
|
+
t = TCPSocket.new TestHost, TestPort
|
60
|
+
t.write [
|
61
|
+
"aaa\n", "bbb\r\n", "ccc\n"
|
62
|
+
].join
|
63
|
+
t.close
|
64
|
+
}, proc {
|
65
|
+
EventMachine.stop
|
66
|
+
}
|
67
|
+
}
|
68
|
+
assert_equal( %w(aaa bbb ccc), lines_received )
|
69
|
+
end
|
70
|
+
|
71
|
+
#--------------------------------------------------------------------
|
72
|
+
|
73
|
+
class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
|
74
|
+
def receive_error text
|
75
|
+
@error_message << text
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_overlength_lines
|
80
|
+
# THIS TEST CURRENTLY FAILS IN JRUBY.
|
81
|
+
assert( RUBY_PLATFORM !~ /java/ )
|
82
|
+
|
83
|
+
lines_received = []
|
84
|
+
Thread.abort_on_exception = true
|
85
|
+
EventMachine.run {
|
86
|
+
EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
|
87
|
+
conn.instance_eval "@error_message = lines_received"
|
88
|
+
end
|
89
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
90
|
+
EventMachine.defer proc {
|
91
|
+
t = TCPSocket.new TestHost, TestPort
|
92
|
+
t.write "a" * (16*1024 + 1)
|
93
|
+
t.write "\n"
|
94
|
+
t.close
|
95
|
+
}, proc {
|
96
|
+
EventMachine.stop
|
97
|
+
}
|
98
|
+
}
|
99
|
+
assert_equal( ["overlength line"], lines_received )
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
#--------------------------------------------------------------------
|
104
|
+
|
105
|
+
class LineAndTextTest < EventMachine::Protocols::LineAndTextProtocol
|
106
|
+
def post_init
|
107
|
+
end
|
108
|
+
def receive_line line
|
109
|
+
if line =~ /content-length:\s*(\d+)/i
|
110
|
+
@content_length = $1.to_i
|
111
|
+
elsif line.length == 0
|
112
|
+
set_binary_mode @content_length
|
113
|
+
end
|
114
|
+
end
|
115
|
+
def receive_binary_data text
|
116
|
+
send_data "received #{text.length} bytes"
|
117
|
+
close_connection_after_writing
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_lines_and_text
|
122
|
+
output = nil
|
123
|
+
lines_received = []
|
124
|
+
text_received = []
|
125
|
+
Thread.abort_on_exception = true
|
126
|
+
EventMachine.run {
|
127
|
+
EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
|
128
|
+
conn.instance_eval "@lines = lines_received; @text = text_received"
|
129
|
+
end
|
130
|
+
EventMachine.add_timer(2) {raise "test timed out"}
|
131
|
+
EventMachine.defer proc {
|
132
|
+
t = TCPSocket.new TestHost, TestPort
|
133
|
+
t.puts "Content-length: 400"
|
134
|
+
t.puts
|
135
|
+
t.write "A" * 400
|
136
|
+
output = t.read
|
137
|
+
t.close
|
138
|
+
}, proc {
|
139
|
+
EventMachine.stop
|
140
|
+
}
|
141
|
+
}
|
142
|
+
assert_equal( "received 400 bytes", output )
|
143
|
+
end
|
144
|
+
|
145
|
+
#--------------------------------------------------------------------
|
146
|
+
|
147
|
+
|
148
|
+
class BinaryTextTest < EventMachine::Protocols::LineAndTextProtocol
|
149
|
+
def post_init
|
150
|
+
end
|
151
|
+
def receive_line line
|
152
|
+
if line =~ /content-length:\s*(\d+)/i
|
153
|
+
set_binary_mode $1.to_i
|
154
|
+
else
|
155
|
+
raise "protocol error"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
def receive_binary_data text
|
159
|
+
send_data "received #{text.length} bytes"
|
160
|
+
close_connection_after_writing
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_binary_text
|
165
|
+
output = nil
|
166
|
+
lines_received = []
|
167
|
+
text_received = []
|
168
|
+
Thread.abort_on_exception = true
|
169
|
+
EventMachine.run {
|
170
|
+
EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
|
171
|
+
conn.instance_eval "@lines = lines_received; @text = text_received"
|
172
|
+
end
|
173
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
174
|
+
EventMachine.defer proc {
|
175
|
+
t = TCPSocket.new TestHost, TestPort
|
176
|
+
t.puts "Content-length: 10000"
|
177
|
+
t.write "A" * 10000
|
178
|
+
output = t.read
|
179
|
+
t.close
|
180
|
+
}, proc {
|
181
|
+
EventMachine.stop
|
182
|
+
}
|
183
|
+
}
|
184
|
+
assert_equal( "received 10000 bytes", output )
|
185
|
+
end
|
186
|
+
|
187
|
+
#--------------------------------------------------------------------
|
188
|
+
end
|
189
|
+
|
190
|
+
|