Software /
code /
prosody
Comparison
net/adns.lua @ 1203:23725bfdeed5
net.adns: Add support for cancelling a non-blocking lookup, optionally calling the handler
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 26 May 2009 21:48:32 +0100 |
parent | 1005:0eed5db7758d |
child | 1207:6842bacddfcb |
comparison
equal
deleted
inserted
replaced
1202:e69fafc14491 | 1203:23725bfdeed5 |
---|---|
14 handler(peek); | 14 handler(peek); |
15 return; | 15 return; |
16 end | 16 end |
17 log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running())); | 17 log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running())); |
18 dns.query(qname, qtype, qclass); | 18 dns.query(qname, qtype, qclass); |
19 coroutine.yield(nil); -- Wait for reply | 19 coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply |
20 log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running())); | 20 log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running())); |
21 local ok, err = pcall(handler, dns.peek(qname, qtype, qclass)); | 21 local ok, err = pcall(handler, dns.peek(qname, qtype, qclass)); |
22 if not ok then | 22 if not ok then |
23 log("debug", "Error in DNS response handler: %s", tostring(err)); | 23 log("debug", "Error in DNS response handler: %s", tostring(err)); |
24 end | 24 end |
25 end)(dns.peek(qname, qtype, qclass)); | 25 end)(dns.peek(qname, qtype, qclass)); |
26 end | |
27 | |
28 function cancel(handle, call_handler) | |
29 dns.cancel(handle); | |
30 if call_handler then | |
31 handle[4]() | |
32 end | |
26 end | 33 end |
27 | 34 |
28 function new_async_socket(sock) | 35 function new_async_socket(sock) |
29 local newconn = {}; | 36 local newconn = {}; |
30 local listener = {}; | 37 local listener = {}; |