Class: Redis2::Connection::TCPSocket

Inherits:
Socket
  • Object
show all
Includes:
SocketMixin
Defined in:
lib/redis2/connection/ruby.rb,
lib/redis2/connection/ruby.rb

Constant Summary

Constants included from SocketMixin

SocketMixin::CRLF

Class Method Summary collapse

Methods included from SocketMixin

#_read_from_socket, #gets, #initialize, #read, #timeout=

Class Method Details

.connect(host, port, timeout) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/redis2/connection/ruby.rb', line 72

def self.connect(host, port, timeout)
  Timeout.timeout(timeout) do
    sock = new(host, port)
    sock
  end
rescue Timeout::Error
  raise TimeoutError
end

.connect_addrinfo(ai, port, timeout) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/redis2/connection/ruby.rb', line 117

def self.connect_addrinfo(ai, port, timeout)
  sock = new(::Socket.const_get(ai[0]), Socket::SOCK_STREAM, 0)
  sockaddr = ::Socket.pack_sockaddr_in(port, ai[3])

  begin
    sock.connect_nonblock(sockaddr)
  rescue Errno::EINPROGRESS
    if IO.select(nil, [sock], nil, timeout) == nil
      raise TimeoutError
    end

    begin
      sock.connect_nonblock(sockaddr)
    rescue Errno::EISCONN
    end
  end

  sock
end