Mercurial > prosody-hg
comparison net/dns.lua @ 1202:e69fafc14491
net.dns: Add support for cancelling a coroutine-based request
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 26 May 2009 21:47:25 +0100 |
| parents | 2c0b9e3c11c3 |
| children | 841d61be198f |
comparison
equal
deleted
inserted
replaced
| 1201:9d5c1b2cf89c | 1202:e69fafc14491 |
|---|---|
| 19 local require = require | 19 local require = require |
| 20 | 20 |
| 21 local coroutine, io, math, socket, string, table = | 21 local coroutine, io, math, socket, string, table = |
| 22 coroutine, io, math, socket, string, table | 22 coroutine, io, math, socket, string, table |
| 23 | 23 |
| 24 local ipairs, next, pairs, print, setmetatable, tostring, assert, error = | 24 local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack = |
| 25 ipairs, next, pairs, print, setmetatable, tostring, assert, error | 25 ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack |
| 26 | 26 |
| 27 local get, set = ztact.get, ztact.set | 27 local get, set = ztact.get, ztact.set |
| 28 | 28 |
| 29 | 29 |
| 30 -------------------------------------------------- module dns | 30 -------------------------------------------------- module dns |
| 709 end | 709 end |
| 710 | 710 |
| 711 return response | 711 return response |
| 712 end | 712 end |
| 713 | 713 |
| 714 function resolver:cancel(data) | |
| 715 local cos = get (self.wanted, unpack(data, 1, 3)) | |
| 716 if cos then | |
| 717 cos[data[4]] = nil; | |
| 718 end | |
| 719 end | |
| 714 | 720 |
| 715 function resolver:pulse () -- - - - - - - - - - - - - - - - - - - - - pulse | 721 function resolver:pulse () -- - - - - - - - - - - - - - - - - - - - - pulse |
| 716 | 722 |
| 717 --print ':pulse' | 723 --print ':pulse' |
| 718 while self:receive() do end | 724 while self:receive() do end |
| 845 return resolve (resolver.query, ...) end | 851 return resolve (resolver.query, ...) end |
| 846 | 852 |
| 847 function dns.feed (...) -- - - - - - - - - - - - - - - - - - - - - - feed | 853 function dns.feed (...) -- - - - - - - - - - - - - - - - - - - - - - feed |
| 848 return resolve (resolver.feed, ...) end | 854 return resolve (resolver.feed, ...) end |
| 849 | 855 |
| 856 function dns.cancel(...) -- - - - - - - - - - - - - - - - - - - - - - cancel | |
| 857 return resolve(resolver.cancel, ...) end | |
| 850 | 858 |
| 851 function dns:socket_wrapper_set (...) -- - - - - - - - - socket_wrapper_set | 859 function dns:socket_wrapper_set (...) -- - - - - - - - - socket_wrapper_set |
| 852 return resolve (resolver.socket_wrapper_set, ...) end | 860 return resolve (resolver.socket_wrapper_set, ...) end |
| 853 | 861 |
| 854 | 862 |
