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 = {}; |