Permalink
Browse files

Add :timeout parameter to clients, which will raise

Qrack::ConnectionTimeout (instead of Timeout::Error) if not connected
within specified timeframe

Increase CONNECT_TIMEOUT default from 1.0 to 5.0
  • Loading branch information...
1 parent 4e4cb23 commit 2c83589eb851bf558bb491cfcd1da093e9dde0a3 Jared Kuolt committed Sep 21, 2009
Showing with 7 additions and 3 deletions.
  1. +1 −0 lib/bunny/client08.rb
  2. +2 −1 lib/bunny/client09.rb
  3. +4 −2 lib/qrack/client.rb
View
@@ -43,6 +43,7 @@ class Client < Qrack::Client
* <tt>:frame_max => maximum frame size in bytes (default = 131072)</tt>
* <tt>:channel_max => maximum number of channels (default = 0 no maximum)</tt>
* <tt>:heartbeat => number of seconds (default = 0 no heartbeat)</tt>
+* <tt>:timeout => number of seconds before Qrack::ConnectionTimeout is raised (default = 5)</tt>
=end
View
@@ -37,6 +37,7 @@ class Client09 < Qrack::Client
* <tt>:frame_max => maximum frame size in bytes (default = 131072)</tt>
* <tt>:channel_max => maximum number of channels (default = 0 no maximum)</tt>
* <tt>:heartbeat => number of seconds (default = 0 no heartbeat)</tt>
+* <tt>:timeout => number of seconds before Qrack::ConnectionTimeout is raised (default = 5)</tt>
=end
@@ -459,4 +460,4 @@ def buffer
end
end
-end
+end
View
@@ -1,11 +1,12 @@
module Qrack
class ClientTimeout < Timeout::Error; end
+ class ConnectionTimeout < Timeout::Error; end
# Client ancestor class
class Client
- CONNECT_TIMEOUT = 1.0
+ CONNECT_TIMEOUT = 5.0
RETRY_DELAY = 10.0
attr_reader :status, :host, :vhost, :port, :logging, :spec, :heartbeat
@@ -25,6 +26,7 @@ def initialize(opts = {})
@frame_max = opts[:frame_max] || 131072
@channel_max = opts[:channel_max] || 0
@heartbeat = opts[:heartbeat] || 0
+ @connect_timeout = opts[:timeout] || CONNECT_TIMEOUT
@logger = nil
create_logger if @logging
@message_in = false
@@ -173,7 +175,7 @@ def socket
begin
# Attempt to connect.
- @socket = timeout(CONNECT_TIMEOUT) do
+ @socket = timeout(@connect_timeout, ConnectionTimeout) do
TCPSocket.new(host, port)
end

0 comments on commit 2c83589

Please sign in to comment.