eventmachine 0.12.10 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +1 -0
  3. data/README +1 -2
  4. data/Rakefile +4 -76
  5. data/docs/DEFERRABLES +183 -70
  6. data/docs/KEYBOARD +15 -11
  7. data/docs/LIGHTWEIGHT_CONCURRENCY +84 -24
  8. data/docs/SMTP +3 -1
  9. data/docs/SPAWNED_PROCESSES +84 -25
  10. data/eventmachine.gemspec +19 -26
  11. data/examples/ex_tick_loop_array.rb +15 -0
  12. data/examples/ex_tick_loop_counter.rb +32 -0
  13. data/ext/binder.cpp +0 -1
  14. data/ext/cmain.cpp +36 -11
  15. data/ext/cplusplus.cpp +1 -1
  16. data/ext/ed.cpp +104 -113
  17. data/ext/ed.h +24 -30
  18. data/ext/em.cpp +347 -248
  19. data/ext/em.h +23 -16
  20. data/ext/eventmachine.h +5 -3
  21. data/ext/extconf.rb +5 -3
  22. data/ext/fastfilereader/extconf.rb +5 -3
  23. data/ext/fastfilereader/mapper.cpp +1 -1
  24. data/ext/kb.cpp +1 -3
  25. data/ext/pipe.cpp +9 -11
  26. data/ext/project.h +12 -4
  27. data/ext/rubymain.cpp +138 -89
  28. data/java/src/com/rubyeventmachine/EmReactor.java +1 -0
  29. data/lib/em/channel.rb +1 -1
  30. data/lib/em/connection.rb +6 -1
  31. data/lib/em/deferrable.rb +16 -2
  32. data/lib/em/iterator.rb +270 -0
  33. data/lib/em/protocols.rb +1 -1
  34. data/lib/em/protocols/httpclient.rb +5 -0
  35. data/lib/em/protocols/line_protocol.rb +28 -0
  36. data/lib/em/protocols/smtpserver.rb +101 -8
  37. data/lib/em/protocols/stomp.rb +1 -1
  38. data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +1 -11
  39. data/lib/em/queue.rb +1 -0
  40. data/lib/em/streamer.rb +1 -1
  41. data/lib/em/tick_loop.rb +85 -0
  42. data/lib/em/timers.rb +2 -1
  43. data/lib/em/version.rb +1 -1
  44. data/lib/eventmachine.rb +38 -84
  45. data/lib/jeventmachine.rb +1 -0
  46. data/tests/test_attach.rb +13 -3
  47. data/tests/test_basic.rb +60 -95
  48. data/tests/test_channel.rb +3 -2
  49. data/tests/test_defer.rb +14 -12
  50. data/tests/test_deferrable.rb +35 -0
  51. data/tests/test_file_watch.rb +1 -1
  52. data/tests/test_futures.rb +1 -1
  53. data/tests/test_hc.rb +40 -68
  54. data/tests/test_httpclient.rb +15 -6
  55. data/tests/test_httpclient2.rb +3 -2
  56. data/tests/test_inactivity_timeout.rb +3 -3
  57. data/tests/test_ltp.rb +13 -5
  58. data/tests/test_next_tick.rb +1 -1
  59. data/tests/test_pending_connect_timeout.rb +2 -2
  60. data/tests/test_process_watch.rb +36 -34
  61. data/tests/test_proxy_connection.rb +52 -0
  62. data/tests/test_pure.rb +10 -1
  63. data/tests/test_sasl.rb +1 -1
  64. data/tests/test_send_file.rb +16 -7
  65. data/tests/test_servers.rb +1 -1
  66. data/tests/test_tick_loop.rb +59 -0
  67. data/tests/test_timers.rb +13 -15
  68. metadata +45 -17
  69. data/web/whatis +0 -7
@@ -29,6 +29,40 @@ class TestProxyConnection < Test::Unit::TestCase
29
29
  end
30
30
  end
31
31
 
32
+ module PartialProxyConnection
33
+ def initialize(client, request, length)
34
+ @client, @request, @length = client, request, length
35
+ end
36
+
37
+ def post_init
38
+ EM::enable_proxy(self, @client, 0, @length)
39
+ end
40
+
41
+ def receive_data(data)
42
+ $unproxied_data = data
43
+ @client.send_data(data)
44
+ end
45
+
46
+ def connection_completed
47
+ EM.next_tick {
48
+ send_data @request
49
+ }
50
+ end
51
+
52
+ def proxy_target_unbound
53
+ $unbound_early = true
54
+ EM.stop
55
+ end
56
+
57
+ def proxy_completed
58
+ $proxy_completed = true
59
+ end
60
+
61
+ def unbind
62
+ @client.close_connection_after_writing
63
+ end
64
+ end
65
+
32
66
  module Client
33
67
  def connection_completed
34
68
  send_data "EventMachine rocks!"
@@ -61,6 +95,12 @@ class TestProxyConnection < Test::Unit::TestCase
61
95
  end
62
96
  end
63
97
 
98
+ module PartialProxyServer
99
+ def receive_data(data)
100
+ EM.connect("127.0.0.1", 54321, PartialProxyConnection, self, data, 1)
101
+ end
102
+ end
103
+
64
104
  module EarlyClosingProxy
65
105
  def receive_data(data)
66
106
  EM.connect("127.0.0.1", 54321, ProxyConnection, self, data)
@@ -78,6 +118,18 @@ class TestProxyConnection < Test::Unit::TestCase
78
118
  assert_equal("I know!", $client_data)
79
119
  end
80
120
 
121
+ def test_partial_proxy_connection
122
+ EM.run {
123
+ EM.start_server("127.0.0.1", 54321, Server)
124
+ EM.start_server("127.0.0.1", 12345, PartialProxyServer)
125
+ EM.connect("127.0.0.1", 12345, Client)
126
+ }
127
+
128
+ assert_equal("I know!", $client_data)
129
+ assert_equal(" know!", $unproxied_data)
130
+ assert($proxy_completed)
131
+ end
132
+
81
133
  def test_early_close
82
134
  $client_data = nil
83
135
  EM.run {
@@ -108,10 +108,19 @@ class TestPure < Test::Unit::TestCase
108
108
  EM.run {
109
109
  EM.start_server "0.0.0.0", 60002
110
110
  EM.connect "0.0.0.0", 60002, TestConnaccepted
111
- EM::Timer.new(1) {timeout = true; EM.stop}
111
+ setup_timeout(1)
112
112
  }
113
113
  assert_equal( false, timeout )
114
114
  end
115
+
116
+ def setup_timeout(timeout = 4)
117
+ EM.schedule {
118
+ start_time = EM.current_time
119
+ EM.add_periodic_timer(0.01) {
120
+ raise "timeout" if EM.current_time - start_time >= timeout
121
+ }
122
+ }
123
+ end
115
124
 
116
125
  def test_reactor_running
117
126
  a = false
@@ -56,7 +56,7 @@ class TestSASL < Test::Unit::TestCase
56
56
 
57
57
  c = EM.connect( Host, Port, SaslClient )
58
58
  d = c.validate?( TestUser, TestPsw )
59
- d.timeout 2
59
+ d.timeout 1
60
60
  d.callback {
61
61
  resp = true
62
62
  EM.stop
@@ -63,6 +63,15 @@ class TestSendFile < Test::Unit::TestCase
63
63
  File.unlink( TestFilename ) if File.exist?( TestFilename )
64
64
  end
65
65
 
66
+ def setup_timeout(timeout = 4)
67
+ EM.schedule {
68
+ start_time = EM.current_time
69
+ EM.add_periodic_timer(0.01) {
70
+ raise "timeout" if EM.current_time - start_time >= timeout
71
+ }
72
+ }
73
+ end
74
+
66
75
  def test_send_file
67
76
  File.open( TestFilename, "w" ) {|f|
68
77
  f << ("A" * 5000)
@@ -72,7 +81,7 @@ class TestSendFile < Test::Unit::TestCase
72
81
 
73
82
  EM.run {
74
83
  EM.start_server TestHost, TestPort, TestModule
75
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
84
+ setup_timeout
76
85
 
77
86
  EM.connect TestHost, TestPort, TestClient do |c|
78
87
  c.data_to { |d| data << d }
@@ -95,7 +104,7 @@ class TestSendFile < Test::Unit::TestCase
95
104
  assert_raises( ex_class ) {
96
105
  EM.run {
97
106
  EM.start_server TestHost, TestPort, TestModule
98
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
107
+ setup_timeout
99
108
  EM.connect TestHost, TestPort, TestClient do |c|
100
109
  c.data_to { |d| data << d }
101
110
  end
@@ -131,7 +140,7 @@ class TestSendFile < Test::Unit::TestCase
131
140
 
132
141
  EM.run {
133
142
  EM.start_server TestHost, TestPort, StreamTestModule
134
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
143
+ setup_timeout
135
144
  EM.connect TestHost, TestPort, TestClient do |c|
136
145
  c.data_to { |d| data << d }
137
146
  end
@@ -151,7 +160,7 @@ class TestSendFile < Test::Unit::TestCase
151
160
 
152
161
  EM.run {
153
162
  EM.start_server TestHost, TestPort, ChunkStreamTestModule
154
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
163
+ setup_timeout
155
164
  EM.connect TestHost, TestPort, TestClient do |c|
156
165
  c.data_to { |d| data << d }
157
166
  end
@@ -175,7 +184,7 @@ class TestSendFile < Test::Unit::TestCase
175
184
  data = ''
176
185
  EM.run {
177
186
  EM.start_server TestHost, TestPort, BadFileTestModule
178
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
187
+ setup_timeout
179
188
  EM.connect TestHost, TestPort, TestClient do |c|
180
189
  c.data_to { |d| data << d }
181
190
  end
@@ -198,7 +207,7 @@ class TestSendFile < Test::Unit::TestCase
198
207
 
199
208
  EM.run {
200
209
  EM.start_server TestHost, TestPort, StreamTestModule
201
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
210
+ setup_timeout
202
211
  EM.connect TestHost, TestPort, TestClient do |c|
203
212
  c.data_to { |d| data << d }
204
213
  end
@@ -223,7 +232,7 @@ class TestSendFile < Test::Unit::TestCase
223
232
 
224
233
  EM.run {
225
234
  EM.start_server TestHost, TestPort, ChunkStreamTestModule
226
- EM.add_timer(2) {EM.stop} # avoid hanging in case of error
235
+ setup_timeout
227
236
  EM.connect TestHost, TestPort, TestClient do |c|
228
237
  c.data_to { |d| data << d }
229
238
  end
@@ -61,7 +61,7 @@ class TestServers < Test::Unit::TestCase
61
61
  assert(grep_netstat(LocalTcpRexp).grep(%r(#{Port})).size >= 1, "Server didn't start")
62
62
  EM.stop_server sig
63
63
  # Give the server some time to shutdown.
64
- EM.add_timer(0.1) {
64
+ EM.add_timer(0.2) {
65
65
  assert(grep_netstat(LocalTcpRexp).grep(%r(#{Port})).empty?, "Servers didn't stop")
66
66
  EM.stop
67
67
  }
@@ -0,0 +1,59 @@
1
+ require "test/unit"
2
+ require "eventmachine"
3
+
4
+ class TestEmTickLoop < Test::Unit::TestCase
5
+ def test_em_tick_loop
6
+ i = 0
7
+ EM.tick_loop { i += 1; EM.stop if i == 10 }
8
+ EM.run { EM.add_timer(1) { EM.stop } }
9
+ assert_equal i, 10
10
+ end
11
+
12
+ def test_tick_loop_on_stop
13
+ t = nil
14
+ tick_loop = EM.tick_loop { :stop }
15
+ tick_loop.on_stop { t = true }
16
+ EM.run { EM.next_tick { EM.stop } }
17
+ assert t
18
+ end
19
+
20
+ def test_start_twice
21
+ i = 0
22
+ s = 0
23
+ tick_loop = EM.tick_loop { i += 1; :stop }
24
+ tick_loop.on_stop { s += 1; EM.stop }
25
+ EM.run { EM.next_tick { EM.stop } }
26
+ assert_equal 1, i
27
+ assert_equal 1, s
28
+ tick_loop.start
29
+ EM.run { EM.next_tick { EM.stop } }
30
+ assert_equal 2, i
31
+ assert_equal 1, s # stop callbacks are only called once
32
+ end
33
+
34
+ def test_stop
35
+ i, s = 0, 0
36
+ tick_loop = EM.tick_loop { i += 1 }
37
+ tick_loop.on_stop { s += 1 }
38
+ EM.run { EM.next_tick { tick_loop.stop; EM.next_tick { EM.stop } } }
39
+ assert tick_loop.stopped?
40
+ assert_equal 1, i
41
+ assert_equal 1, s
42
+ end
43
+
44
+ def test_immediate_stops
45
+ s = 0
46
+ tick_loop = EM::TickLoop.new { }
47
+ tick_loop.on_stop { s += 1 }
48
+ tick_loop.on_stop { s += 1 }
49
+ assert_equal 2, s
50
+ end
51
+
52
+ def test_stopped
53
+ tick_loop = EM::TickLoop.new { }
54
+ assert tick_loop.stopped?
55
+ tick_loop.start
56
+ assert !tick_loop.stopped?
57
+ end
58
+
59
+ end
@@ -98,9 +98,9 @@ class TestTimers < Test::Unit::TestCase
98
98
  def test_add_periodic_timer_cancel
99
99
  x = 0
100
100
  EventMachine.run {
101
- pt = EM.add_periodic_timer(0.25) { x += 1 }
101
+ pt = EM.add_periodic_timer(0.1) { x += 1 }
102
102
  EM.cancel_timer(pt)
103
- EM.add_timer(0.5) { EM.stop }
103
+ EM.add_timer(0.2) { EM.stop }
104
104
  }
105
105
  assert( x == 0 )
106
106
  end
@@ -124,21 +124,20 @@ class TestTimers < Test::Unit::TestCase
124
124
  # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
125
125
  #
126
126
  def test_timer_change_max_outstanding
127
- ten_thousand_timers = proc {
128
- 10001.times {
129
- EM.add_timer(5) {}
130
- }
131
- }
127
+ defaults = EM.get_max_timers
128
+ EM.set_max_timers(100)
129
+
130
+ one_hundred_one_timers = proc { 101.times { EM.add_timer(5) {} } }
132
131
 
133
132
  EM.run {
134
133
  if EM.library_type == :pure_ruby
135
- ten_thousand_timers.call
134
+ one_hundred_one_timers.call
136
135
  elsif EM.library_type == :java
137
- ten_thousand_timers.call
136
+ one_hundred_one_timers.call
138
137
  else
139
138
  begin
140
139
  assert_raises( RuntimeError ) {
141
- ten_thousand_timers.call
140
+ one_hundred_one_timers.call
142
141
  }
143
142
  rescue Object
144
143
  p $!
@@ -148,15 +147,14 @@ class TestTimers < Test::Unit::TestCase
148
147
  EM.stop
149
148
  }
150
149
 
151
- assert(!EM.reactor_running?, 'Reactor running when it should not be.')
152
- assert( EM.get_max_timers != 10001 )
153
- EM.set_max_timers( 10001 )
154
- assert( EM.get_max_timers == 10001 )
150
+ EM.set_max_timers( 101 )
155
151
 
156
152
  EM.run {
157
- ten_thousand_timers.call
153
+ one_hundred_one_timers.call
158
154
  EM.stop
159
155
  }
156
+ ensure
157
+ EM.set_max_timers(defaults)
160
158
  end
161
159
 
162
160
  end
metadata CHANGED
@@ -1,19 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.10
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ - beta
10
+ - 1
11
+ version: 1.0.0.beta.1
5
12
  platform: ruby
6
13
  authors:
7
14
  - Francis Cianfrocca
15
+ - Aman Gupta
8
16
  autorequire:
9
17
  bindir: bin
10
18
  cert_chain: []
11
19
 
12
- date: 2009-10-25 00:00:00 -07:00
20
+ date: 2010-11-13 00:00:00 -06:00
13
21
  default_executable:
14
- dependencies: []
15
-
16
- description: |
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: rake-compiler
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: |-
17
36
  EventMachine implements a fast, single-threaded engine for arbitrary network
18
37
  communications. It's extremely easy to use in Ruby. EventMachine wraps all
19
38
  interactions with IP sockets, allowing programs to concentrate on the
@@ -24,8 +43,9 @@ description: |
24
43
  are provided with the package, primarily to serve as examples. The real goal
25
44
  of EventMachine is to enable programs to easily interface with other programs
26
45
  using TCP/IP, especially if custom protocols are required.
27
-
28
- email: garbagecat10@gmail.com
46
+ email:
47
+ - garbagecat10@gmail.com
48
+ - aman@tmm1.net
29
49
  executables: []
30
50
 
31
51
  extensions:
@@ -35,6 +55,7 @@ extra_rdoc_files: []
35
55
 
36
56
  files:
37
57
  - .gitignore
58
+ - Gemfile
38
59
  - README
39
60
  - Rakefile
40
61
  - docs/COPYING
@@ -54,6 +75,8 @@ files:
54
75
  - eventmachine.gemspec
55
76
  - examples/ex_channel.rb
56
77
  - examples/ex_queue.rb
78
+ - examples/ex_tick_loop_array.rb
79
+ - examples/ex_tick_loop_counter.rb
57
80
  - examples/helper.rb
58
81
  - ext/binder.cpp
59
82
  - ext/binder.h
@@ -112,6 +135,7 @@ files:
112
135
  - lib/em/deferrable.rb
113
136
  - lib/em/file_watch.rb
114
137
  - lib/em/future.rb
138
+ - lib/em/iterator.rb
115
139
  - lib/em/messages.rb
116
140
  - lib/em/process_watch.rb
117
141
  - lib/em/processes.rb
@@ -120,6 +144,7 @@ files:
120
144
  - lib/em/protocols/httpclient.rb
121
145
  - lib/em/protocols/httpclient2.rb
122
146
  - lib/em/protocols/line_and_text.rb
147
+ - lib/em/protocols/line_protocol.rb
123
148
  - lib/em/protocols/linetext2.rb
124
149
  - lib/em/protocols/memcache.rb
125
150
  - lib/em/protocols/object_protocol.rb
@@ -130,9 +155,11 @@ files:
130
155
  - lib/em/protocols/socks4.rb
131
156
  - lib/em/protocols/stomp.rb
132
157
  - lib/em/protocols/tcptest.rb
158
+ - lib/em/pure_ruby.rb
133
159
  - lib/em/queue.rb
134
160
  - lib/em/spawnable.rb
135
161
  - lib/em/streamer.rb
162
+ - lib/em/tick_loop.rb
136
163
  - lib/em/timers.rb
137
164
  - lib/em/version.rb
138
165
  - lib/eventmachine.rb
@@ -143,7 +170,6 @@ files:
143
170
  - lib/evma/protocol.rb
144
171
  - lib/evma/reactor.rb
145
172
  - lib/jeventmachine.rb
146
- - lib/pr_eventmachine.rb
147
173
  - setup.rb
148
174
  - tasks/cpp.rake_example
149
175
  - tests/client.crt
@@ -153,6 +179,7 @@ files:
153
179
  - tests/test_channel.rb
154
180
  - tests/test_connection_count.rb
155
181
  - tests/test_defer.rb
182
+ - tests/test_deferrable.rb
156
183
  - tests/test_epoll.rb
157
184
  - tests/test_error_handler.rb
158
185
  - tests/test_errors.rb
@@ -187,10 +214,10 @@ files:
187
214
  - tests/test_ssl_args.rb
188
215
  - tests/test_ssl_methods.rb
189
216
  - tests/test_ssl_verify.rb
217
+ - tests/test_tick_loop.rb
190
218
  - tests/test_timers.rb
191
219
  - tests/test_ud.rb
192
220
  - tests/testem.rb
193
- - web/whatis
194
221
  has_rdoc: true
195
222
  homepage: http://rubyeventmachine.com
196
223
  licenses: []
@@ -201,7 +228,6 @@ rdoc_options:
201
228
  - EventMachine
202
229
  - --main
203
230
  - README
204
- - --line-numbers
205
231
  - -x
206
232
  - lib/em/version
207
233
  - -x
@@ -209,8 +235,6 @@ rdoc_options:
209
235
  - -x
210
236
  - lib/evma/
211
237
  - -x
212
- - lib/pr_eventmachine
213
- - -x
214
238
  - lib/jeventmachine
215
239
  require_paths:
216
240
  - lib
@@ -218,18 +242,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
242
  requirements:
219
243
  - - ">="
220
244
  - !ruby/object:Gem::Version
245
+ segments:
246
+ - 0
221
247
  version: "0"
222
- version:
223
248
  required_rubygems_version: !ruby/object:Gem::Requirement
224
249
  requirements:
225
- - - ">="
250
+ - - ">"
226
251
  - !ruby/object:Gem::Version
227
- version: "0"
228
- version:
252
+ segments:
253
+ - 1
254
+ - 3
255
+ - 1
256
+ version: 1.3.1
229
257
  requirements: []
230
258
 
231
259
  rubyforge_project: eventmachine
232
- rubygems_version: 1.3.4
260
+ rubygems_version: 1.3.6
233
261
  signing_key:
234
262
  specification_version: 3
235
263
  summary: Ruby/EventMachine library