eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. data/{docs/README → README} +21 -13
  2. data/Rakefile +14 -4
  3. data/docs/DEFERRABLES +0 -5
  4. data/docs/INSTALL +2 -4
  5. data/docs/LEGAL +1 -1
  6. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
  7. data/docs/PURE_RUBY +0 -2
  8. data/docs/RELEASE_NOTES +0 -2
  9. data/docs/SMTP +0 -7
  10. data/docs/SPAWNED_PROCESSES +0 -4
  11. data/docs/TODO +0 -2
  12. data/eventmachine.gemspec +41 -32
  13. data/examples/ex_channel.rb +43 -0
  14. data/examples/ex_queue.rb +2 -0
  15. data/examples/helper.rb +2 -0
  16. data/ext/cmain.cpp +685 -586
  17. data/ext/cplusplus.cpp +15 -6
  18. data/ext/ed.cpp +1732 -1522
  19. data/ext/ed.h +407 -380
  20. data/ext/em.cpp +2263 -1937
  21. data/ext/em.h +223 -186
  22. data/ext/eventmachine.h +111 -98
  23. data/ext/eventmachine_cpp.h +1 -0
  24. data/ext/extconf.rb +4 -0
  25. data/ext/kb.cpp +81 -82
  26. data/ext/pipe.cpp +349 -351
  27. data/ext/project.h +21 -0
  28. data/ext/rubymain.cpp +1047 -847
  29. data/ext/ssl.cpp +38 -1
  30. data/ext/ssl.h +5 -1
  31. data/java/src/com/rubyeventmachine/Application.java +7 -3
  32. data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
  33. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
  34. data/lib/{protocols → em}/buftok.rb +16 -5
  35. data/lib/em/callback.rb +26 -0
  36. data/lib/em/channel.rb +57 -0
  37. data/lib/em/connection.rb +505 -0
  38. data/lib/em/deferrable.rb +144 -165
  39. data/lib/em/file_watch.rb +54 -0
  40. data/lib/em/future.rb +24 -25
  41. data/lib/em/messages.rb +1 -1
  42. data/lib/em/process_watch.rb +44 -0
  43. data/lib/em/processes.rb +119 -113
  44. data/lib/em/protocols.rb +35 -0
  45. data/lib/em/protocols/header_and_content.rb +138 -0
  46. data/lib/em/protocols/httpclient.rb +263 -0
  47. data/lib/em/protocols/httpclient2.rb +582 -0
  48. data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
  49. data/lib/em/protocols/linetext2.rb +160 -0
  50. data/lib/{protocols → em/protocols}/memcache.rb +37 -7
  51. data/lib/em/protocols/object_protocol.rb +39 -0
  52. data/lib/em/protocols/postgres3.rb +247 -0
  53. data/lib/em/protocols/saslauth.rb +175 -0
  54. data/lib/em/protocols/smtpclient.rb +331 -0
  55. data/lib/em/protocols/smtpserver.rb +547 -0
  56. data/lib/em/protocols/stomp.rb +200 -0
  57. data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
  58. data/lib/em/queue.rb +61 -0
  59. data/lib/em/spawnable.rb +53 -56
  60. data/lib/em/streamer.rb +92 -74
  61. data/lib/em/timers.rb +55 -0
  62. data/lib/em/version.rb +3 -0
  63. data/lib/eventmachine.rb +1636 -1926
  64. data/lib/evma.rb +1 -1
  65. data/lib/jeventmachine.rb +106 -101
  66. data/lib/pr_eventmachine.rb +47 -36
  67. data/tasks/project.rake +2 -1
  68. data/tests/client.crt +31 -0
  69. data/tests/client.key +51 -0
  70. data/tests/test_attach.rb +18 -0
  71. data/tests/test_basic.rb +285 -231
  72. data/tests/test_channel.rb +63 -0
  73. data/tests/test_connection_count.rb +2 -2
  74. data/tests/test_epoll.rb +162 -163
  75. data/tests/test_errors.rb +36 -36
  76. data/tests/test_exc.rb +22 -25
  77. data/tests/test_file_watch.rb +49 -0
  78. data/tests/test_futures.rb +77 -93
  79. data/tests/test_hc.rb +2 -2
  80. data/tests/test_httpclient.rb +55 -52
  81. data/tests/test_httpclient2.rb +153 -155
  82. data/tests/test_inactivity_timeout.rb +30 -0
  83. data/tests/test_kb.rb +8 -9
  84. data/tests/test_ltp2.rb +274 -277
  85. data/tests/test_next_tick.rb +135 -109
  86. data/tests/test_object_protocol.rb +37 -0
  87. data/tests/test_process_watch.rb +48 -0
  88. data/tests/test_processes.rb +128 -95
  89. data/tests/test_proxy_connection.rb +92 -0
  90. data/tests/test_pure.rb +1 -5
  91. data/tests/test_queue.rb +44 -0
  92. data/tests/test_running.rb +9 -14
  93. data/tests/test_sasl.rb +32 -34
  94. data/tests/test_send_file.rb +175 -176
  95. data/tests/test_servers.rb +37 -41
  96. data/tests/test_smtpserver.rb +47 -55
  97. data/tests/test_spawn.rb +284 -291
  98. data/tests/test_ssl_args.rb +1 -1
  99. data/tests/test_ssl_methods.rb +1 -1
  100. data/tests/test_ssl_verify.rb +82 -0
  101. data/tests/test_timers.rb +81 -88
  102. data/tests/test_ud.rb +0 -7
  103. data/tests/testem.rb +1 -1
  104. metadata +52 -36
  105. data/lib/em/eventable.rb +0 -39
  106. data/lib/eventmachine_version.rb +0 -31
  107. data/lib/protocols/header_and_content.rb +0 -129
  108. data/lib/protocols/httpcli2.rb +0 -803
  109. data/lib/protocols/httpclient.rb +0 -270
  110. data/lib/protocols/linetext2.rb +0 -161
  111. data/lib/protocols/postgres.rb +0 -261
  112. data/lib/protocols/saslauth.rb +0 -179
  113. data/lib/protocols/smtpclient.rb +0 -308
  114. data/lib/protocols/smtpserver.rb +0 -556
  115. data/lib/protocols/stomp.rb +0 -153
  116. data/tests/test_eventables.rb +0 -77
data/tests/test_attach.rb CHANGED
@@ -80,4 +80,22 @@ class TestAttach < Test::Unit::TestCase
80
80
 
81
81
  assert_equal $read, "ghi\n"
82
82
  end
83
+
84
+ module PipeReader
85
+ def receive_data data
86
+ $read = data
87
+ EM.stop
88
+ end
89
+ end
90
+
91
+ def test_read_write_pipe
92
+ EM.run{
93
+ $r, $w = IO.pipe
94
+ EM.attach $r, PipeReader
95
+ writer = EM.attach($w)
96
+ writer.send_data 'ghi'
97
+ }
98
+
99
+ assert_equal $read, "ghi"
100
+ end
83
101
  end
data/tests/test_basic.rb CHANGED
@@ -1,231 +1,285 @@
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
- $:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
28
- require 'eventmachine'
29
- require 'test/unit'
30
-
31
- class TestBasic < Test::Unit::TestCase
32
-
33
- def setup
34
- assert(!EM.reactor_running?)
35
- end
36
-
37
- def teardown
38
- assert(!EM.reactor_running?)
39
- end
40
-
41
- #-------------------------------------
42
-
43
- def test_libtype
44
- lt = EventMachine.library_type
45
- em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
46
-
47
- # Running from test runner, under jruby.
48
- if RUBY_PLATFORM == 'java'
49
- unless em_lib == :pure_ruby
50
- assert_equal( :java, lt )
51
- return
52
- end
53
- end
54
-
55
- case em_lib
56
- when :pure_ruby
57
- assert_equal( :pure_ruby, lt )
58
- when :extension
59
- assert_equal( :extension, lt )
60
- when :java
61
- assert_equal( :java, lt )
62
- else
63
- # Running from jruby as a standalone test.
64
- if RUBY_PLATFORM == 'java'
65
- assert_equal( :java, lt )
66
- else
67
- assert_equal( :extension, lt )
68
- end
69
- end
70
- end
71
-
72
- #-------------------------------------
73
-
74
-
75
- def test_em
76
- EventMachine.run {
77
- EventMachine.add_timer 0 do
78
- EventMachine.stop
79
- end
80
- }
81
- end
82
-
83
- #-------------------------------------
84
-
85
- def test_timer
86
- n = 0
87
- EventMachine.run {
88
- EventMachine.add_periodic_timer(0.1) {
89
- n += 1
90
- EventMachine.stop if n == 2
91
- }
92
- }
93
- end
94
-
95
- #-------------------------------------
96
-
97
- # This test once threw an already-running exception.
98
- module Trivial
99
- def post_init
100
- EventMachine.stop
101
- end
102
- end
103
-
104
- def test_server
105
- EventMachine.run {
106
- EventMachine.start_server "localhost", 9000, Trivial
107
- EventMachine.connect "localhost", 9000
108
- }
109
- assert( true ) # make sure it halts
110
- end
111
-
112
- #--------------------------------------
113
-
114
- # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
115
- # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
116
- # even after the supplied block completes.
117
- def test_run_block
118
- assert !EM.reactor_running?
119
- a = nil
120
- EM.run_block { a = "Worked" }
121
- assert a
122
- assert !EM.reactor_running?
123
- end
124
-
125
-
126
- #--------------------------------------
127
-
128
- # TODO! This is an unfinished edge case.
129
- # EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers.
130
- # A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure
131
- # block in EM::run). But if EM is processing an unbind request, the release_machine call
132
- # will cause a segmentation fault.
133
- #
134
-
135
- TestHost = "127.0.0.1"
136
- TestPort = 9070
137
-
138
- class UnbindError < EM::Connection
139
- def initialize *args
140
- super
141
- end
142
- def connection_completed
143
- close_connection_after_writing
144
- end
145
- def unbind
146
- raise "Blooey"
147
- end
148
- end
149
-
150
- def xxx_test_unbind_error
151
- assert_raises( RuntimeError ) {
152
- EM.run {
153
- EM.start_server TestHost, TestPort
154
- EM.connect TestHost, TestPort, UnbindError
155
- }
156
- }
157
- end
158
-
159
- #------------------------------------
160
- #
161
- # TODO. This is an unfinished bug fix.
162
- # This case was originally reported by Dan Aquino. If you throw a Ruby exception
163
- # in a post_init handler, it gets rethrown as a confusing reactor exception.
164
- # The problem is in eventmachine.rb, which calls post_init within the private
165
- # initialize method of the EM::Connection class. This happens in both the EM::connect
166
- # method and in the code that responds to connection-accepted events.
167
- # What happens is that we instantiate the new connection object, which calls
168
- # initialize, and then after initialize returns, we stick the new connection object
169
- # into EM's @conns hashtable.
170
- # But the problem is that Connection::initialize calls #post_init before it returns,
171
- # and this may be user-written code that may throw an uncaught Ruby exception.
172
- # If that happens, the reactor will abort, and it will then try to run down open
173
- # connections. Because @conns never got a chance to properly reflect the new connection
174
- # (because initialize never returned), we throw a ConnectionNotBound error
175
- # (eventmachine.rb line 1080).
176
- # When the bug is fixed, activate this test case.
177
- #
178
-
179
- class PostInitError < EM::Connection
180
- def post_init
181
- aaa bbb # should produce a Ruby exception
182
- end
183
- end
184
- # This test causes issues, the machine becomes unreleasable after
185
- # release_machine suffers an exception in event_callback.
186
- def xxx_test_post_init_error
187
- assert_raises( EventMachine::ConnectionNotBound ) {
188
- EM.run {
189
- EM::Timer.new(1) {EM.stop}
190
- EM.start_server TestHost, TestPort
191
- EM.connect TestHost, TestPort, PostInitError
192
- }
193
- }
194
- EM.run {
195
- EM.stop
196
- }
197
- assert !EM.reactor_running?
198
- end
199
-
200
- module BrsTestSrv
201
- def receive_data data
202
- $received << data
203
- end
204
- def unbind
205
- EM.stop
206
- end
207
- end
208
- module BrsTestCli
209
- def post_init
210
- send_data $sent
211
- close_connection_after_writing
212
- end
213
- end
214
-
215
- # From ticket #50
216
- def test_byte_range_send
217
- $received = ''
218
- $sent = (0..255).to_a.pack('C*')
219
- EM::run {
220
-
221
- EM::start_server TestHost, TestPort, BrsTestSrv
222
-
223
- EM::connect TestHost, TestPort, BrsTestCli
224
-
225
- EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
226
- }
227
- assert_equal($sent, $received)
228
- end
229
-
230
- end
231
-
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
+ $:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
28
+ require 'eventmachine'
29
+ require 'socket'
30
+ require 'test/unit'
31
+
32
+ class TestBasic < Test::Unit::TestCase
33
+
34
+ def setup
35
+ assert(!EM.reactor_running?)
36
+ end
37
+
38
+ def teardown
39
+ assert(!EM.reactor_running?)
40
+ end
41
+
42
+ #-------------------------------------
43
+
44
+ def test_libtype
45
+ lt = EventMachine.library_type
46
+ em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
47
+
48
+ # Running from test runner, under jruby.
49
+ if RUBY_PLATFORM == 'java'
50
+ unless em_lib == :pure_ruby
51
+ assert_equal( :java, lt )
52
+ return
53
+ end
54
+ end
55
+
56
+ case em_lib
57
+ when :pure_ruby
58
+ assert_equal( :pure_ruby, lt )
59
+ when :extension
60
+ assert_equal( :extension, lt )
61
+ when :java
62
+ assert_equal( :java, lt )
63
+ else
64
+ # Running from jruby as a standalone test.
65
+ if RUBY_PLATFORM == 'java'
66
+ assert_equal( :java, lt )
67
+ else
68
+ assert_equal( :extension, lt )
69
+ end
70
+ end
71
+ end
72
+
73
+ #-------------------------------------
74
+
75
+
76
+ def test_em
77
+ EventMachine.run {
78
+ EventMachine.add_timer 0 do
79
+ EventMachine.stop
80
+ end
81
+ }
82
+ end
83
+
84
+ #-------------------------------------
85
+
86
+ def test_timer
87
+ n = 0
88
+ EventMachine.run {
89
+ EventMachine.add_periodic_timer(0.1) {
90
+ n += 1
91
+ EventMachine.stop if n == 2
92
+ }
93
+ }
94
+ end
95
+
96
+ #-------------------------------------
97
+
98
+ # This test once threw an already-running exception.
99
+ module Trivial
100
+ def post_init
101
+ EventMachine.stop
102
+ end
103
+ end
104
+
105
+ def test_server
106
+ EventMachine.run {
107
+ EventMachine.start_server "localhost", 9000, Trivial
108
+ EventMachine.connect "localhost", 9000
109
+ }
110
+ assert( true ) # make sure it halts
111
+ end
112
+
113
+ #--------------------------------------
114
+
115
+ # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
116
+ # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
117
+ # even after the supplied block completes.
118
+ def test_run_block
119
+ assert !EM.reactor_running?
120
+ a = nil
121
+ EM.run_block { a = "Worked" }
122
+ assert a
123
+ assert !EM.reactor_running?
124
+ end
125
+
126
+
127
+ #--------------------------------------
128
+
129
+ # TODO! This is an unfinished edge case.
130
+ # EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers.
131
+ # A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure
132
+ # block in EM::run). But if EM is processing an unbind request, the release_machine call
133
+ # will cause a segmentation fault.
134
+ #
135
+
136
+ TestHost = "127.0.0.1"
137
+ TestPort = 9070
138
+
139
+ class UnbindError < EM::Connection
140
+ def initialize *args
141
+ super
142
+ end
143
+ def connection_completed
144
+ close_connection_after_writing
145
+ end
146
+ def unbind
147
+ raise "Blooey"
148
+ end
149
+ end
150
+
151
+ def xxx_test_unbind_error
152
+ assert_raises( RuntimeError ) {
153
+ EM.run {
154
+ EM.start_server TestHost, TestPort
155
+ EM.connect TestHost, TestPort, UnbindError
156
+ }
157
+ }
158
+ end
159
+
160
+ #------------------------------------
161
+ #
162
+ # TODO. This is an unfinished bug fix.
163
+ # This case was originally reported by Dan Aquino. If you throw a Ruby exception
164
+ # in a post_init handler, it gets rethrown as a confusing reactor exception.
165
+ # The problem is in eventmachine.rb, which calls post_init within the private
166
+ # initialize method of the EM::Connection class. This happens in both the EM::connect
167
+ # method and in the code that responds to connection-accepted events.
168
+ # What happens is that we instantiate the new connection object, which calls
169
+ # initialize, and then after initialize returns, we stick the new connection object
170
+ # into EM's @conns hashtable.
171
+ # But the problem is that Connection::initialize calls #post_init before it returns,
172
+ # and this may be user-written code that may throw an uncaught Ruby exception.
173
+ # If that happens, the reactor will abort, and it will then try to run down open
174
+ # connections. Because @conns never got a chance to properly reflect the new connection
175
+ # (because initialize never returned), we throw a ConnectionNotBound error
176
+ # (eventmachine.rb line 1080).
177
+ # When the bug is fixed, activate this test case.
178
+ #
179
+
180
+ class PostInitError < EM::Connection
181
+ def post_init
182
+ aaa bbb # should produce a Ruby exception
183
+ end
184
+ end
185
+ # This test causes issues, the machine becomes unreleasable after
186
+ # release_machine suffers an exception in event_callback.
187
+ def xxx_test_post_init_error
188
+ assert_raises( EventMachine::ConnectionNotBound ) {
189
+ EM.run {
190
+ EM::Timer.new(1) {EM.stop}
191
+ EM.start_server TestHost, TestPort
192
+ EM.connect TestHost, TestPort, PostInitError
193
+ }
194
+ }
195
+ EM.run {
196
+ EM.stop
197
+ }
198
+ assert !EM.reactor_running?
199
+ end
200
+
201
+ module BrsTestSrv
202
+ def receive_data data
203
+ $received << data
204
+ end
205
+ def unbind
206
+ EM.stop
207
+ end
208
+ end
209
+ module BrsTestCli
210
+ def post_init
211
+ send_data $sent
212
+ close_connection_after_writing
213
+ end
214
+ end
215
+
216
+ # From ticket #50
217
+ def test_byte_range_send
218
+ $received = ''
219
+ $sent = (0..255).to_a.pack('C*')
220
+ EM::run {
221
+ EM::start_server TestHost, TestPort, BrsTestSrv
222
+ EM::connect TestHost, TestPort, BrsTestCli
223
+
224
+ EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
225
+ }
226
+ assert_equal($sent, $received)
227
+ end
228
+
229
+ def test_bind_connect
230
+ local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
231
+
232
+ bind_port = rand(33333)+1025
233
+
234
+ test = self
235
+ EM.run do
236
+ EM.start_server(TestHost, TestPort, Module.new do
237
+ define_method :post_init do
238
+ begin
239
+ test.assert_equal bind_port, Socket.unpack_sockaddr_in(get_peername).first
240
+ test.assert_equal local_ip, Socket.unpack_sockaddr_in(get_peername).last
241
+ ensure
242
+ EM.stop_event_loop
243
+ end
244
+ end
245
+ end)
246
+ EM.bind_connect local_ip, bind_port, TestHost, TestPort
247
+ end
248
+ end
249
+
250
+ def test_reactor_thread?
251
+ assert !EM.reactor_thread?
252
+ EM.run { assert EM.reactor_thread?; EM.stop }
253
+ assert !EM.reactor_thread?
254
+ end
255
+
256
+ def test_schedule_on_reactor_thread
257
+ x = false
258
+ EM.run do
259
+ EM.schedule { x = true }
260
+ EM.stop
261
+ end
262
+ assert x
263
+ end
264
+
265
+ def test_schedule_from_thread
266
+ x = false
267
+ assert !x
268
+ EM.run do
269
+ Thread.new { EM.schedule { x = true } }.join
270
+ EM.stop
271
+ end
272
+ assert x
273
+ end
274
+
275
+ def test_set_heartbeat_interval
276
+ interval = 0.5
277
+ EM.run {
278
+ EM.set_heartbeat_interval interval
279
+ $interval = EM.get_heartbeat_interval
280
+ EM.stop
281
+ }
282
+ assert_equal(interval, $interval)
283
+ end
284
+ end
285
+