Class: Libuv::Dns

Inherits:
Q::DeferredPromise show all
Includes:
Listener, Net, Resource
Defined in:
lib/libuv/dns.rb

Constant Summary collapse

HINTS =
{
    :IPv4 => ::Libuv::Ext::UvAddrinfo.new,
    :IPv6 => ::Libuv::Ext::UvAddrinfo.new
}

Constants included from Net

Net::INET6_ADDRSTRLEN, Net::INET_ADDRSTRLEN, Net::IP_ARGUMENT_ERROR, Net::PORT_ARGUMENT_ERROR

Constants inherited from Q::Promise

Q::Promise::MAKE_PROMISE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Resource

#check_result, #check_result!, #resolve, #to_ptr

Methods inherited from Q::DeferredPromise

#resolved?, #then

Methods inherited from Q::Promise

#catch, #finally, #progress

Constructor Details

#initialize(loop, domain, port, hint = :IPv4) ⇒ Dns

Returns a new instance of Dns.

Parameters:

  • loop (::Libuv::Loop)

    loop this work request will be associated

  • domain (String)

    the domain name to resolve

  • port (Integer, String)

    the port we wish to use



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/libuv/dns.rb', line 34

def initialize(loop, domain, port, hint = :IPv4)
    super(loop, loop.defer)

    @domain = domain
    @port = port
    @hint = hint
    @complete = false
    @pointer = ::Libuv::Ext.allocate_request_getaddrinfo
    @error = nil    # error in callback

    @instance_id = @pointer.address
    error = check_result ::Libuv::Ext.getaddrinfo(@loop, @pointer, callback(:on_complete), domain, port.to_s, HINTS[hint])

    if error
        ::Libuv::Ext.free(@pointer)
        @complete = true
        @defer.reject(error)
    end
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/libuv/dns.rb', line 10

def domain
  @domain
end

#hintObject (readonly)

Returns the value of attribute hint.



12
13
14
# File 'lib/libuv/dns.rb', line 12

def hint
  @hint
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/libuv/dns.rb', line 11

def port
  @port
end

#resultsObject (readonly)

Returns the value of attribute results.



9
10
11
# File 'lib/libuv/dns.rb', line 9

def results
  @results
end

Instance Method Details

#completed?true, false

Indicates if the lookup has completed yet or not.

Returns:

  • (true, false)


57
58
59
# File 'lib/libuv/dns.rb', line 57

def completed?
    return @complete
end