net/adns.lua

changeset 3956
32ec833c2edf
parent 3326
fb95015bc646
equal deleted inserted replaced
3955:a096700d23d9 3956:32ec833c2edf
24 log("debug", "Records for %s already cached, using those...", qname); 24 log("debug", "Records for %s already cached, using those...", qname);
25 handler(peek); 25 handler(peek);
26 return; 26 return;
27 end 27 end
28 log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running())); 28 log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running()));
29 dns.query(qname, qtype, qclass); 29 local ok, err = dns.query(qname, qtype, qclass);
30 coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply 30 if ok then
31 log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running())); 31 coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply
32 local ok, err = pcall(handler, dns.peek(qname, qtype, qclass)); 32 log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running()));
33 end
34 if ok then
35 ok, err = pcall(handler, dns.peek(qname, qtype, qclass));
36 else
37 log("error", "Error sending DNS query: %s", err);
38 ok, err = pcall(handler, nil, err);
39 end
33 if not ok then 40 if not ok then
34 log("error", "Error in DNS response handler: %s", tostring(err)); 41 log("error", "Error in DNS response handler: %s", tostring(err));
35 end 42 end
36 end)(dns.peek(qname, qtype, qclass)); 43 end)(dns.peek(qname, qtype, qclass));
37 end 44 end

mercurial