Skip to content

Commit

Permalink
Add :timeout parameter to clients, which will raise
Browse files Browse the repository at this point in the history
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
Jared Kuolt committed Sep 21, 2009
1 parent 4e4cb23 commit 2c83589
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/bunny/client08.rb
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/bunny/client09.rb
Expand Up @@ -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

Expand Down Expand Up @@ -459,4 +460,4 @@ def buffer
end

end
end
end
6 changes: 4 additions & 2 deletions lib/qrack/client.rb
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2c83589

Please sign in to comment.