eventmachine-le 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,6 +15,7 @@ Makefile
15
15
  java/src/.project
16
16
  *.rbc
17
17
  Gemfile.lock
18
+ *.gem
18
19
 
19
20
  .yardoc/*
20
21
  doc/*
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # About EventMachine-LE #
1
+ # EventMachine-LE #
2
+
3
+ EventMachine-LE (Live Edition) is a branch of [EventMachine](http://github.com/eventmachine/eventmachine) with fixes and more features.
4
+
5
+ * Home page: http://ibc.github.com/EventMachine-LE/
2
6
 
3
- EventMachine-LE (Live Edition) is a branch of [EventMachine](http://github.com/eventmachine/eventmachine).
4
7
 
5
8
  ## What do you mean by "branch"? ##
6
9
 
@@ -34,9 +37,12 @@ EventMachine-LE draws from a number of dormant pull requests on the
34
37
  mainline version of EventMachine. New proposals will also directly
35
38
  come to EventMachine-LE and will be included once they are tested.
36
39
 
37
- This is not a "development branch" — we do intend to use
38
- EventMachine-LE in production, just beyond the focus of mainline
39
- EventMachine.
40
+ This is not a "development branch" — we do use EventMachine-LE in production,
41
+ just beyond the focus of mainline EventMachine.
42
+
43
+ The intention is that EventMachine-LE is always a drop-in replacement
44
+ for EventMachine, just with additional (and fixed) functionality.
45
+
40
46
 
41
47
  ## Features and changes ##
42
48
 
@@ -50,13 +56,14 @@ the following features/fixes have been applied in EventMachine-LE:
50
56
  * `EM::get_max_timers` and `EM::set_max_timers` are removed (they still exist but do nothing). This solves the annoying "RuntimeError: max timers exceeded" exception.
51
57
  * Support for Enumerable in `EM::Iterator` ([fl00r](https://github.com/eventmachine/eventmachine/pull/300)).
52
58
  * Improvements to `EM::Protocols::LineProtocol` and have it autoload ([gaffneyc](https://github.com/eventmachine/eventmachine/pull/151)).
53
- * `EM::Protocols::SmtpServer`: support multiple messages per one connection ([bogdan](https://github.com/eventmachine/eventmachine/pull/288)).
59
+ * `EM::Protocols::SmtpServer`: support multiple messages per one connection and login auth type ([bogdan](https://github.com/eventmachine/eventmachine/pull/288)).
60
+ * Reimplement `EM::Queue` to avoid shift/push performance problem ([grddev](https://github.com/eventmachine/eventmachine/pull/311)).
54
61
  * Many code cleanups.
55
62
 
56
63
 
57
64
  ## Installation ##
58
65
 
59
- Install the Ruby Gem:
66
+ The Current stable version is eventmachine-le-1.1.0 (published as Ruby Gem), installable via:
60
67
  <pre>
61
68
  gem install eventmachine-le
62
69
  </pre>
@@ -69,11 +76,16 @@ gem install eventmachine-le --pre
69
76
 
70
77
  ## Usage ##
71
78
 
72
- In order to use this branch in your project, make sure you load it as follows:
79
+ Using EventMachine-LE within your project just requires loading it as follows:
73
80
  <pre>
74
81
  # First load EventMachine-LE.
75
82
  require "eventmachine-le"
76
- # Later load any other Ruby Gem depending on EventMachine so they will use EventMachine-LE.
83
+
84
+ # NOTE: It does not hurt to call "require 'eventmachine'" later
85
+ # (it has no effect at all).
86
+
87
+ # Then load any other Ruby Gem depending on EventMachine so it
88
+ # will use EventMachine-LE.
77
89
  require "em-udns"
78
90
  </pre>
79
91
 
data/ext/rubymain.cpp CHANGED
@@ -516,7 +516,7 @@ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
516
516
  rb_raise (EM_eConnectionError, "no connection");
517
517
  return ULONG2NUM (f);
518
518
  } catch (std::runtime_error e) {
519
- rb_raise (EM_eConnectionError, e.what());
519
+ rb_raise (EM_eConnectionError, e.what(), "%s");
520
520
  }
521
521
  return Qnil;
522
522
  }
@@ -537,7 +537,7 @@ static VALUE t_bind_connect_server (VALUE self, VALUE bind_addr, VALUE bind_port
537
537
  rb_raise (EM_eConnectionError, "no connection");
538
538
  return ULONG2NUM (f);
539
539
  } catch (std::runtime_error e) {
540
- rb_raise (EM_eConnectionError, e.what());
540
+ rb_raise (EM_eConnectionError, e.what(), "%s");
541
541
  }
542
542
  return Qnil;
543
543
  }
@@ -859,7 +859,7 @@ static VALUE t_watch_filename (VALUE self, VALUE fname)
859
859
  try {
860
860
  return ULONG2NUM(evma_watch_filename(StringValuePtr(fname)));
861
861
  } catch (std::runtime_error e) {
862
- rb_raise (EM_eUnsupported, e.what());
862
+ rb_raise (EM_eUnsupported, e.what(), "%s");
863
863
  }
864
864
  return Qnil;
865
865
  }
@@ -885,7 +885,7 @@ static VALUE t_watch_pid (VALUE self, VALUE pid)
885
885
  try {
886
886
  return ULONG2NUM(evma_watch_pid(NUM2INT(pid)));
887
887
  } catch (std::runtime_error e) {
888
- rb_raise (EM_eUnsupported, e.what());
888
+ rb_raise (EM_eUnsupported, e.what(), "%s");
889
889
  }
890
890
  return Qnil;
891
891
  }
@@ -1085,7 +1085,7 @@ static VALUE t_start_proxy (VALUE self, VALUE from, VALUE to, VALUE bufsize, VAL
1085
1085
  try {
1086
1086
  evma_start_proxy(NUM2ULONG (from), NUM2ULONG (to), NUM2ULONG(bufsize), NUM2ULONG(length));
1087
1087
  } catch (std::runtime_error e) {
1088
- rb_raise (EM_eConnectionError, e.what());
1088
+ rb_raise (EM_eConnectionError, e.what(), "%s");
1089
1089
  }
1090
1090
  return Qnil;
1091
1091
  }
@@ -1100,7 +1100,7 @@ static VALUE t_stop_proxy (VALUE self, VALUE from)
1100
1100
  try{
1101
1101
  evma_stop_proxy(NUM2ULONG (from));
1102
1102
  } catch (std::runtime_error e) {
1103
- rb_raise (EM_eConnectionError, e.what());
1103
+ rb_raise (EM_eConnectionError, e.what(), "%s");
1104
1104
  }
1105
1105
  return Qnil;
1106
1106
  }
@@ -1114,7 +1114,7 @@ static VALUE t_proxied_bytes (VALUE self, VALUE from)
1114
1114
  try{
1115
1115
  return ULONG2NUM(evma_proxied_bytes(NUM2ULONG (from)));
1116
1116
  } catch (std::runtime_error e) {
1117
- rb_raise (EM_eConnectionError, e.what());
1117
+ rb_raise (EM_eConnectionError, e.what(), "%s");
1118
1118
  }
1119
1119
  return Qnil;
1120
1120
  }
@@ -1139,7 +1139,7 @@ static VALUE t_get_idle_time (VALUE self, VALUE from)
1139
1139
  return Qnil;
1140
1140
  }
1141
1141
  } catch (std::runtime_error e) {
1142
- rb_raise (EM_eConnectionError, e.what());
1142
+ rb_raise (EM_eConnectionError, e.what(), "%s");
1143
1143
  }
1144
1144
  return Qnil;
1145
1145
  }
data/lib/em/iterator.rb CHANGED
@@ -1,7 +1,29 @@
1
1
  module EventMachine
2
+
3
+ # EventMachine::Queue support
4
+ #
5
+ # queue = EM::Queue.new
6
+ # queue.push "glasses", "apples"
7
+ # result = []
8
+ # EM::Iterator.new(queue).each do |item, iter|
9
+ # result << "I have got #{item}"
10
+ # iter.next
11
+ # end
12
+ # queue.push "cars", "elephants"
13
+ # p result
14
+ # #=> ["I have got glasses", "I have got apples", "I have got cars", "I have got elephants"]
15
+ #
16
+ class QueueIsEmpty < RuntimeError; end
17
+ module IteratorWithQueue
18
+ def next_from_queue?
19
+ raise(QueueIsEmpty) if @queue.empty?
20
+ @queue.pop{ |q| @next_item = q}
21
+ true
22
+ end
23
+ end
24
+
2
25
  # Support for Enumerable in Ruby 1.9+
3
26
  module IteratorWithEnumerable
4
- attr_reader :next_item
5
27
 
6
28
  # In case of Enumerable object we can use lazyness of Enumerator
7
29
  def setup_list(list)
@@ -25,7 +47,6 @@ module EventMachine
25
47
 
26
48
  # Ruby 1.8 uses continuations in Enumerable, so we should use Arrays
27
49
  module IteratorWithArray
28
- attr_reader :next_item
29
50
 
30
51
  def setup_list(list)
31
52
  raise ArgumentError, 'argument must be an array' unless list.respond_to?(:to_a)
@@ -82,8 +103,11 @@ module EventMachine
82
103
  #
83
104
 
84
105
  class Iterator
106
+ attr_reader :next_item
107
+
85
108
  include IteratorWithEnumerable if defined? Fiber
86
109
  include IteratorWithArray unless defined? Fiber
110
+ include IteratorWithQueue
87
111
 
88
112
  # Create a new parallel async iterator with specified concurrency.
89
113
  #
@@ -93,7 +117,12 @@ module EventMachine
93
117
  # is started via #each, #map or #inject
94
118
  #
95
119
  def initialize(list, concurrency = 1)
96
- @list = setup_list(list)
120
+ if list.class == EventMachine::Queue
121
+ @queue = list
122
+ alias :next? :next_from_queue?
123
+ else
124
+ @list = setup_list(list)
125
+ end
97
126
  @concurrency = concurrency
98
127
 
99
128
  @started = false
@@ -140,32 +169,36 @@ module EventMachine
140
169
  @process_next = proc{
141
170
  # p [:process_next, :pending=, @pending, :workers=, @workers, :ended=, @ended, :concurrency=, @concurrency, :list=, @list]
142
171
  unless @ended or @workers > @concurrency
143
- if next?
144
- item = next_item
145
- @pending += 1
146
-
147
- is_done = false
148
- on_done = proc{
149
- raise RuntimeError, 'already completed this iteration' if is_done
150
- is_done = true
151
-
152
- @pending -= 1
153
-
154
- if @ended
155
- all_done.call
156
- else
157
- EM.next_tick(@process_next)
172
+ begin
173
+ if next?
174
+ item = next_item
175
+ @pending += 1
176
+
177
+ is_done = false
178
+ on_done = proc{
179
+ raise RuntimeError, 'already completed this iteration' if is_done
180
+ is_done = true
181
+
182
+ @pending -= 1
183
+
184
+ if @ended
185
+ all_done.call
186
+ else
187
+ EM.next_tick(@process_next)
188
+ end
189
+ }
190
+ class << on_done
191
+ alias :next :call
158
192
  end
159
- }
160
- class << on_done
161
- alias :next :call
162
- end
163
193
 
164
- foreach.call(item, on_done)
165
- else
166
- @ended = true
167
- @workers -= 1
168
- all_done.call
194
+ foreach.call(item, on_done)
195
+ else
196
+ @ended = true
197
+ @workers -= 1
198
+ all_done.call
199
+ end
200
+ rescue EventMachine::QueueIsEmpty
201
+ EM.next_tick(@process_next)
169
202
  end
170
203
  else
171
204
  @workers -= 1
data/lib/em/queue.rb CHANGED
@@ -17,7 +17,8 @@ module EventMachine
17
17
  #
18
18
  class Queue
19
19
  def initialize
20
- @items = []
20
+ @sink = []
21
+ @drain = []
21
22
  @popq = []
22
23
  end
23
24
 
@@ -29,10 +30,14 @@ module EventMachine
29
30
  def pop(*a, &b)
30
31
  cb = EM::Callback(*a, &b)
31
32
  EM.schedule do
32
- if @items.empty?
33
+ if @drain.empty?
34
+ @drain = @sink
35
+ @sink = []
36
+ end
37
+ if @drain.empty?
33
38
  @popq << cb
34
39
  else
35
- cb.call @items.shift
40
+ cb.call @drain.shift
36
41
  end
37
42
  end
38
43
  nil # Always returns nil
@@ -43,8 +48,12 @@ module EventMachine
43
48
  # next reactor tick.
44
49
  def push(*items)
45
50
  EM.schedule do
46
- @items.push(*items)
47
- @popq.shift.call @items.shift until @items.empty? || @popq.empty?
51
+ @sink.push(*items)
52
+ unless @popq.empty?
53
+ @drain = @sink
54
+ @sink = []
55
+ @popq.shift.call @drain.shift until @drain.empty? || @popq.empty?
56
+ end
48
57
  end
49
58
  end
50
59
  alias :<< :push
@@ -52,13 +61,13 @@ module EventMachine
52
61
  # @return [Boolean]
53
62
  # @note This is a peek, it's not thread safe, and may only tend toward accuracy.
54
63
  def empty?
55
- @items.empty?
64
+ @drain.empty? && @sink.empty?
56
65
  end
57
66
 
58
67
  # @return [Integer] Queue size
59
68
  # @note This is a peek, it's not thread safe, and may only tend toward accuracy.
60
69
  def size
61
- @items.size
70
+ @drain.size + @sink.size
62
71
  end
63
72
 
64
73
  # @return [Integer] Waiting size
data/lib/em/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EventMachine
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/tests/test_queue.rb CHANGED
@@ -47,4 +47,18 @@ class TestEMQueue < Test::Unit::TestCase
47
47
  EM.run { EM.next_tick { EM.stop } }
48
48
  assert_equal many, q.num_waiting
49
49
  end
50
+
51
+ def test_big_queue
52
+ EM.run do
53
+ q = EM::Queue.new
54
+ 2000.times do |i|
55
+ q.push(*0..1000)
56
+ q.pop { |v| assert_equal v, i % 1001 }
57
+ end
58
+ q.pop do
59
+ assert_equal 1_999_999, q.size
60
+ EM.stop
61
+ end
62
+ end
63
+ end
50
64
  end
metadata CHANGED
@@ -1,91 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-le
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 0
9
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Francis Cianfrocca
13
9
  - Aman Gupta
14
10
  - hacked by Carsten Bormann and Inaki Baz Castillo
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2012-03-13 00:00:00 +01:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
14
+ date: 2012-07-12 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
23
17
  name: rake-compiler
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &21749960 !ruby/object:Gem::Requirement
26
19
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- segments:
31
- - 0
32
- - 7
33
- - 9
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
34
23
  version: 0.7.9
35
24
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: yard
39
25
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *21749960
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: &21749500 !ruby/object:Gem::Requirement
41
30
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- segments:
46
- - 0
47
- - 7
48
- - 2
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
49
34
  version: 0.7.2
50
35
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: bluecloth
54
36
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *21749500
38
+ - !ruby/object:Gem::Dependency
39
+ name: bluecloth
40
+ requirement: &21748940 !ruby/object:Gem::Requirement
56
41
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
63
46
  type: :development
64
- version_requirements: *id003
65
- description: |
66
- EventMachine-LE (Live Edition) is a branch of EventMachine (https://github.com/eventmachine/eventmachine).
67
-
68
- This branch incorporates interesting pull requests that are not yet included in the mainline EventMachine repository. The maintainers of that version prefer to minimize change in order to keep the stability with already existing EventMachine deployments, which provides an impressive multi-platform base for IPv4 TCP servers (e.g., Web servers) that don't need good UDP or IPv6 support.
69
-
70
- This dedication to stability is helpful for production use, but can also lead to ossification. The present "Live Edition" or "Leading Edge" branch has its focus on supporting a somewhat wider use, including new Web servers or protocols beyond the HTTP Web.
71
-
72
- To provide even more focus, this branch is currently applying its energy towards Linux and Unix/BSD/OSX environments. Java reactor and pure Ruby reactor are for now removed in this branch, and Windows/Cygwin support is untested. This may very well change later, once interesting pull requests come in.
73
-
74
- EventMachine-LE draws from a number of dormant pull requests on the mainline version of EventMachine. New proposals will also directly come to EventMachine-LE and will be included once they are tested.
75
-
76
- This is not a "development branch", EventMachine-LE is ready for production, just beyond the focus of mainline EventMachine.
47
+ prerelease: false
48
+ version_requirements: *21748940
49
+ description: ! 'EventMachine-LE (Live Edition) is a branch of EventMachine (https://github.com/eventmachine/eventmachine).
50
+
51
+
52
+ This branch incorporates interesting pull requests that are not yet included in
53
+ the mainline EventMachine repository. The maintainers of that version prefer to
54
+ minimize change in order to keep the stability with already existing EventMachine
55
+ deployments, which provides an impressive multi-platform base for IPv4 TCP servers
56
+ (e.g., Web servers) that don''t need good UDP or IPv6 support.
57
+
77
58
 
78
- email:
59
+ This dedication to stability is helpful for production use, but can also lead to
60
+ ossification. The present "Live Edition" or "Leading Edge" branch has its focus
61
+ on supporting a somewhat wider use, including new Web servers or protocols beyond
62
+ the HTTP Web.
63
+
64
+
65
+ To provide even more focus, this branch is currently applying its energy towards
66
+ Linux and Unix/BSD/OSX environments. Java reactor and pure Ruby reactor are for
67
+ now removed in this branch, and Windows/Cygwin support is untested. This may very
68
+ well change later, once interesting pull requests come in.
69
+
70
+
71
+ EventMachine-LE draws from a number of dormant pull requests on the mainline version
72
+ of EventMachine. New proposals will also directly come to EventMachine-LE and will
73
+ be included once they are tested.
74
+
75
+
76
+ This is not a "development branch", EventMachine-LE is ready for production, just
77
+ beyond the focus of mainline EventMachine.
78
+
79
+ '
80
+ email:
79
81
  - garbagecat10@gmail.com
80
82
  - aman@tmm1.net
81
83
  - cabo@tzi.org
82
84
  - ibc@aliax.net
83
85
  executables: []
84
-
85
- extensions:
86
+ extensions:
86
87
  - ext/extconf.rb
87
88
  - ext/fastfilereader/extconf.rb
88
- extra_rdoc_files:
89
+ extra_rdoc_files:
89
90
  - README.md
90
91
  - .gitignore
91
92
  - .yardopts
@@ -215,7 +216,7 @@ extra_rdoc_files:
215
216
  - tests/test_ud.rb
216
217
  - tests/test_udp46.rb
217
218
  - tests/test_unbind_reason.rb
218
- files:
219
+ files:
219
220
  - .gitignore
220
221
  - .yardopts
221
222
  - GNU
@@ -345,44 +346,35 @@ files:
345
346
  - tests/test_ud.rb
346
347
  - tests/test_udp46.rb
347
348
  - tests/test_unbind_reason.rb
348
- has_rdoc: true
349
349
  homepage: https://github.com/ibc/EventMachine-LE/
350
350
  licenses: []
351
-
352
351
  post_install_message:
353
- rdoc_options:
352
+ rdoc_options:
354
353
  - --title
355
354
  - EventMachine-LE
356
355
  - --main
357
356
  - README.md
358
357
  - -x
359
358
  - lib/em/version
360
- require_paths:
359
+ require_paths:
361
360
  - lib
362
- required_ruby_version: !ruby/object:Gem::Requirement
361
+ required_ruby_version: !ruby/object:Gem::Requirement
363
362
  none: false
364
- requirements:
365
- - - ">="
366
- - !ruby/object:Gem::Version
367
- segments:
368
- - 1
369
- - 8
370
- - 7
363
+ requirements:
364
+ - - ! '>='
365
+ - !ruby/object:Gem::Version
371
366
  version: 1.8.7
372
- required_rubygems_version: !ruby/object:Gem::Requirement
367
+ required_rubygems_version: !ruby/object:Gem::Requirement
373
368
  none: false
374
- requirements:
375
- - - ">="
376
- - !ruby/object:Gem::Version
377
- segments:
378
- - 0
379
- version: "0"
369
+ requirements:
370
+ - - ! '>='
371
+ - !ruby/object:Gem::Version
372
+ version: '0'
380
373
  requirements: []
381
-
382
374
  rubyforge_project:
383
- rubygems_version: 1.3.7
375
+ rubygems_version: 1.8.11
384
376
  signing_key:
385
377
  specification_version: 3
386
378
  summary: EventMachine LE (Live Edition)
387
379
  test_files: []
388
-
380
+ has_rdoc: