752 |
752 |
753 -- remember the query |
753 -- remember the query |
754 self.active[id] = self.active[id] or {}; |
754 self.active[id] = self.active[id] or {}; |
755 self.active[id][question] = o; |
755 self.active[id][question] = o; |
756 |
756 |
|
757 local conn, err = self:getsocket(o.server) |
|
758 if not conn then |
|
759 return nil, err; |
|
760 end |
|
761 conn:send (o.packet) |
|
762 |
757 -- remember which coroutine wants the answer |
763 -- remember which coroutine wants the answer |
758 if co then |
764 if co then |
759 set(self.wanted, qclass, qtype, qname, co, true); |
765 set(self.wanted, qclass, qtype, qname, co, true); |
760 end |
766 end |
761 |
767 |
762 local conn, err = self:getsocket(o.server) |
|
763 if not conn then |
|
764 return nil, err; |
|
765 end |
|
766 conn:send (o.packet) |
|
767 |
|
768 if timer and self.timeout then |
768 if timer and self.timeout then |
769 local num_servers = #self.server; |
769 local num_servers = #self.server; |
770 local i = 1; |
770 local i = 1; |
771 timer.add_task(self.timeout, function () |
771 timer.add_task(self.timeout, function () |
772 if get(self.wanted, qclass, qtype, qname, co) then |
772 if get(self.wanted, qclass, qtype, qname, co) then |
859 end |
859 end |
860 |
860 |
861 -- retire the query |
861 -- retire the query |
862 local queries = self.active[response.header.id]; |
862 local queries = self.active[response.header.id]; |
863 queries[response.question.raw] = nil; |
863 queries[response.question.raw] = nil; |
864 |
864 |
865 if not next(queries) then self.active[response.header.id] = nil; end |
865 if not next(queries) then self.active[response.header.id] = nil; end |
866 if not next(self.active) then self:closeall(); end |
866 if not next(self.active) then self:closeall(); end |
867 |
867 |
868 -- was the query on the wanted list? |
868 -- was the query on the wanted list? |
869 local q = response.question[1]; |
869 local q = response.question[1]; |