Mercurial > prosody-hg
comparison net/adns.lua @ 4024:d2f80697c329
net.adns: Handle dns.query() failures, and pass error to handler
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 24 Dec 2010 04:52:40 +0000 |
| parents | fb95015bc646 |
| children | 764922062c38 |
comparison
equal
deleted
inserted
replaced
| 4023:7910f36e2791 | 4024:d2f80697c329 |
|---|---|
| 24 log("debug", "Records for %s already cached, using those...", qname); | 24 log("debug", "Records for %s already cached, using those...", qname); |
| 25 handler(peek); | 25 handler(peek); |
| 26 return; | 26 return; |
| 27 end | 27 end |
| 28 log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running())); | 28 log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running())); |
| 29 dns.query(qname, qtype, qclass); | 29 local ok, err = dns.query(qname, qtype, qclass); |
| 30 coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply | 30 if ok then |
| 31 log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running())); | 31 coroutine.yield({ qclass or "IN", qtype or "A", qname, coroutine.running()}); -- Wait for reply |
| 32 local ok, err = pcall(handler, dns.peek(qname, qtype, qclass)); | 32 log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running())); |
| 33 end | |
| 34 if ok then | |
| 35 ok, err = pcall(handler, dns.peek(qname, qtype, qclass)); | |
| 36 else | |
| 37 log("error", "Error sending DNS query: %s", err); | |
| 38 ok, err = pcall(handler, nil, err); | |
| 39 end | |
| 33 if not ok then | 40 if not ok then |
| 34 log("error", "Error in DNS response handler: %s", tostring(err)); | 41 log("error", "Error in DNS response handler: %s", tostring(err)); |
| 35 end | 42 end |
| 36 end)(dns.peek(qname, qtype, qclass)); | 43 end)(dns.peek(qname, qtype, qclass)); |
| 37 end | 44 end |
