if ret ~= 0 then return nil, knot_strerror(ret) end
return true
end,
- clear = function (pkt) return C.kr_pkt_recycle(pkt) end,
+ recycle = function (pkt)
+ assert(pkt ~= nil)
+ local ret = C.kr_pkt_recycle(pkt)
+ if ret ~= 0 then return nil, knot_strerror(ret) end
+ return true
+ end,
question = function(pkt, qname, qclass, qtype)
assert(pkt ~= nil)
assert(qclass ~= nil, string.format('invalid class: %s', qclass))
pkt:rcode(kres.rcode.NXDOMAIN)
-- Clear answer and write QUESTION
- pkt:clear()
+ pkt:recycle()
pkt:question('\7blocked', kres.class.IN, kres.type.SOA)
-- Start writing data
pkt:begin(kres.section.ANSWER)
local qname = pkt:qname()
local qclass = pkt:qclass()
local qtype = pkt:qtype()
- pkt:clear()
+ pkt:recycle()
pkt:question(qname, qclass, qtype)
for i = 1, ancount do
local rr = records[i]
same(parsed:id(), pkt:id(), 'parsed packet has same MSGID')
same(parsed:ancount(), pkt:ancount(), 'parsed packet has same answer count')
same(parsed:tostring(), pkt:tostring(), 'parsed packet is equal to source packet')
+ -- Test recycling of packets
+ ok(pkt:recycle(), 'recycle() works')
+ is(pkt:ancount(), 0, 'recycle() clears records')
+ is(pkt:qname(), nil, 'recycle() clears question')
+ is(#pkt:towire(), 12, 'recycle() clears the packet wireformat')
end
return {