bunny-ext 0.6.4 → 0.6.5

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.
@@ -3,13 +3,12 @@ require 'qrack/client'
3
3
 
4
4
  module Qrack
5
5
  class Client
6
- SOCKET_TIMEOUT = 5.0
7
6
 
8
7
  alias initialize_without_timeout_opts initialize
9
8
  def initialize_with_timeout_opts(opts = {})
10
9
  initialize_without_timeout_opts(opts)
11
- @socket_timeout = opts[:socket_timeout] || SOCKET_TIMEOUT
12
- @use_timeout = RUBY_VERSION >= "1.9"
10
+ @read_write_timeout = opts[:socket_timeout]
11
+ @read_write_timeout = nil if @read_write_timeout == 0
13
12
  end
14
13
  alias initialize initialize_with_timeout_opts
15
14
 
@@ -20,8 +19,8 @@ module Qrack
20
19
  def send_command(cmd, *args)
21
20
  begin
22
21
  raise Bunny::ConnectionError, 'No connection - socket has not been created' if !@socket
23
- if @use_timeout
24
- Bunny::Timer::timeout(@socket_timeout, Qrack::ClientTimeout) do
22
+ if @read_write_timeout
23
+ Bunny::Timer::timeout(@read_write_timeout, Qrack::ClientTimeout) do
25
24
  @socket.__send__(cmd, *args)
26
25
  end
27
26
  else
@@ -32,22 +31,6 @@ module Qrack
32
31
  end
33
32
  end
34
33
 
35
- # Set socket send and receive timeouts and let the operating system deal
36
- # with these timeouts. If setting those isn't supported (for example on solaris)
37
- # we use the Bunny::Timer::timeout method to wrap all socket accesses
38
- def set_socket_timeouts
39
- return if @status == :not_connected
40
- secs = Integer(@socket_timeout)
41
- usecs = Integer((@socket_timeout - secs) * 1_000_000)
42
- optval = [secs, usecs].pack("l_2")
43
- begin
44
- @socket.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
45
- @socket.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
46
- rescue Errno::ENOPROTOOPT
47
- @use_timeout = true
48
- end
49
- end
50
-
51
34
  def socket
52
35
  return @socket if @socket and (@status == :connected) and not @socket.closed?
53
36
 
@@ -74,19 +57,21 @@ module Qrack
74
57
  raise Bunny::ServerDownError, e.message
75
58
  end
76
59
 
77
- set_socket_timeouts
78
-
79
60
  @socket
80
61
  end
81
62
 
63
+ def disconnect_timeout
64
+ @read_write_timeout || @connect_timeout
65
+ end
66
+
82
67
  def close
83
68
  return if @socket.nil? || @socket.closed?
84
69
 
85
70
  # Close all active channels
86
- channels.each { |c| Bunny::Timer::timeout(@socket_timeout) { c.close if c.open? } }
71
+ channels.each { |c| Bunny::Timer::timeout(disconnect_timeout) { c.close if c.open? } }
87
72
 
88
73
  # Close connection to AMQP server
89
- Bunny::Timer::timeout(@socket_timeout) { close_connection }
74
+ Bunny::Timer::timeout(disconnect_timeout) { close_connection }
90
75
  rescue Exception
91
76
  # http://http://cheezburger.com/Asset/View/4033311488
92
77
  ensure
@@ -1,5 +1,5 @@
1
1
  module Bunny
2
2
  module Ext
3
- VERSION = "0.6.4"
3
+ VERSION = "0.6.5"
4
4
  end
5
5
  end
@@ -1,8 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
 
3
3
  class QrackClientExtTest < Test::Unit::TestCase
4
- def test_should_monkeypatch_the_client_class
5
- Bunny.send :setup, "0.8", {}
6
- assert Bunny::Client.instance_methods.include? "set_socket_timeouts"
4
+ def test_nothing
5
+ assert true
7
6
  end
8
- end
7
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny-ext
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 5
10
+ version: 0.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stefan Kaes
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-09 00:00:00 +01:00
19
+ date: 2010-12-10 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency