jdunphy (owner)

Revisions

gist: 227314 Download_button fork
public
Public Clone URL: git://gist.github.com/227314.git
Embed All Files: show embed
memcache.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    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