Comparison

net/dns.lua @ 10664:c2b79b44ded7

net.dns: Handle being loaded outside of Prosody `if timer ...` suggests that this was intended, but it did not work because net.timer depends on net.server which refuses to be loaded outside of Prosody.
author Kim Alvefur <zash@zash.se>
date Mon, 24 Feb 2020 20:21:46 +0100
parent 9952:6402bc76f51a
child 10955:7bcfac630b65
comparison
equal deleted inserted replaced
10663:fd651ba2317f 10664:c2b79b44ded7
11 -- reference: http://tools.ietf.org/html/rfc1035 11 -- reference: http://tools.ietf.org/html/rfc1035
12 -- reference: http://tools.ietf.org/html/rfc1876 (LOC) 12 -- reference: http://tools.ietf.org/html/rfc1876 (LOC)
13 13
14 14
15 local socket = require "socket"; 15 local socket = require "socket";
16 local timer = require "util.timer"; 16 local have_timer, timer = pcall(require, "util.timer");
17 local new_ip = require "util.ip".new_ip; 17 local new_ip = require "util.ip".new_ip;
18 local have_util_net, util_net = pcall(require, "util.net"); 18 local have_util_net, util_net = pcall(require, "util.net");
19 19
20 local _, windows = pcall(require, "util.windows"); 20 local _, windows = pcall(require, "util.windows");
21 local is_windows = (_ and windows) or os.getenv("WINDIR"); 21 local is_windows = (_ and windows) or os.getenv("WINDIR");
869 -- remember which coroutine wants the answer 869 -- remember which coroutine wants the answer
870 if co then 870 if co then
871 set(self.wanted, qclass, qtype, qname, co, true); 871 set(self.wanted, qclass, qtype, qname, co, true);
872 end 872 end
873 873
874 if timer and self.timeout then 874 if have_timer and self.timeout then
875 local num_servers = #self.server; 875 local num_servers = #self.server;
876 local i = 1; 876 local i = 1;
877 timer.add_task(self.timeout, function () 877 timer.add_task(self.timeout, function ()
878 if get(self.wanted, qclass, qtype, qname, co) then 878 if get(self.wanted, qclass, qtype, qname, co) then
879 if i < num_servers then 879 if i < num_servers then