Created
November 5, 2009 19:26
-
-
Save jdunphy/227314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def socket | |
%return @sock if @sock and not @sock.closed? | |
@sock = nil | |
# If the host was dead, don't retry for a while. | |
return if @retry and @retry > Time.now | |
# Attempt to connect if not already connected. | |
begin | |
@sock = connect_to(@host, @port, @timeout) | |
@sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 | |
@retry = nil | |
@status = 'CONNECTED' | |
rescue SocketError, SystemCallError, IOError => err | |
logger.warn { "Unable to open socket: #{err.class.name}, #{err.message}" } if logger | |
mark_dead err | |
end | |
return @sock | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment