bertrpc 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ = 1.2.0 / 2010-02-09
2
+ * Enhancements
3
+ * Better timeouts courtesy of select(2)
4
+ * BERTRPCError gives self for original_exception if nil
5
+
1
6
  = 1.1.2 / 2009-11-27
2
7
  * Minor Changes
3
8
  * Add useful debugging information to ReadTimeoutError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0
data/bertrpc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bertrpc}
8
- s.version = "1.1.2"
8
+ s.version = "1.2.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{2009-11-28}
12
+ s.date = %q{2010-02-09}
13
13
  s.email = %q{tom@mojombo.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -23,8 +23,21 @@ module BERTRPC
23
23
  sock.write(bert)
24
24
  end
25
25
 
26
+ def read(sock, len, timeout)
27
+ data, size = [], 0
28
+ while size < len
29
+ r, w, e = IO.select([sock], [], [], timeout)
30
+ raise Errno::EAGAIN if r.nil?
31
+ msg, sender = sock.recvfrom(len - size)
32
+ size += msg.size
33
+ data << msg
34
+ end
35
+ data.join ''
36
+ end
37
+
26
38
  def transaction(bert_request)
27
- sock = connect_to(@svc.host, @svc.port, @svc.timeout)
39
+ timeout = @svc.timeout && Float(@svc.timeout)
40
+ sock = connect_to(@svc.host, @svc.port, timeout)
28
41
 
29
42
  if @req.options
30
43
  if @req.options[:cache] && @req.options[:cache][0] == :validation
@@ -35,10 +48,10 @@ module BERTRPC
35
48
  end
36
49
 
37
50
  write(sock, bert_request)
38
- lenheader = sock.read(4)
51
+ lenheader = read(sock, 4, timeout)
39
52
  raise ProtocolError.new(ProtocolError::NO_HEADER) unless lenheader
40
53
  len = lenheader.unpack('N').first
41
- bert_response = sock.read(len)
54
+ bert_response = read(sock, len, timeout)
42
55
  raise ProtocolError.new(ProtocolError::NO_DATA) unless bert_response
43
56
  sock.close
44
57
  bert_response
@@ -57,7 +70,8 @@ module BERTRPC
57
70
  # +port+ Integer port of the target TCP server
58
71
  # +timeout+ Optional Integer (in seconds) of the read timeout
59
72
  def connect_to(host, port, timeout = nil)
60
- sock = TCPSocket.new(host, port)
73
+ addr = Socket.getaddrinfo(host, nil)
74
+ sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
61
75
  sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
62
76
 
63
77
  if timeout
@@ -68,6 +82,7 @@ module BERTRPC
68
82
  sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
69
83
  end
70
84
 
85
+ sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
71
86
  sock
72
87
  end
73
88
  end
@@ -13,6 +13,8 @@ module BERTRPC
13
13
  if klass
14
14
  self.original_exception = RemoteError.new("#{klass}: #{message}")
15
15
  self.original_exception.set_backtrace(bt)
16
+ else
17
+ self.original_exception = self
16
18
  end
17
19
 
18
20
  self.code = code
data/test/action_test.rb CHANGED
@@ -54,8 +54,8 @@ class ActionTest < Test::Unit::TestCase
54
54
  io = stub()
55
55
  io.expects(:write).with("\000\000\000\003")
56
56
  io.expects(:write).with("foo")
57
- io.expects(:read).with(4).returns("\000\000\000\003")
58
- io.expects(:read).with(3).returns("bar")
57
+ @call.expects(:read).with(io, 4, nil).returns("\000\000\000\003")
58
+ @call.expects(:read).with(io, 3, nil).returns("bar")
59
59
  io.expects(:close)
60
60
  @call.expects(:connect_to).returns(io)
61
61
  assert_equal "bar", @call.transaction("foo")
@@ -65,7 +65,7 @@ class ActionTest < Test::Unit::TestCase
65
65
  io = stub()
66
66
  io.expects(:write).with("\000\000\000\003")
67
67
  io.expects(:write).with("foo")
68
- io.expects(:read).with(4).returns(nil)
68
+ @call.expects(:read).with(io, 4, nil).returns(nil)
69
69
  @call.expects(:connect_to).returns(io)
70
70
  begin
71
71
  @call.transaction("foo")
@@ -79,8 +79,8 @@ class ActionTest < Test::Unit::TestCase
79
79
  io = stub()
80
80
  io.expects(:write).with("\000\000\000\003")
81
81
  io.expects(:write).with("foo")
82
- io.expects(:read).with(4).returns("\000\000\000\003")
83
- io.expects(:read).with(3).returns(nil)
82
+ @call.expects(:read).with(io, 4, nil).returns("\000\000\000\003")
83
+ @call.expects(:read).with(io, 3, nil).returns(nil)
84
84
  @call.expects(:connect_to).returns(io)
85
85
  begin
86
86
  @call.transaction("foo")
@@ -94,7 +94,7 @@ class ActionTest < Test::Unit::TestCase
94
94
  io = stub()
95
95
  io.expects(:write).with("\000\000\000\003")
96
96
  io.expects(:write).with("foo")
97
- io.expects(:read).with(4).raises(Errno::EAGAIN)
97
+ @call.expects(:read).with(io, 4, nil).raises(Errno::EAGAIN)
98
98
  @call.expects(:connect_to).returns(io)
99
99
  begin
100
100
  @call.transaction("foo")
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.1.2
4
+ version: 1.2.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: 2009-11-28 00:00:00 -08:00
12
+ date: 2010-02-09 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency