bertrpc 1.2.1 → 1.3.0

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.
@@ -1,3 +1,7 @@
1
+ = 1.3.0 / 2010-02-24
2
+ * Enhancements
3
+ * Raise BERTRPC::ReadTimeout if remote connection is closed
4
+
1
5
  = 1.2.1 / 2010-02-10
2
6
  * Bug fixes
3
7
  * Restrict to IPv4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bertrpc}
8
- s.version = "1.2.1"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Preston-Werner"]
12
- s.date = %q{2010-02-10}
12
+ s.date = %q{2010-02-24}
13
13
  s.email = %q{tom@mojombo.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -29,6 +29,7 @@ module BERTRPC
29
29
  r, w, e = IO.select([sock], [], [], timeout)
30
30
  raise Errno::EAGAIN if r.nil?
31
31
  msg, sender = sock.recvfrom(len - size)
32
+ raise Errno::ECONNRESET if msg.size == 0
32
33
  size += msg.size
33
34
  data << msg
34
35
  end
@@ -56,9 +57,11 @@ module BERTRPC
56
57
  sock.close
57
58
  bert_response
58
59
  rescue Errno::ECONNREFUSED
59
- raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
60
+ raise ConnectionError.new(@svc.host, @svc.port)
60
61
  rescue Errno::EAGAIN
61
62
  raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
63
+ rescue Errno::ECONNRESET
64
+ raise ReadError.new(@svc.host, @svc.port)
62
65
  end
63
66
 
64
67
  # Creates a socket object which does speedy, non-blocking reads
@@ -27,7 +27,11 @@ module BERTRPC
27
27
  end
28
28
 
29
29
  class ConnectionError < BERTRPCError
30
-
30
+ attr_reader :host, :port
31
+ def initialize(host, port)
32
+ @host, @port = host, port
33
+ super("Unable to connect to #{host}:#{port}")
34
+ end
31
35
  end
32
36
 
33
37
  # Raised when we don't get a response from a server in a timely
@@ -40,6 +44,15 @@ module BERTRPC
40
44
  end
41
45
  end
42
46
 
47
+ # Raised when unexpected EOF is reached on the socket.
48
+ class ReadError < BERTRPCError
49
+ attr_reader :host, :port
50
+ def initialize(host, port)
51
+ @host, @port = host, port
52
+ super("Unable to read from #{host}:#{port}")
53
+ end
54
+ end
55
+
43
56
  class ProtocolError < BERTRPCError
44
57
  NO_HEADER = [0, "Unable to read length header from server."]
45
58
  NO_DATA = [1, "Unable to read data from server."]
@@ -105,6 +105,22 @@ class ActionTest < Test::Unit::TestCase
105
105
  assert_equal 9941, e.port
106
106
  end
107
107
  end
108
+
109
+ should "raise a ReadError when the socket becomes unreadable" do
110
+ io = stub()
111
+ io.expects(:write).with("\000\000\000\003")
112
+ io.expects(:write).with("foo")
113
+ @call.expects(:read).with(io, 4, nil).raises(Errno::ECONNRESET)
114
+ @call.expects(:connect_to).returns(io)
115
+ begin
116
+ @call.transaction("foo")
117
+ fail "Should have thrown an error"
118
+ rescue BERTRPC::ReadError => e
119
+ assert_equal 0, e.code
120
+ assert_equal 'localhost', e.host
121
+ assert_equal 9941, e.port
122
+ end
123
+ end
108
124
  end
109
125
  end
110
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bertrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-10 00:00:00 -08:00
12
+ date: 2010-02-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency