Class: UringMachine::DNSResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/uringmachine/dns_resolver.rb

Overview

A basic DNS resolver implementation.

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ void

Initializes the DNS resolver.

Parameters:



13
14
15
16
17
18
19
# File 'lib/uringmachine/dns_resolver.rb', line 13

def initialize(machine)
  @machine = machine
  @requests = UM::Queue.new
  @nameservers = get_nameservers
  @fiber = @machine.spin { handle_requests_loop }
  @last_id = 0
end

Instance Method Details

#resolve(hostname, type) ⇒ String

Resolves the given hostname.

Parameters:

  • hostname (String)

    hostname

  • type (Symbol)

    DNS record type

Returns:

  • (String)

    IP address



26
27
28
29
# File 'lib/uringmachine/dns_resolver.rb', line 26

def resolve(hostname, type)
  @machine.push(@requests, [hostname, type, Fiber.current])
  @machine.yield
end