Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Correctly pass error to `unbind` on connection handler #289

Merged
merged 1 commit into from

4 participants

@mislav

To check if a method accepts at least 1 argument, it's better to check arity != 0. Checking arity == 1 is wrong since the first argument may be optional, in which case arity will be -1.

@ibc

This pull request should be included in EM master ASAP. Thanks a lot.

@tmm1 tmm1 merged commit 64a949a into eventmachine:master
@avsej

+1, when will be next EM release?

@ibc

Probably never. But you can check EventMachine-LE which already includes that patch in the stable 1.1.0 Gem version (along with other pull requests):

https://github.com/ibc/EventMachine-LE/

@avsej

Thanks @ibc

@mislav mislav deleted the mislav:unbind branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2012
  1. @mislav
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 3 deletions.
  1. +1 −1  lib/eventmachine.rb
  2. +19 −2 tests/test_unbind_reason.rb
View
2  lib/eventmachine.rb
@@ -1414,7 +1414,7 @@ def self.event_callback conn_binding, opcode, data
if opcode == ConnectionUnbound
if c = @conns.delete( conn_binding )
begin
- if c.original_method(:unbind).arity == 1
+ if c.original_method(:unbind).arity != 0
c.unbind(data == 0 ? nil : EventMachine::ERRNOS[data])
else
c.unbind
View
21 tests/test_unbind_reason.rb
@@ -2,6 +2,15 @@
require 'socket'
class TestUnbindReason < Test::Unit::TestCase
+
+ class StubConnection < EM::Connection
+ attr_reader :error
+ def unbind(reason = nil)
+ @error = reason
+ EM.stop
+ end
+ end
+
def test_connect_timeout
error = nil
EM.run {
@@ -13,7 +22,7 @@ def test_connect_timeout
}
conn.pending_connect_timeout = 0.1
}
- assert_equal error, Errno::ETIMEDOUT
+ assert_equal Errno::ETIMEDOUT, error
end
def test_connect_refused
@@ -26,6 +35,14 @@ def test_connect_refused
end
}
}
- assert_equal error, Errno::ECONNREFUSED
+ assert_equal Errno::ECONNREFUSED, error
+ end
+
+ def test_optional_argument
+ conn = nil
+ EM.run {
+ conn = EM.connect '127.0.0.1', 12388, StubConnection
+ }
+ assert_equal Errno::ECONNREFUSED, conn.error
end
end
Something went wrong with that request. Please try again.