Class: Resolv::DNS::Requester

Inherits:
Object
  • Object
show all
Defined in:
lib/shuttlecraft/resolv.rb

Defined Under Namespace

Classes: MDNSOneShot

Instance Method Summary collapse

Instance Method Details

#request(sender, tout) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shuttlecraft/resolv.rb', line 10

def request(sender, tout)
  start = Time.now
  timelimit = start + tout
  begin
    sender.send
  rescue Errno::EHOSTUNREACH
    # multi-homed IPv6 may generate this
    raise ResolvTimeout
  end
  while true
    before_select = Time.now
    timeout = timelimit - before_select
    if timeout <= 0
      raise ResolvTimeout
    end
    select_result = IO.select(@socks, nil, nil, timeout)
    if !select_result
      after_select = Time.now
      next if after_select < timelimit
      raise ResolvTimeout
    end
    begin
      reply, from = recv_reply(select_result[0])
    rescue Errno::ECONNREFUSED, # GNU/Linux, FreeBSD
           Errno::ECONNRESET # Windows
      # No name server running on the server?
      # Don't wait anymore.
      raise ResolvTimeout
    end
    begin
      msg = Message.decode(reply)
    rescue DecodeError
      next # broken DNS message ignored
    end
    if s = sender_for(from, msg)
      break
    else
      # unexpected DNS message ignored
    end
  end
  return msg, s.data
end

#sender_for(addr, msg) ⇒ Object



53
54
55
# File 'lib/shuttlecraft/resolv.rb', line 53

def sender_for(addr, msg)
  @senders[[addr,msg.id]]
end