#include "statbag.hh"
#include <map>
#include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
extern StatBag S;
PacketCache::PacketCache()
{
d_maps.resize(1024);
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
pthread_rwlock_init(&mc.d_mut, 0);
}
{
// WriteLock l(&d_mut);
vector<WriteLock*> locks;
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
locks.push_back(new WriteLock(&mc.d_mut));
}
- BOOST_FOREACH(WriteLock* wl, locks) {
+ for(auto wl : locks) {
delete wl;
}
}
string value;
bool haveSomething;
{
- MapCombo& mc=getMap(p->qdomain);
+ auto& mc=getMap(p->qdomain);
TryReadLock l(&mc.d_mut); // take a readlock here
if(!l.gotIt()) {
S.inc("deferred-cache-lookup");
val.zoneID = zoneID;
val.hasEDNS = EDNS;
- MapCombo& mc = getMap(val.qname);
+ auto& mc = getMap(val.qname);
+
TryWriteLock l(&mc.d_mut);
if(l.gotIt()) {
bool success;
int PacketCache::purge()
{
int delcount=0;
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
WriteLock l(&mc.d_mut);
delcount+=mc.d_map.size();
mc.d_map.clear();
string prefix(match);
prefix.resize(prefix.size()-1);
DNSName dprefix(prefix);
- for(MapCombo& mc : d_maps) {
+ for(auto& mc : d_maps) {
WriteLock l(&mc.d_mut);
cmap_t::const_iterator iter = mc.d_map.lower_bound(tie(dprefix));
auto start=iter;
}
else {
DNSName dn(match);
- auto mc = getMap(dn);
+ auto& mc = getMap(dn);
+
WriteLock l(&mc.d_mut);
auto range = mc.d_map.equal_range(tie(dn));
if(range.first != range.second) {
- delcount+=distance(range.first, range.second) - 1;
+ delcount+=distance(range.first, range.second);
mc.d_map.erase(range.first, range.second);
}
}
cleanup();
}
- MapCombo& mc=getMap(qname);
+ auto& mc=getMap(qname);
TryReadLock l(&mc.d_mut); // take a readlock here
if(!l.gotIt()) {
{
uint16_t qt = qtype.getCode();
//cerr<<"Lookup for maxReplyLen: "<<maxReplyLen<<endl;
- MapCombo& mc=getMap(qname);
+ auto& mc=getMap(qname);
cmap_t::const_iterator i=mc.d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen, dnssecOK, hasEDNS, *age));
time_t now=time(0);
bool ret=(i!=mc.d_map.end() && i->ttd > now);
{
int recursivePackets=0, nonRecursivePackets=0, queryCacheEntries=0, negQueryCacheEntries=0;
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
ReadLock l(&mc.d_mut);
for(cmap_t::const_iterator iter = mc.d_map.begin() ; iter != mc.d_map.end(); ++iter) {
int PacketCache::size()
{
uint64_t ret=0;
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
ReadLock l(&mc.d_mut);
ret+=mc.d_map.size();
}
void PacketCache::cleanup()
{
*d_statnumentries=AtomicCounter(0);
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
ReadLock l(&mc.d_mut);
*d_statnumentries+=mc.d_map.size();
time_t now=time(0);
DLOG(L<<"Starting cache clean"<<endl);
//unsigned int totErased=0;
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
WriteLock wl(&mc.d_mut);
typedef cmap_t::nth_index<1>::type sequence_t;
sequence_t& sidx=mc.d_map.get<1>();
// cerr<<"erased: "<<totErased<<endl;
*d_statnumentries=AtomicCounter(0);
- BOOST_FOREACH(MapCombo& mc, d_maps) {
+ for(auto& mc : d_maps) {
ReadLock l(&mc.d_mut);
*d_statnumentries+=mc.d_map.size();
}
int counter=0;
try {
for(counter = 0; counter < 100000; ++counter) {
- PC.insert(DNSName("hello ")+DNSName(boost::lexical_cast<string>(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
+ DNSName a=DNSName("hello ")+DNSName(boost::lexical_cast<string>(counter));
+ BOOST_CHECK_EQUAL(DNSName(a.toString()), a);
+
+ PC.insert(a, QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
+ if(!PC.purge(a.toString()))
+ BOOST_FAIL("Could not remove entry we just added to packet cache!");
+ PC.insert(a, QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
}
BOOST_CHECK_EQUAL(PC.size(), counter);
int delcounter=0;
for(delcounter=0; delcounter < counter/100; ++delcounter) {
- PC.purge((DNSName("hello ")+DNSName(boost::lexical_cast<string>(delcounter))).toString());
+ DNSName a=DNSName("hello ")+DNSName(boost::lexical_cast<string>(delcounter));
+ PC.purge(a.toString());
}
BOOST_CHECK_EQUAL(PC.size(), counter-delcounter);