net.websocket: Fix handling of 'protocol' argument
[prosody.git] / net / dns.lua
index bd5c260ec2f1a638843c662544139e1b2eb6e920..42bbdb013b80648f4dd0ec64128b4de9045bfcdf 100644 (file)
@@ -722,6 +722,14 @@ end
 function resolver:query(qname, qtype, qclass)    -- - - - - - - - - - -- query
        qname, qtype, qclass = standardize(qname, qtype, qclass)
 
+       local co = coroutine.running();
+       local q = get(self.wanted, qclass, qtype, qname);
+       if co and q then
+               -- We are already waiting for a reply to an identical query.
+               set(self.wanted, qclass, qtype, qname, co, true);
+               return true;
+       end
+
        if not self.server then self:adddefaultnameservers(); end
 
        local question = encodeQuestion(qname, qtype, qclass);
@@ -742,10 +750,8 @@ function resolver:query(qname, qtype, qclass)    -- - - - - - - - - - -- query
        self.active[id][question] = o;
 
        -- remember which coroutine wants the answer
-       local co = coroutine.running();
        if co then
                set(self.wanted, qclass, qtype, qname, co, true);
-               --set(self.yielded, co, qclass, qtype, qname, true);
        end
 
        local conn, err = self:getsocket(o.server)
@@ -770,7 +776,7 @@ function resolver:query(qname, qtype, qclass)    -- - - - - - - - - - -- query
                                        end
                                end
                                -- Tried everything, failed
-                               self:cancel(qclass, qtype, qname, co, true);
+                               self:cancel(qclass, qtype, qname);
                        end
                end)
        end
@@ -858,7 +864,6 @@ function resolver:receive(rset)    -- - - - - - - - - - - - - - - - -  receive
                                        local cos = get(self.wanted, q.class, q.type, q.name);
                                        if cos then
                                                for co in pairs(cos) do
-                                                       set(self.yielded, co, q.class, q.type, q.name, nil);
                                                        if coroutine.status(co) == "suspended" then coroutine.resume(co); end
                                                end
                                                set(self.wanted, q.class, q.type, q.name, nil);
@@ -899,7 +904,6 @@ function resolver:feed(sock, packet, force)
                        local cos = get(self.wanted, q.class, q.type, q.name);
                        if cos then
                                for co in pairs(cos) do
-                                       set(self.yielded, co, q.class, q.type, q.name, nil);
                                        if coroutine.status(co) == "suspended" then coroutine.resume(co); end
                                end
                                set(self.wanted, q.class, q.type, q.name, nil);
@@ -910,13 +914,13 @@ function resolver:feed(sock, packet, force)
        return response;
 end
 
-function resolver:cancel(qclass, qtype, qname, co, call_handler)
+function resolver:cancel(qclass, qtype, qname)
        local cos = get(self.wanted, qclass, qtype, qname);
        if cos then
-               if call_handler then
-                       coroutine.resume(co);
+               for co in pairs(cos) do
+                       if coroutine.status(co) == "suspended" then coroutine.resume(co); end
                end
-               cos[co] = nil;
+               set(self.wanted, qclass, qtype, qname, nil);
        end
 end
 
@@ -1037,7 +1041,7 @@ end
 function dns.resolver ()    -- - - - - - - - - - - - - - - - - - - - - resolver
        -- this function seems to be redundant with resolver.new ()
 
-       local r = { active = {}, cache = {}, unsorted = {}, wanted = {}, yielded = {}, best_server = 1 };
+       local r = { active = {}, cache = {}, unsorted = {}, wanted = {}, best_server = 1 };
        setmetatable (r, resolver);
        setmetatable (r.cache, cache_metatable);
        setmetatable (r.unsorted, { __mode = 'kv' });