bertrpc 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ = 1.1.2 / 2009-11-27
2
+ * Minor Changes
3
+ * Add useful debugging information to ReadTimeoutError
4
+ * Switch to using raw socket timeouts over buffered io (Linux only)
5
+ * Add BERTRPC::VERSION and BERTRPC.version
6
+
1
7
  = 1.1.1 / 2009-10-28
2
8
  Major Changes
3
9
  * Require bert-1.1.0 or greater
data/Rakefile CHANGED
@@ -9,8 +9,9 @@ begin
9
9
  gem.email = "tom@mojombo.com"
10
10
  gem.homepage = "http://github.com/mojombo/bertrpc"
11
11
  gem.authors = ["Tom Preston-Werner"]
12
- gem.add_dependency('bert', '>= 1.1.0')
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
+ gem.add_dependency('bert', '>= 1.1.0', '< 2.0.0')
13
+ # gem is a Gem::Specification...
14
+ # see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
15
16
 
16
17
  rescue LoadError
@@ -37,7 +38,6 @@ rescue LoadError
37
38
  end
38
39
  end
39
40
 
40
-
41
41
  task :default => :test
42
42
 
43
43
  require 'rake/rdoctask'
@@ -55,3 +55,6 @@ Rake::RDocTask.new do |rdoc|
55
55
  rdoc.rdoc_files.include('lib/**/*.rb')
56
56
  end
57
57
 
58
+ task :console do
59
+ exec('irb -Ilib -rbertrpc')
60
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
data/bertrpc.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bertrpc}
8
- s.version = "1.1.1"
8
+ s.version = "1.1.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-10-28}
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",
@@ -60,11 +59,12 @@ Gem::Specification.new do |s|
60
59
  s.specification_version = 3
61
60
 
62
61
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
- s.add_runtime_dependency(%q<bert>, [">= 1.1.0"])
62
+ s.add_runtime_dependency(%q<bert>, [">= 1.1.0", "< 2.0.0"])
64
63
  else
65
- s.add_dependency(%q<bert>, [">= 1.1.0"])
64
+ s.add_dependency(%q<bert>, [">= 1.1.0", "< 2.0.0"])
66
65
  end
67
66
  else
68
- s.add_dependency(%q<bert>, [">= 1.1.0"])
67
+ s.add_dependency(%q<bert>, [">= 1.1.0", "< 2.0.0"])
69
68
  end
70
69
  end
70
+
@@ -44,8 +44,8 @@ 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
48
- raise ReadTimeoutError.new("No response from #{@svc.host}:#{@svc.port} in #{@svc.timeout}s")
47
+ rescue Errno::EAGAIN
48
+ raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
49
49
  end
50
50
 
51
51
  # Creates a socket object which does speedy, non-blocking reads
@@ -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
@@ -28,8 +28,14 @@ module BERTRPC
28
28
 
29
29
  end
30
30
 
31
+ # Raised when we don't get a response from a server in a timely
32
+ # manner. This typically occurs in spite of a successful connection.
31
33
  class ReadTimeoutError < BERTRPCError
32
-
34
+ attr_reader :host, :port, :timeout
35
+ def initialize(host, port, timeout)
36
+ @host, @port, @timeout = host, port, timeout
37
+ super("No response from #{host}:#{port} in #{timeout}s")
38
+ end
33
39
  end
34
40
 
35
41
  class ProtocolError < BERTRPCError
@@ -52,4 +58,4 @@ module BERTRPC
52
58
  class InvalidOption < BERTRPCError
53
59
 
54
60
  end
55
- end
61
+ end
data/lib/bertrpc.rb CHANGED
@@ -8,4 +8,13 @@ require 'bertrpc/mod'
8
8
  require 'bertrpc/encodes'
9
9
  require 'bertrpc/action'
10
10
  require 'bertrpc/errors'
11
- require 'bertrpc/buffered_io'
11
+
12
+ module BERTRPC
13
+ def self.version
14
+ File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION])).chomp
15
+ rescue
16
+ 'unknown'
17
+ end
18
+
19
+ VERSION = self.version
20
+ end
data/test/action_test.rb CHANGED
@@ -94,13 +94,15 @@ 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")
101
101
  fail "Should have thrown an error"
102
102
  rescue BERTRPC::ReadTimeoutError => e
103
103
  assert_equal 0, e.code
104
+ assert_equal 'localhost', e.host
105
+ assert_equal 9941, e.port
104
106
  end
105
107
  end
106
108
  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.1.1
4
+ version: 1.1.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-10-28 00:00:00 -07:00
12
+ date: 2009-11-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,6 +21,9 @@ dependencies:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.1.0
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
24
27
  version:
25
28
  description:
26
29
  email: tom@mojombo.com
@@ -42,7 +45,6 @@ files:
42
45
  - bertrpc.gemspec
43
46
  - lib/bertrpc.rb
44
47
  - lib/bertrpc/action.rb
45
- - lib/bertrpc/buffered_io.rb
46
48
  - lib/bertrpc/encodes.rb
47
49
  - lib/bertrpc/errors.rb
48
50
  - 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