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
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, Errno::ECONNRESET raise ResolvTimeout
end
begin
msg = Message.decode(reply)
rescue DecodeError
next end
if s = sender_for(from, msg)
break
else
end
end
return msg, s.data
end
|