eventmachine 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/COPYING +44 -265
  2. data/GNU +281 -0
  3. data/LEGAL +25 -0
  4. data/README +5 -3
  5. data/RELEASE_NOTES +7 -2
  6. data/ext/binder.cpp +8 -15
  7. data/ext/binder.h +8 -15
  8. data/ext/cmain.cpp +29 -15
  9. data/ext/ed.cpp +36 -43
  10. data/ext/ed.h +8 -15
  11. data/ext/em.cpp +116 -21
  12. data/ext/em.h +11 -16
  13. data/ext/emwin.cpp +9 -16
  14. data/ext/emwin.h +9 -16
  15. data/ext/eventmachine.h +9 -14
  16. data/ext/extconf.rb +9 -17
  17. data/ext/files.cpp +7 -14
  18. data/ext/files.h +7 -14
  19. data/ext/page.cpp +8 -15
  20. data/ext/page.h +8 -15
  21. data/ext/project.h +15 -15
  22. data/ext/rubymain.cpp +37 -16
  23. data/ext/sigs.cpp +8 -15
  24. data/ext/sigs.h +8 -15
  25. data/ext/ssl.cpp +8 -15
  26. data/ext/ssl.h +8 -15
  27. data/lib/em/deferrable.rb +40 -27
  28. data/lib/em/eventable.rb +12 -23
  29. data/lib/em/future.rb +62 -0
  30. data/lib/eventmachine.rb +156 -66
  31. data/lib/eventmachine_version.rb +12 -23
  32. data/lib/evma.rb +15 -18
  33. data/lib/evma/callback.rb +16 -19
  34. data/lib/evma/container.rb +17 -19
  35. data/lib/evma/factory.rb +16 -19
  36. data/lib/evma/protocol.rb +17 -19
  37. data/lib/evma/reactor.rb +17 -19
  38. data/lib/pr_eventmachine.rb +12 -23
  39. data/lib/protocols/buftok.rb +121 -0
  40. data/lib/protocols/header_and_content.rb +12 -23
  41. data/lib/protocols/httpclient.rb +44 -31
  42. data/lib/protocols/line_and_text.rb +97 -118
  43. data/lib/protocols/tcptest.rb +12 -22
  44. data/tests/test_basic.rb +14 -24
  45. data/tests/test_eventables.rb +14 -24
  46. data/tests/test_exc.rb +57 -0
  47. data/tests/test_futures.rb +136 -0
  48. data/tests/test_hc.rb +14 -24
  49. data/tests/test_httpclient.rb +106 -25
  50. data/tests/test_ltp.rb +14 -23
  51. data/tests/test_timers.rb +109 -0
  52. data/tests/test_ud.rb +14 -24
  53. metadata +11 -2
@@ -1,38 +1,28 @@
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.
1
+ # $Id: test_basic.rb 323 2007-05-22 22:22:43Z blackhedd $
9
2
  #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # 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
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
35
24
  #
25
+ #
36
26
 
37
27
  $:.unshift "../lib"
38
28
  require 'eventmachine'
@@ -1,38 +1,28 @@
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.
1
+ # $Id: test_eventables.rb 323 2007-05-22 22:22:43Z blackhedd $
9
2
  #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # 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
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
35
24
  #
25
+ #
36
26
 
37
27
  $:.unshift "../lib"
38
28
  require 'eventmachine'
@@ -0,0 +1,57 @@
1
+ # $Id: test_exc.rb 323 2007-05-22 22:22:43Z 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
+ $:.unshift "../lib"
27
+ require 'eventmachine'
28
+
29
+ class TestSomeExceptions < Test::Unit::TestCase
30
+
31
+
32
+ # Read the commentary in EventMachine#run.
33
+ # This test exercises the ensure block in #run that makes sure
34
+ # EventMachine#release_machine gets called even if an exception is
35
+ # thrown within the user code. Without the ensured call to release_machine,
36
+ # the second call to EventMachine#run will fail with a C++ exception
37
+ # because the machine wasn't cleaned up properly.
38
+
39
+ def test_a
40
+ assert_raise(RuntimeError) {
41
+ EventMachine.run {
42
+ raise "some exception"
43
+ }
44
+ }
45
+ end
46
+
47
+ def test_b
48
+ assert_raise(RuntimeError) {
49
+ EventMachine.run {
50
+ raise "some exception"
51
+ }
52
+ }
53
+ end
54
+
55
+
56
+ end
57
+
@@ -0,0 +1,136 @@
1
+ # $Id: test_futures.rb 323 2007-05-22 22:22:43Z 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
+
30
+
31
+
32
+ class TestFutures < Test::Unit::TestCase
33
+
34
+ def setup
35
+ end
36
+
37
+ def teardown
38
+ end
39
+
40
+ def test_future
41
+ assert_equal(100, EventMachine::Deferrable.future(100) )
42
+
43
+ p1 = proc { 100 + 1 }
44
+ assert_equal(101, EventMachine::Deferrable.future(p1) )
45
+ end
46
+
47
+
48
+
49
+ class MyFuture
50
+ include EventMachine::Deferrable
51
+ def initialize *args
52
+ super
53
+ set_deferred_status :succeeded, 40
54
+ end
55
+ end
56
+
57
+ class MyErrorFuture
58
+ include EventMachine::Deferrable
59
+ def initialize *args
60
+ super
61
+ set_deferred_status :failed, 41
62
+ end
63
+ end
64
+
65
+
66
+ def test_future_1
67
+ # Call future with one additional argument and it will be treated as a callback.
68
+ def my_future
69
+ MyFuture.new
70
+ end
71
+
72
+ value = nil
73
+ EventMachine::Deferrable.future my_future, proc {|v| value=v}
74
+ assert_equal( 40, value )
75
+ end
76
+
77
+
78
+ def test_future_2
79
+ # Call future with two additional arguments and they will be treated as a callback
80
+ # and an errback.
81
+ value = nil
82
+ EventMachine::Deferrable.future MyErrorFuture.new, nil, proc {|v| value=v}
83
+ assert_equal( 41, value )
84
+ end
85
+
86
+
87
+ def test_future_3
88
+ # Call future with no additional arguments but with a block, and the block will be
89
+ # treated as a callback.
90
+ value = nil
91
+ EventMachine::Deferrable.future MyFuture.new do |v|
92
+ value=v
93
+ end
94
+ assert_equal( 40, value )
95
+ end
96
+
97
+
98
+ class RecursiveCallback
99
+ include EventMachine::Deferrable
100
+ end
101
+
102
+ # A Deferrable callback can call #set_deferred_status to change the values
103
+ # passed to subsequent callbacks.
104
+ #
105
+ def test_recursive_callbacks
106
+ n = 0 # counter assures that all the tests actually run.
107
+ rc = RecursiveCallback.new
108
+ rc.callback {|a|
109
+ assert_equal(100, a)
110
+ n += 1
111
+ rc.set_deferred_status :succeeded, 101, 101
112
+ }
113
+ rc.callback {|a,b|
114
+ assert_equal(101, a)
115
+ assert_equal(101, b)
116
+ n += 1
117
+ rc.set_deferred_status :succeeded, 102, 102, 102
118
+ }
119
+ rc.callback {|a,b,c|
120
+ assert_equal(102, a)
121
+ assert_equal(102, b)
122
+ assert_equal(102, c)
123
+ n += 1
124
+ }
125
+ rc.set_deferred_status :succeeded, 100
126
+ assert_equal(3, n)
127
+ end
128
+
129
+ def test_syntactic_sugar
130
+ rc = RecursiveCallback.new
131
+ rc.set_deferred_success 100
132
+ rc.set_deferred_failure 200
133
+ end
134
+
135
+ end
136
+
@@ -1,38 +1,28 @@
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.
1
+ # $Id: test_hc.rb 323 2007-05-22 22:22:43Z blackhedd $
9
2
  #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # 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
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
35
24
  #
25
+ #
36
26
 
37
27
  $:.unshift "../lib"
38
28
  require 'eventmachine'
@@ -1,44 +1,37 @@
1
- # $Id: test_httpclient.rb 226 2006-08-10 08:55:49Z 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.
1
+ # $Id: test_httpclient.rb 323 2007-05-22 22:22:43Z blackhedd $
9
2
  #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # 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
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
35
24
  #
25
+ #
36
26
 
37
27
  $:.unshift "../lib"
38
28
  require 'eventmachine'
39
29
 
40
30
  class TestHttpClient < Test::Unit::TestCase
41
31
 
32
+ Localhost = "127.0.0.1"
33
+ Localport = 9801
34
+
42
35
  def setup
43
36
  end
44
37
 
@@ -79,7 +72,6 @@ class TestHttpClient < Test::Unit::TestCase
79
72
  EventMachine.run {
80
73
  c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
81
74
  c.callback {|result|
82
- p result
83
75
  ok = true;
84
76
  EventMachine.stop
85
77
  }
@@ -89,6 +81,95 @@ p result
89
81
  end
90
82
 
91
83
 
84
+ #-----------------------------------------
85
+
86
+ # Test a server that returns a page with a zero content-length.
87
+ # This caused an early version of the HTTP client not to generate a response,
88
+ # causing this test to hang. Observe, there was no problem with responses
89
+ # lacking a content-length, just when the content-length was zero.
90
+ #
91
+ class EmptyContent < EventMachine::Connection
92
+ def initialize *args
93
+ super
94
+ end
95
+ def receive_data data
96
+ send_data "HTTP/1.0 404 ...\r\nContent-length: 0\r\n\r\n"
97
+ close_connection_after_writing
98
+ end
99
+ end
100
+
101
+ def test_http_empty_content
102
+ ok = false
103
+ EventMachine.run {
104
+ EventMachine.start_server "127.0.0.1", 9701, EmptyContent
105
+ c = EventMachine::Protocols::HttpClient.send :request, :host => "127.0.0.1", :port => 9701
106
+ c.callback {|result|
107
+ ok = true
108
+ EventMachine.stop
109
+ }
110
+ }
111
+ assert ok
112
+ end
113
+
114
+ #---------------------------------------
115
+
116
+ class PostContent < EventMachine::Protocols::LineAndTextProtocol
117
+ def initialize *args
118
+ super
119
+ @lines = []
120
+ end
121
+ def receive_line line
122
+ if line.length > 0
123
+ @lines << line
124
+ else
125
+ process_headers
126
+ end
127
+ end
128
+ def receive_binary_data data
129
+ @post_content = data
130
+ send_response
131
+ end
132
+ def process_headers
133
+ if @lines.first =~ /\APOST ([^\s]+) HTTP\/1.1\Z/
134
+ @uri = $1.dup
135
+ else
136
+ raise "bad request"
137
+ end
138
+ @lines.each {|line|
139
+ if line =~ /\AContent-length:\s*(\d+)\Z/i
140
+ @content_length = $1.dup.to_i
141
+ elsif line =~ /\AContent-type:\s*(\d+)\Z/i
142
+ @content_type = $1.dup
143
+ end
144
+ }
145
+
146
+ raise "invalid content length" unless @content_length
147
+ set_binary_mode @content_length
148
+ end
149
+ def send_response
150
+ send_data "HTTP/1.1 200 ...\r\nConnection: close\r\nContent-length: 10\r\nContent-type: text/html\r\n\r\n0123456789"
151
+ close_connection_after_writing
152
+ end
153
+ end
154
+
155
+ def test_post
156
+ response = nil
157
+ EventMachine.run {
158
+ EventMachine.start_server Localhost, Localport, PostContent
159
+ EventMachine.add_timer(2) {raise "timed out"}
160
+ c = EventMachine::Protocols::HttpClient.request :host=>Localhost,
161
+ :port=>Localport, :method=>:post, :request=>"/aaa", :content=>"XYZ",
162
+ :content_type=>"text/plain"
163
+ c.callback {|r|
164
+ response = r
165
+ EventMachine.stop
166
+ }
167
+ }
168
+
169
+ assert_equal( 200, response[:status] )
170
+ assert_equal( "0123456789", response[:content] )
171
+ end
172
+
92
173
  end
93
174
 
94
175