- if num == self.best_server then
- self.best_server = self.best_server + 1
- if self.best_server > #self.server then
- -- Exhausted all servers, try first again
- self.best_server = 1
- end
- end
-end
-
-function resolver:receive (rset) -- - - - - - - - - - - - - - - - - receive
-
- --print 'receive' print (self.socket)
- self.time = socket.gettime ()
- rset = rset or self.socket
-
- local response
- for i,sock in pairs (rset) do
-
- if self.socketset[sock] then
- local packet = sock:receive ()
- if packet then
-
- response = self:decode (packet)
- if response then
- --print 'received response'
- --self.print (response)
-
- for i,section in pairs { 'answer', 'authority', 'additional' } do
- for j,rr in pairs (response[section]) do
- self:remember (rr, response.question[1].type) end end
-
- -- retire the query
- local queries = self.active[response.header.id]
- if queries[response.question.raw] then
- queries[response.question.raw] = nil end
- if not next (queries) then self.active[response.header.id] = nil end
- if not next (self.active) then self:closeall () end
-
- -- was the query on the wanted list?
- local q = response.question
- 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)
- end end end end end
-
- return response
- end
-
-
-function resolver:feed(sock, packet)
- --print 'receive' print (self.socket)
- self.time = socket.gettime ()
-
- local response = self:decode (packet)
- if response then
- --print 'received response'
- --self.print (response)
-
- for i,section in pairs { 'answer', 'authority', 'additional' } do
- for j,rr in pairs (response[section]) do
- self:remember (rr, response.question[1].type)
- end
- end
-
- -- retire the query
- local queries = self.active[response.header.id]
- if queries[response.question.raw] then
- queries[response.question.raw] = nil
- end
- if not next (queries) then self.active[response.header.id] = nil end
- if not next (self.active) then self:closeall () end
-
- -- was the query on the wanted list?
- local q = response.question[1]
- if q then
- 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)
- end
- end
- end