bertrpc 0.4.1 → 0.4.2

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.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.4.2 / 2009-11-27
2
+ * Major changes
3
+ * Switch to using raw socket timeouts over buffered io (Linux only)
4
+
1
5
  = 0.4.1 / 2009-11-26
2
6
  * Major changes
3
7
  * Backport timeout option
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
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 = "0.4.1"
8
+ s.version = "0.4.2"
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-26}
12
+ s.date = %q{2009-11-28}
13
13
  s.email = %q{tom@mojombo.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
26
26
  "bertrpc.gemspec",
27
27
  "lib/bertrpc.rb",
28
28
  "lib/bertrpc/action.rb",
29
- "lib/bertrpc/buffered_io.rb",
30
29
  "lib/bertrpc/encodes.rb",
31
30
  "lib/bertrpc/errors.rb",
32
31
  "lib/bertrpc/mod.rb",
@@ -44,7 +44,7 @@ module BERTRPC
44
44
  bert_response
45
45
  rescue Errno::ECONNREFUSED
46
46
  raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
47
- rescue Timeout::Error
47
+ rescue Errno::EAGAIN
48
48
  raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
49
49
  end
50
50
 
@@ -57,9 +57,18 @@ module BERTRPC
57
57
  # +port+ Integer port of the target TCP server
58
58
  # +timeout+ Optional Integer (in seconds) of the read timeout
59
59
  def connect_to(host, port, timeout = nil)
60
- io = BufferedIO.new(TCPSocket.new(host, port))
61
- io.read_timeout = timeout
62
- io
60
+ sock = TCPSocket.new(host, port)
61
+ sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
62
+
63
+ if timeout
64
+ secs = Integer(timeout)
65
+ usecs = Integer((timeout - secs) * 1_000_000)
66
+ optval = [secs, usecs].pack("l_2")
67
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
68
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
69
+ end
70
+
71
+ sock
63
72
  end
64
73
  end
65
74
  end
data/lib/bertrpc.rb CHANGED
@@ -8,4 +8,3 @@ require 'bertrpc/mod'
8
8
  require 'bertrpc/encodes'
9
9
  require 'bertrpc/action'
10
10
  require 'bertrpc/errors'
11
- require 'bertrpc/buffered_io'
data/test/action_test.rb CHANGED
@@ -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(Timeout::Error)
97
+ io.expects(:read).with(4).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: 0.4.1
4
+ version: 0.4.2
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-26 00:00:00 -08:00
12
+ date: 2009-11-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,6 @@ files:
52
52
  - bertrpc.gemspec
53
53
  - lib/bertrpc.rb
54
54
  - lib/bertrpc/action.rb
55
- - lib/bertrpc/buffered_io.rb
56
55
  - lib/bertrpc/encodes.rb
57
56
  - lib/bertrpc/errors.rb
58
57
  - lib/bertrpc/mod.rb
@@ -1,28 +0,0 @@
1
- module BERTRPC
2
- # Taken with love from memcache-client.
3
- #
4
- # See http://is.gd/4CWRA for the code and
5
- # http://is.gd/4CYde for the discussion.
6
- class BufferedIO < Net::BufferedIO # :nodoc:
7
- BUFSIZE = 1024 * 16
8
-
9
- if RUBY_VERSION < '1.9.1'
10
- def rbuf_fill
11
- begin
12
- @rbuf << @io.read_nonblock(BUFSIZE)
13
- rescue Errno::EWOULDBLOCK
14
- retry unless @read_timeout
15
- if IO.select([@io], nil, nil, @read_timeout)
16
- retry
17
- else
18
- raise Timeout::Error, 'IO timeout'
19
- end
20
- end
21
- end
22
- end
23
-
24
- def setsockopt(*args)
25
- @io.setsockopt(*args)
26
- end
27
- end
28
- end