net.dns: Add support for cancelling a coroutine-based request

Tue, 26 May 2009 21:47:25 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 26 May 2009 21:47:25 +0100
changeset 1202
e69fafc14491
parent 1201
9d5c1b2cf89c
child 1203
23725bfdeed5

net.dns: Add support for cancelling a coroutine-based request

net/dns.lua file | annotate | diff | comparison | revisions
--- a/net/dns.lua	Tue May 26 04:51:05 2009 +0100
+++ b/net/dns.lua	Tue May 26 21:47:25 2009 +0100
@@ -21,8 +21,8 @@
 local coroutine, io, math, socket, string, table =
       coroutine, io, math, socket, string, table
 
-local ipairs, next, pairs, print, setmetatable, tostring, assert, error =
-      ipairs, next, pairs, print, setmetatable, tostring, assert, error
+local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack =
+      ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack
 
 local get, set = ztact.get, ztact.set
 
@@ -711,6 +711,12 @@
   return response
 end
 
+function resolver:cancel(data)
+	local cos = get (self.wanted, unpack(data, 1, 3))
+	if cos then
+		cos[data[4]] = nil;
+	end
+end
 
 function resolver:pulse ()    -- - - - - - - - - - - - - - - - - - - - -  pulse
 
@@ -847,6 +853,8 @@
 function dns.feed (...)    -- - - - - - - - - - - - - - - - - - - - - -  feed
   return resolve (resolver.feed, ...)  end
 
+function dns.cancel(...)   -- - - - - - - - - - - - - - - - - - - - - -  cancel
+  return resolve(resolver.cancel, ...) end
 
 function dns:socket_wrapper_set (...)    -- - - - - - - - -  socket_wrapper_set
   return resolve (resolver.socket_wrapper_set, ...)  end

mercurial