X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=net%2Fdns.lua;h=c905f56c5d612565d416a2fcd85321cc64f58b7a;hb=7e15c408cdd8564b9e811bf6e5f76b2b76f43ca5;hp=23a453aa82e1c49be9e269655240f7238f43e463;hpb=70281db08732799bcd1ff4dcc3ca51b1388f1375;p=prosody.git diff --git a/net/dns.lua b/net/dns.lua index 23a453aa..c905f56c 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -158,8 +158,6 @@ resolver.__index = resolver; resolver.timeout = default_timeout; -local SRV_tostring; - local function default_rr_tostring(rr) local rr_val = rr.type and rr[rr.type:lower()]; if type(rr_val) ~= "string" then @@ -170,8 +168,13 @@ end local special_tostrings = { LOC = resolver.LOC_tostring; - MX = function (rr) return string.format('%2i %s', rr.pref, rr.mx); end; - SRV = SRV_tostring; + MX = function (rr) + return string.format('%2i %s', rr.pref, rr.mx); + end; + SRV = function (rr) + local s = rr.srv; + return string.format('%5d %5d %5d %s', s.priority, s.weight, s.port, s.target); + end; }; local rr_metatable = {}; -- - - - - - - - - - - - - - - - - - - rr_metatable @@ -475,12 +478,6 @@ function resolver:PTR(rr) rr.ptr = self:name(); end -function SRV_tostring(rr) -- - - - - - - - - - - - - - - - - - SRV_tostring - local s = rr.srv; - return string.format( '%5d %5d %5d %s', s.priority, s.weight, s.port, s.target ); -end - - function resolver:TXT(rr) -- - - - - - - - - - - - - - - - - - - - - - TXT rr.txt = self:sub (rr.rdlength); end @@ -602,7 +599,11 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket local sock = self.socket[servernum]; if sock then return sock; end - sock = socket.udp(); + local err; + sock, err = socket.udp(); + if not sock then + return nil, err; + end if self.socket_wrapper then sock = self.socket_wrapper(sock, self); end sock:settimeout(0); -- todo: attempt to use a random port, fallback to 0 @@ -718,7 +719,10 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query --set(self.yielded, co, qclass, qtype, qname, true); end - local conn = self:getsocket(o.server) + local conn, err = self:getsocket(o.server) + if not conn then + return nil, err; + end conn:send (o.packet) if timer and self.timeout then @@ -730,16 +734,18 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query i = i + 1; self:servfail(conn); o.server = self.best_server; - conn = self:getsocket(o.server); - conn:send(o.packet); - return self.timeout; - else - -- Tried everything, failed - self:cancel(qclass, qtype, qname, co, true); + conn, err = self:getsocket(o.server); + if conn then + conn:send(o.packet); + return self.timeout; + end end + -- Tried everything, failed + self:cancel(qclass, qtype, qname, co, true); end end) end + return true; end function resolver:servfail(sock)