Class: Coolio::TCPSocket::TCPConnectResolver

Inherits:
DNSResolver show all
Defined in:
lib/cool.io/socket.rb

Constant Summary

Constants inherited from DNSResolver

DNSResolver::DATAGRAM_SIZE, DNSResolver::DNS_PORT, DNSResolver::RETRIES, DNSResolver::TIMEOUT

Instance Method Summary collapse

Methods inherited from DNSResolver

#attach, #detach, hosts, #on_timeout

Methods inherited from IOWatcher

#attach, #detach, #disable, #enable, #on_readable, #on_writable

Methods included from Meta

#event_callback, #watcher_delegate

Methods inherited from Watcher

#attach, #attached?, #detach, #disable, #enable, #enabled?, #evloop

Constructor Details

#initialize(socket, host, port, *args) ⇒ TCPConnectResolver

Returns a new instance of TCPConnectResolver.



183
184
185
186
# File 'lib/cool.io/socket.rb', line 183

def initialize(socket, host, port, *args)
  @sock, @host, @port, @args = socket, host, port, args
  super(host)
end

Instance Method Details

#on_failureObject



207
208
209
210
211
212
213
214
# File 'lib/cool.io/socket.rb', line 207

def on_failure
  @sock.__send__(:on_resolve_failed)
  @sock.instance_eval do
    @_resolver = nil
    @_failed = true
  end
  return
end

#on_success(addr) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/cool.io/socket.rb', line 188

def on_success(addr)
  host, port, args = @host, @port, @args

  @sock.instance_eval do
    # DNSResolver only supports IPv4 so we can safely assume IPv4 address
    begin
      socket = TCPConnectSocket.new(::Socket::AF_INET, addr, port, host)
    rescue Errno::ENETUNREACH
      on_connect_failed
      return
    end

    initialize(socket, *args)
    @_connector = Socket::Connector.new(self, socket)
    @_resolver = nil
  end
  @sock.attach(evloop)
end