net.dns: Handle being loaded outside of Prosody
authorKim Alvefur <zash@zash.se>
Mon, 24 Feb 2020 20:21:46 +0100
changeset 10668 c2b79b44ded7
parent 10667 fd651ba2317f
child 10670 dfc8257d8445
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.
net/dns.lua
--- a/net/dns.lua	Mon Feb 24 18:38:09 2020 +0100
+++ b/net/dns.lua	Mon Feb 24 20:21:46 2020 +0100
@@ -13,7 +13,7 @@
 
 
 local socket = require "socket";
-local timer = require "util.timer";
+local have_timer, timer = pcall(require, "util.timer");
 local new_ip = require "util.ip".new_ip;
 local have_util_net, util_net = pcall(require, "util.net");
 
@@ -871,7 +871,7 @@
 		set(self.wanted, qclass, qtype, qname, co, true);
 	end
 	
-	if timer and self.timeout then
+	if have_timer and self.timeout then
 		local num_servers = #self.server;
 		local i = 1;
 		timer.add_task(self.timeout, function ()