From cf6bf3622b3a6e5c390234272ac3f18370d0f3ce Mon Sep 17 00:00:00 2001 From: Pascal Friederich Date: Fri, 19 Nov 2010 15:29:28 +0100 Subject: [PATCH] Use the bunny-ext gem for the timeout monkey patching stuff --- amqp_logging.gemspec | 3 +- lib/amqp_logging.rb | 3 +- lib/amqp_logging/ext/qrack/client.rb | 44 ---------------------------- 3 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 lib/amqp_logging/ext/qrack/client.rb diff --git a/amqp_logging.gemspec b/amqp_logging.gemspec index d401ed2..354242a 100644 --- a/amqp_logging.gemspec +++ b/amqp_logging.gemspec @@ -36,7 +36,8 @@ Gem::Specification.new do |s| INFO s.specification_version = 3 - s.add_runtime_dependency("bunny", [">= 0.6.0"]) + s.add_runtime_dependency("bunny", ["= 0.6.0"]) + s.add_runtime_dependency("bunny-ext", ["= 0.6.0"]) s.add_runtime_dependency("activesupport", [">= 2.3.0"]) s.add_runtime_dependency("json", [">= 1.4.0"]) s.add_development_dependency("mocha", [">= 0"]) diff --git a/lib/amqp_logging.rb b/lib/amqp_logging.rb index 0d9acd8..70f8bf6 100755 --- a/lib/amqp_logging.rb +++ b/lib/amqp_logging.rb @@ -1,4 +1,5 @@ require 'bunny' +require 'bunny-ext' begin # ActiveSupport 3.x @@ -22,4 +23,4 @@ def self.iso_time_with_microseconds(t = Time.now) require 'logger' require 'amqp_logging/logger' require 'amqp_logging/log_device' -require 'amqp_logging/ext/qrack/client' + diff --git a/lib/amqp_logging/ext/qrack/client.rb b/lib/amqp_logging/ext/qrack/client.rb deleted file mode 100644 index 0c75c3f..0000000 --- a/lib/amqp_logging/ext/qrack/client.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'qrack/client' - - -unless Qrack::Client.instance_methods.include?("socket_with_reliable_timeout") - module AMQPLogging - Timer = if RUBY_VERSION < "1.9" - begin - require 'system_timer' - SystemTimer - rescue LoadError - require 'timeout' - Timeout - end - else - require 'timeout' - Timeout - end - end - - module Qrack - class Client - # overwrite the timeout method so that SystemTimer is used - # instead the standard timeout.rb: http://ph7spot.com/musings/system-timer - delegate :timeout, :to => AMQPLogging::Timer - - def socket_with_reliable_timeout - socket_without_reliable_timeout - - secs = Integer(CONNECT_TIMEOUT) - usecs = Integer((CONNECT_TIMEOUT - secs) * 1_000_000) - optval = [secs, usecs].pack("l_2") - - begin - @socket.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval - @socket.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval - rescue Errno::ENOPROTOOPT - end - @socket - end - alias_method_chain :socket, :reliable_timeout - - end - end -end \ No newline at end of file