Class: Redis::Connection::TCPSocket

Inherits:
Socket
  • Object
show all
Includes:
SocketMixin
Defined in:
lib/redis/connection/ruby.rb,
lib/redis/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=, #write, #write_timeout=

Class Method Details

.connect(host, port, timeout) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/redis/connection/ruby.rb', line 108

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

.connect_addrinfo(addrinfo, port, timeout) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/redis/connection/ruby.rb', line 150

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

  begin
    sock.connect_nonblock(sockaddr)
  rescue Errno::EINPROGRESS
    raise TimeoutError unless sock.wait_writable(timeout)

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

  sock
end