Class: Rev::TCPSocket::TCPConnectResolver

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

Constant Summary

Constants inherited from DNSResolver

DNSResolver::DATAGRAM_SIZE, DNSResolver::DNS_PORT, DNSResolver::HOSTS, DNSResolver::RESOLV_CONF, 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.



174
175
176
177
# File 'lib/rev/socket.rb', line 174

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

Instance Method Details

#on_failureObject



198
199
200
201
202
203
204
205
# File 'lib/rev/socket.rb', line 198

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

#on_success(addr) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/rev/socket.rb', line 179

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