123456789_123456789_123456789_123456789_123456789_

Class: EventMachine::DNS::Resolver

Relationships & Source Files
Inherits: Object
Defined in: lib/em/resolver.rb

Constant Summary

Class Attribute Summary

Class Method Summary

Class Attribute Details

.nameservers (rw)

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 36

def self.nameservers
  return @nameservers if @nameservers

  if windows?
    _, ns = Win32::Resolv.get_resolv_info
    return @nameservers = ns || []
  end

  @nameservers = []
  IO.readlines('/etc/resolv.conf').each do |line|
    if line =~ /^nameserver (.+)$/
      @nameservers << $1.split(/\s+/).first
    end
  end

  @nameservers
rescue
  @nameservers = []
end

.nameservers=(ns) (rw)

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 32

def self.nameservers=(ns)
  @nameservers = ns
end

.windows?Boolean (readonly)

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 5

def self.windows?
  if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
    require 'win32/resolv'
    true
  else
    false
  end
end

Class Method Details

.hosts

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 60

def self.hosts
  return @hosts if @hosts

  @hosts = {}
  IO.readlines(HOSTS_FILE).each do |line|
    next if line =~ /^#/
    addr, host = line.split(/\s+/)

    next unless addr && host
    @hosts[host] ||= []
    @hosts[host] << addr
  end

  @hosts
rescue
  @hosts = {}
end

.nameserver

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 56

def self.nameserver
  nameservers.shuffle.first
end

.resolve(hostname)

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 20

def self.resolve(hostname)
  Request.new(socket, hostname)
end

.socket

[ GitHub ]

  
# File 'lib/em/resolver.rb', line 24

def self.socket
  if @socket && @socket.error?
    @socket = Socket.open
  else
    @socket ||= Socket.open
  end
end