eventmachine-win32 0.5.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/RELEASE_NOTES +14 -1
- data/TODO +10 -0
- data/lib/em/deferrable.rb +89 -0
- data/lib/em/eventable.rb +50 -0
- data/lib/eventmachine.rb +274 -9
- data/lib/eventmachine_version.rb +42 -0
- data/lib/evma.rb +35 -0
- data/lib/evma/callback.rb +35 -0
- data/lib/evma/container.rb +77 -0
- data/lib/evma/factory.rb +80 -0
- data/lib/evma/protocol.rb +89 -0
- data/lib/evma/reactor.rb +50 -0
- data/lib/pr_eventmachine.rb +714 -0
- data/lib/protocols/header_and_content.rb +134 -0
- data/lib/protocols/httpclient.rb +233 -0
- data/lib/protocols/line_and_text.rb +141 -0
- data/lib/protocols/tcptest.rb +67 -0
- data/lib/rubyeventmachine.so +0 -0
- data/tests/test_basic.rb +106 -0
- data/tests/test_eventables.rb +85 -0
- data/tests/test_hc.rb +207 -0
- data/tests/test_httpclient.rb +94 -0
- data/tests/test_ltp.rb +192 -0
- data/tests/test_ud.rb +52 -0
- metadata +29 -3
@@ -0,0 +1,67 @@
|
|
1
|
+
# $Id: tcptest.rb 218 2006-07-17 10:29:20Z blackhedd $
|
2
|
+
#
|
3
|
+
# Author:: blackhedd (gmail address: garbagecat10).
|
4
|
+
# Date:: 16 July 2006
|
5
|
+
#
|
6
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# This program is made available under the terms of the GPL version 2.
|
9
|
+
#
|
10
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
11
|
+
# usage examples.
|
12
|
+
#
|
13
|
+
#----------------------------------------------------------------------------
|
14
|
+
#
|
15
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
16
|
+
#
|
17
|
+
# Gmail: garbagecat10
|
18
|
+
#
|
19
|
+
# This program is free software; you can redistribute it and/or modify
|
20
|
+
# it under the terms of the GNU General Public License as published by
|
21
|
+
# the Free Software Foundation; either version 2 of the License, or
|
22
|
+
# (at your option) any later version.
|
23
|
+
#
|
24
|
+
# This program is distributed in the hope that it will be useful,
|
25
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
# GNU General Public License for more details.
|
28
|
+
#
|
29
|
+
# You should have received a copy of the GNU General Public License
|
30
|
+
# along with this program; if not, write to the Free Software
|
31
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
32
|
+
#
|
33
|
+
#---------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
module EventMachine
|
40
|
+
module Protocols
|
41
|
+
|
42
|
+
class TcpConnectTester < Connection
|
43
|
+
include EventMachine::Deferrable
|
44
|
+
|
45
|
+
def self.test( host, port )
|
46
|
+
EventMachine.connect( host, port, self )
|
47
|
+
end
|
48
|
+
|
49
|
+
def post_init
|
50
|
+
@start_time = Time.now
|
51
|
+
end
|
52
|
+
|
53
|
+
def connection_completed
|
54
|
+
@completed = true
|
55
|
+
set_deferred_status :succeeded, (Time.now - @start_time)
|
56
|
+
close_connection
|
57
|
+
end
|
58
|
+
|
59
|
+
def unbind
|
60
|
+
set_deferred_status :failed, (Time.now - @start_time) unless @completed
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/lib/rubyeventmachine.so
CHANGED
Binary file
|
data/tests/test_basic.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# $Id: test_basic.rb 225 2006-08-10 08:53:52Z blackhedd $
|
2
|
+
#
|
3
|
+
# Author:: blackhedd (gmail address: garbagecat10).
|
4
|
+
# Date:: 8 Apr 2006
|
5
|
+
#
|
6
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# This program is made available under the terms of the GPL version 2.
|
9
|
+
#
|
10
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
11
|
+
# usage examples.
|
12
|
+
#
|
13
|
+
#----------------------------------------------------------------------------
|
14
|
+
#
|
15
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
16
|
+
#
|
17
|
+
# Gmail: garbagecat10
|
18
|
+
#
|
19
|
+
# This program is free software; you can redistribute it and/or modify
|
20
|
+
# it under the terms of the GNU General Public License as published by
|
21
|
+
# the Free Software Foundation; either version 2 of the License, or
|
22
|
+
# (at your option) any later version.
|
23
|
+
#
|
24
|
+
# This program is distributed in the hope that it will be useful,
|
25
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
# GNU General Public License for more details.
|
28
|
+
#
|
29
|
+
# You should have received a copy of the GNU General Public License
|
30
|
+
# along with this program; if not, write to the Free Software
|
31
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
32
|
+
#
|
33
|
+
#---------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#
|
36
|
+
|
37
|
+
$:.unshift "../lib"
|
38
|
+
require 'eventmachine'
|
39
|
+
|
40
|
+
class TestBasic < Test::Unit::TestCase
|
41
|
+
|
42
|
+
def setup
|
43
|
+
end
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
end
|
47
|
+
|
48
|
+
#-------------------------------------
|
49
|
+
|
50
|
+
def test_libtype
|
51
|
+
lt = EventMachine.library_type
|
52
|
+
case $eventmachine_library
|
53
|
+
when :pure_ruby
|
54
|
+
assert_equal( :pure_ruby, lt )
|
55
|
+
when :extension
|
56
|
+
assert_equal( :extension, lt )
|
57
|
+
else
|
58
|
+
assert_equal( :extension, lt )
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#-------------------------------------
|
63
|
+
|
64
|
+
|
65
|
+
def test_em
|
66
|
+
EventMachine.run {
|
67
|
+
EventMachine.add_timer 0 do
|
68
|
+
EventMachine.stop
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
#-------------------------------------
|
74
|
+
|
75
|
+
def test_timer
|
76
|
+
n = 0
|
77
|
+
EventMachine.run {
|
78
|
+
EventMachine.add_periodic_timer(1) {
|
79
|
+
n += 1
|
80
|
+
EventMachine.stop if n == 2
|
81
|
+
}
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
#-------------------------------------
|
86
|
+
|
87
|
+
# This test throws an already-running exception. WHY?
|
88
|
+
module Trivial
|
89
|
+
def post_init
|
90
|
+
EentMachine.stop
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_server
|
95
|
+
#EventMachine.run {
|
96
|
+
# EventMachine.start_server "localhost", 9000, Trivial
|
97
|
+
# EventMachine.connect "localhost", 9000
|
98
|
+
#}
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
#--------------------------------------
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# $Id: test_eventables.rb 252 2006-09-02 19:23:20Z blackhedd $
|
2
|
+
#
|
3
|
+
# Author:: blackhedd (gmail address: garbagecat10).
|
4
|
+
# Date:: 8 Apr 2006
|
5
|
+
#
|
6
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# This program is made available under the terms of the GPL version 2.
|
9
|
+
#
|
10
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
11
|
+
# usage examples.
|
12
|
+
#
|
13
|
+
#----------------------------------------------------------------------------
|
14
|
+
#
|
15
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
16
|
+
#
|
17
|
+
# Gmail: garbagecat10
|
18
|
+
#
|
19
|
+
# This program is free software; you can redistribute it and/or modify
|
20
|
+
# it under the terms of the GNU General Public License as published by
|
21
|
+
# the Free Software Foundation; either version 2 of the License, or
|
22
|
+
# (at your option) any later version.
|
23
|
+
#
|
24
|
+
# This program is distributed in the hope that it will be useful,
|
25
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
# GNU General Public License for more details.
|
28
|
+
#
|
29
|
+
# You should have received a copy of the GNU General Public License
|
30
|
+
# along with this program; if not, write to the Free Software
|
31
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
32
|
+
#
|
33
|
+
#---------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#
|
36
|
+
|
37
|
+
$:.unshift "../lib"
|
38
|
+
require 'eventmachine'
|
39
|
+
|
40
|
+
require 'test/unit/testsuite'
|
41
|
+
require 'test/unit/ui/console/testrunner'
|
42
|
+
|
43
|
+
|
44
|
+
class TestEventables < Test::Unit::TestCase
|
45
|
+
|
46
|
+
class EvTest
|
47
|
+
include EventMachine::Eventable
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_a
|
57
|
+
n = 0
|
58
|
+
tester = EvTest.new
|
59
|
+
tester.listen_event( :fire1 ) {|arg|
|
60
|
+
n = 1 if arg == "$"
|
61
|
+
EventMachine.stop
|
62
|
+
}
|
63
|
+
tester.post_event( :fire1, "$" )
|
64
|
+
|
65
|
+
EventMachine.run {
|
66
|
+
EventMachine::add_timer(1) {EventMachine.stop}
|
67
|
+
}
|
68
|
+
|
69
|
+
assert n == 1
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
#--------------------------------------
|
76
|
+
|
77
|
+
if __FILE__ == $0
|
78
|
+
runner = Test::Unit::UI::Console::TestRunner
|
79
|
+
suite = Test::Unit::TestSuite.new("name")
|
80
|
+
ObjectSpace.each_object(Class) do |testcase|
|
81
|
+
suite << testcase.suite if testcase < Test::Unit::TestCase
|
82
|
+
end
|
83
|
+
runner.run(suite)
|
84
|
+
end
|
85
|
+
|
data/tests/test_hc.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
# $Id: test_hc.rb 281 2006-11-20 03:17:22Z blackhedd $
|
2
|
+
#
|
3
|
+
# Author:: blackhedd (gmail address: garbagecat10).
|
4
|
+
# Date:: 8 Apr 2006
|
5
|
+
#
|
6
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# This program is made available under the terms of the GPL version 2.
|
9
|
+
#
|
10
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
11
|
+
# usage examples.
|
12
|
+
#
|
13
|
+
#----------------------------------------------------------------------------
|
14
|
+
#
|
15
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
16
|
+
#
|
17
|
+
# Gmail: garbagecat10
|
18
|
+
#
|
19
|
+
# This program is free software; you can redistribute it and/or modify
|
20
|
+
# it under the terms of the GNU General Public License as published by
|
21
|
+
# the Free Software Foundation; either version 2 of the License, or
|
22
|
+
# (at your option) any later version.
|
23
|
+
#
|
24
|
+
# This program is distributed in the hope that it will be useful,
|
25
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
+
# GNU General Public License for more details.
|
28
|
+
#
|
29
|
+
# You should have received a copy of the GNU General Public License
|
30
|
+
# along with this program; if not, write to the Free Software
|
31
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
32
|
+
#
|
33
|
+
#---------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#
|
36
|
+
|
37
|
+
$:.unshift "../lib"
|
38
|
+
require 'eventmachine'
|
39
|
+
|
40
|
+
class TestHeaderAndContentProtocol < Test::Unit::TestCase
|
41
|
+
|
42
|
+
TestHost = "127.0.0.1"
|
43
|
+
TestPort = 8905
|
44
|
+
|
45
|
+
|
46
|
+
#--------------------------------------------------------------------
|
47
|
+
|
48
|
+
class SimpleTest < EventMachine::Protocols::HeaderAndContentProtocol
|
49
|
+
attr_reader :first_header, :my_headers, :request
|
50
|
+
|
51
|
+
def receive_first_header_line hdr
|
52
|
+
@first_header ||= []
|
53
|
+
@first_header << hdr
|
54
|
+
end
|
55
|
+
def receive_headers hdrs
|
56
|
+
@my_headers ||= []
|
57
|
+
@my_headers << hdrs
|
58
|
+
end
|
59
|
+
def receive_request hdrs, content
|
60
|
+
@request ||= []
|
61
|
+
@request << [hdrs, content]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_no_content
|
66
|
+
Thread.abort_on_exception = true
|
67
|
+
the_connection = nil
|
68
|
+
EventMachine.run {
|
69
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
70
|
+
the_connection = conn
|
71
|
+
end
|
72
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
73
|
+
EventMachine.defer proc {
|
74
|
+
t = TCPSocket.new TestHost, TestPort
|
75
|
+
t.write [
|
76
|
+
"aaa\n", "bbb\r\n", "ccc\n", "\n"
|
77
|
+
].join
|
78
|
+
t.close
|
79
|
+
}, proc {
|
80
|
+
EventMachine.stop
|
81
|
+
}
|
82
|
+
}
|
83
|
+
assert_equal( ["aaa"], the_connection.first_header )
|
84
|
+
assert_equal( [%w(aaa bbb ccc)], the_connection.my_headers )
|
85
|
+
assert_equal( [[%w(aaa bbb ccc), ""]], the_connection.request )
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_content
|
89
|
+
Thread.abort_on_exception = true
|
90
|
+
the_connection = nil
|
91
|
+
content = "A" * 50
|
92
|
+
headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
|
93
|
+
EventMachine.run {
|
94
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
95
|
+
the_connection = conn
|
96
|
+
end
|
97
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
98
|
+
EventMachine.defer proc {
|
99
|
+
t = TCPSocket.new TestHost, TestPort
|
100
|
+
headers.each {|h| t.write "#{h}\r\n" }
|
101
|
+
t.write "\n"
|
102
|
+
t.write content
|
103
|
+
t.close
|
104
|
+
}, proc {
|
105
|
+
EventMachine.stop
|
106
|
+
}
|
107
|
+
}
|
108
|
+
assert_equal( ["aaa"], the_connection.first_header )
|
109
|
+
assert_equal( [headers], the_connection.my_headers )
|
110
|
+
assert_equal( [[headers, content]], the_connection.request )
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_several_requests
|
114
|
+
Thread.abort_on_exception = true
|
115
|
+
the_connection = nil
|
116
|
+
content = "A" * 50
|
117
|
+
headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
|
118
|
+
EventMachine.run {
|
119
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
120
|
+
the_connection = conn
|
121
|
+
end
|
122
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
123
|
+
EventMachine.defer proc {
|
124
|
+
t = TCPSocket.new TestHost, TestPort
|
125
|
+
5.times {
|
126
|
+
headers.each {|h| t.write "#{h}\r\n" }
|
127
|
+
t.write "\n"
|
128
|
+
t.write content
|
129
|
+
}
|
130
|
+
t.close
|
131
|
+
}, proc {
|
132
|
+
EventMachine.stop
|
133
|
+
}
|
134
|
+
}
|
135
|
+
assert_equal( ["aaa"] * 5, the_connection.first_header )
|
136
|
+
assert_equal( [headers] * 5, the_connection.my_headers )
|
137
|
+
assert_equal( [[headers, content]] * 5, the_connection.request )
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def x_test_multiple_content_length_headers
|
142
|
+
# This is supposed to throw a RuntimeError but it throws a C++ exception instead.
|
143
|
+
Thread.abort_on_exception = true
|
144
|
+
the_connection = nil
|
145
|
+
content = "A" * 50
|
146
|
+
headers = ["aaa", "bbb", ["Content-length: #{content.length}"]*2, "ccc"].flatten
|
147
|
+
EventMachine.run {
|
148
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
149
|
+
the_connection = conn
|
150
|
+
end
|
151
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
152
|
+
EventMachine.defer proc {
|
153
|
+
t = TCPSocket.new TestHost, TestPort
|
154
|
+
headers.each {|h| t.write "#{h}\r\n" }
|
155
|
+
t.write "\n"
|
156
|
+
t.write content
|
157
|
+
t.close
|
158
|
+
}, proc {
|
159
|
+
EventMachine.stop
|
160
|
+
}
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_interpret_headers
|
165
|
+
Thread.abort_on_exception = true
|
166
|
+
the_connection = nil
|
167
|
+
content = "A" * 50
|
168
|
+
headers = [
|
169
|
+
"GET / HTTP/1.0",
|
170
|
+
"Accept: aaa",
|
171
|
+
"User-Agent: bbb",
|
172
|
+
"Host: ccc",
|
173
|
+
"x-tempest-header:ddd"
|
174
|
+
]
|
175
|
+
EventMachine.run {
|
176
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
177
|
+
the_connection = conn
|
178
|
+
end
|
179
|
+
EventMachine.add_timer(4) {raise "test timed out"}
|
180
|
+
EventMachine.defer proc {
|
181
|
+
t = TCPSocket.new TestHost, TestPort
|
182
|
+
headers.each {|h| t.write "#{h}\r\n" }
|
183
|
+
t.write "\n"
|
184
|
+
t.write content
|
185
|
+
t.close
|
186
|
+
}, proc {
|
187
|
+
EventMachine.stop
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
hsh = the_connection.headers_2_hash( the_connection.my_headers.shift )
|
192
|
+
assert_equal(
|
193
|
+
{
|
194
|
+
:accept => "aaa",
|
195
|
+
:user_agent => "bbb",
|
196
|
+
:host => "ccc",
|
197
|
+
:x_tempest_header => "ddd"
|
198
|
+
},
|
199
|
+
hsh
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
#--------------------------------------------------------------------
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
|