net.adns: Handle dns.query() failures, and pass error to handler

Fri, 24 Dec 2010 04:52:40 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 24 Dec 2010 04:52:40 +0000
changeset 3956
32ec833c2edf
parent 3955
a096700d23d9
child 3957
b5223a74e07e

net.adns: Handle dns.query() failures, and pass error to handler

net/adns.lua file | annotate | diff | comparison | revisions
--- a/net/adns.lua	Fri Dec 24 04:52:13 2010 +0000
+++ b/net/adns.lua	Fri Dec 24 04:52:40 2010 +0000
@@ -26,10 +26,17 @@
 					return;
 				end
 				log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running()));
-				dns.query(qname, qtype, qclass);
-				coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply
-				log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running()));
-				local ok, err = pcall(handler, dns.peek(qname, qtype, qclass));
+				local ok, err = dns.query(qname, qtype, qclass);
+				if ok then
+					coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply
+					log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running()));
+				end
+				if ok then
+					ok, err = pcall(handler, dns.peek(qname, qtype, qclass));
+				else
+					log("error", "Error sending DNS query: %s", err);
+					ok, err = pcall(handler, nil, err);
+				end
 				if not ok then
 					log("error", "Error in DNS response handler: %s", tostring(err));
 				end

mercurial