Comparison

net/dns.lua @ 6312:1940a014aeca

Merge 0.9->0.10
author Matthew Wild <mwild1@gmail.com>
date Fri, 25 Jul 2014 13:01:57 +0100
parent 6289:a29cc79295e6
parent 6310:d232bb1bbe1e
child 6464:737c81bd898e
comparison
equal deleted inserted replaced
6306:c6d9e21cd5f2 6312:1940a014aeca
750 self.active[id][question] = o; 750 self.active[id][question] = o;
751 751
752 -- remember which coroutine wants the answer 752 -- remember which coroutine wants the answer
753 if co then 753 if co then
754 set(self.wanted, qclass, qtype, qname, co, true); 754 set(self.wanted, qclass, qtype, qname, co, true);
755 --set(self.yielded, co, qclass, qtype, qname, true);
756 end 755 end
757 756
758 local conn, err = self:getsocket(o.server) 757 local conn, err = self:getsocket(o.server)
759 if not conn then 758 if not conn then
760 return nil, err; 759 return nil, err;
775 conn:send(o.packet); 774 conn:send(o.packet);
776 return self.timeout; 775 return self.timeout;
777 end 776 end
778 end 777 end
779 -- Tried everything, failed 778 -- Tried everything, failed
780 self:cancel(qclass, qtype, qname, co, true); 779 self:cancel(qclass, qtype, qname);
781 end 780 end
782 end) 781 end)
783 end 782 end
784 return true; 783 return true;
785 end 784 end
863 -- was the query on the wanted list? 862 -- was the query on the wanted list?
864 local q = response.question[1]; 863 local q = response.question[1];
865 local cos = get(self.wanted, q.class, q.type, q.name); 864 local cos = get(self.wanted, q.class, q.type, q.name);
866 if cos then 865 if cos then
867 for co in pairs(cos) do 866 for co in pairs(cos) do
868 set(self.yielded, co, q.class, q.type, q.name, nil);
869 if coroutine.status(co) == "suspended" then coroutine.resume(co); end 867 if coroutine.status(co) == "suspended" then coroutine.resume(co); end
870 end 868 end
871 set(self.wanted, q.class, q.type, q.name, nil); 869 set(self.wanted, q.class, q.type, q.name, nil);
872 end 870 end
873 end 871 end
904 local q = response.question[1]; 902 local q = response.question[1];
905 if q then 903 if q then
906 local cos = get(self.wanted, q.class, q.type, q.name); 904 local cos = get(self.wanted, q.class, q.type, q.name);
907 if cos then 905 if cos then
908 for co in pairs(cos) do 906 for co in pairs(cos) do
909 set(self.yielded, co, q.class, q.type, q.name, nil);
910 if coroutine.status(co) == "suspended" then coroutine.resume(co); end 907 if coroutine.status(co) == "suspended" then coroutine.resume(co); end
911 end 908 end
912 set(self.wanted, q.class, q.type, q.name, nil); 909 set(self.wanted, q.class, q.type, q.name, nil);
913 end 910 end
914 end 911 end
915 end 912 end
916 913
917 return response; 914 return response;
918 end 915 end
919 916
920 function resolver:cancel(qclass, qtype, qname, co, call_handler) 917 function resolver:cancel(qclass, qtype, qname)
921 local cos = get(self.wanted, qclass, qtype, qname); 918 local cos = get(self.wanted, qclass, qtype, qname);
922 if cos then 919 if cos then
923 if call_handler then 920 for co in pairs(cos) do
924 coroutine.resume(co); 921 if coroutine.status(co) == "suspended" then coroutine.resume(co); end
925 end 922 end
926 cos[co] = nil; 923 set(self.wanted, qclass, qtype, qname, nil);
927 end 924 end
928 end 925 end
929 926
930 function resolver:pulse() -- - - - - - - - - - - - - - - - - - - - - pulse 927 function resolver:pulse() -- - - - - - - - - - - - - - - - - - - - - pulse
931 --print(':pulse'); 928 --print(':pulse');
1042 1039
1043 1040
1044 function dns.resolver () -- - - - - - - - - - - - - - - - - - - - - resolver 1041 function dns.resolver () -- - - - - - - - - - - - - - - - - - - - - resolver
1045 -- this function seems to be redundant with resolver.new () 1042 -- this function seems to be redundant with resolver.new ()
1046 1043
1047 local r = { active = {}, cache = {}, unsorted = {}, wanted = {}, yielded = {}, best_server = 1 }; 1044 local r = { active = {}, cache = {}, unsorted = {}, wanted = {}, best_server = 1 };
1048 setmetatable (r, resolver); 1045 setmetatable (r, resolver);
1049 setmetatable (r.cache, cache_metatable); 1046 setmetatable (r.cache, cache_metatable);
1050 setmetatable (r.unsorted, { __mode = 'kv' }); 1047 setmetatable (r.unsorted, { __mode = 'kv' });
1051 return r; 1048 return r;
1052 end 1049 end