Diff

net/dns.lua @ 3327:b447682f2a8d

net.dns: Make timeout configurable (default 15s)
author Matthew Wild <mwild1@gmail.com>
date Mon, 05 Jul 2010 12:09:50 +0100
parent 3326:fb95015bc646
child 3328:5ac4fbbfb74d
line wrap: on
line diff
--- a/net/dns.lua	Mon Jul 05 12:05:46 2010 +0100
+++ b/net/dns.lua	Mon Jul 05 12:09:50 2010 +0100
@@ -29,7 +29,7 @@
 
 local get, set = ztact.get, ztact.set;
 
-local dns_timeout = 15;
+local default_timeout = 15;
 
 -------------------------------------------------- module dns
 module('dns')
@@ -118,6 +118,7 @@
 local resolver = {};
 resolver.__index = resolver;
 
+resolver.timeout = default_timeout;
 
 local SRV_tostring;
 
@@ -684,10 +685,10 @@
 	local conn = self:getsocket(o.server)
 	conn:send (o.packet)
 	
-	if timer then
+	if timer and self.timeout then
 		local num_servers = #self.server;
 		local i = 1;
-		timer.add_task(dns_timeout, function ()
+		timer.add_task(self.timeout, function ()
 			if get(self.wanted, qclass, qtype, qname, co) then
 				if i < num_servers then
 					i = i + 1;
@@ -695,7 +696,7 @@
 					o.server = self.best_server;
 					conn = self:getsocket(o.server);
 					conn:send(o.packet);
-					return dns_timeout;
+					return self.timeout;
 				else
 					-- Tried everything, failed
 					resolver:cancel(qclass, qtype, qname, co, true);
@@ -744,6 +745,10 @@
 	end
 end
 
+function resolver:settimeout(seconds)
+	self.timeout = seconds;
+end
+
 function resolver:receive(rset)    -- - - - - - - - - - - - - - - - -  receive
 	--print('receive');  print(self.socket);
 	self.time = socket.gettime();