net.adns: Add support for cancelling a non-blocking lookup, optionally calling the handler

Tue, 26 May 2009 21:48:32 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 26 May 2009 21:48:32 +0100
changeset 1203
23725bfdeed5
parent 1202
e69fafc14491
child 1204
dea89234e545

net.adns: Add support for cancelling a non-blocking lookup, optionally calling the handler

net/adns.lua file | annotate | diff | comparison | revisions
--- a/net/adns.lua	Tue May 26 21:47:25 2009 +0100
+++ b/net/adns.lua	Tue May 26 21:48:32 2009 +0100
@@ -16,7 +16,7 @@
 				end
 				log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running()));
 				dns.query(qname, qtype, qclass);
-				coroutine.yield(nil); -- Wait for reply
+				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));
 				if not ok then
@@ -25,6 +25,13 @@
 			end)(dns.peek(qname, qtype, qclass));
 end
 
+function cancel(handle, call_handler)
+	dns.cancel(handle);
+	if call_handler then
+		handle[4]()
+	end
+end
+
 function new_async_socket(sock)
 	local newconn = {};
 	local listener = {};

mercurial