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, #_write_to_socket, #gets, #initialize, #read, #timeout=, #write, #write_timeout=

Class Method Details

.connect(host, port, timeout) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/redis/connection/ruby.rb', line 130

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



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/redis/connection/ruby.rb', line 175

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