ne.d_name=qname;
ne.d_qtype=QType(0);
- pair<negcache_t::iterator, bool> res=s_negcache.insert(ne);
- if(!res.second) {
- s_negcache.erase(res.first);
- s_negcache.insert(ne);
- }
+ replacing_insert(s_negcache, ne);
negindic=true;
}
else if(i->d_place==DNSResourceRecord::ANSWER && i->qname==qname && i->qtype.getCode()==QType::CNAME && (!(qtype==QType(QType::CNAME)))) {
ne.d_name=qname;
ne.d_qtype=qtype;
if(qtype.getCode()) { // prevents us from blacking out a whole domain
- pair<negcache_t::iterator, bool> res=s_negcache.insert(ne);
- if(!res.second) {
- s_negcache.erase(res.first);
- s_negcache.insert(ne);
- }
+ replacing_insert(s_negcache, ne);
}
negindic=true;
}
};
extern RecursorStats g_stats;
+
+
+template<typename Index>
+std::pair<typename Index::iterator,bool>
+replacing_insert(Index& i,const typename Index::value_type& x)
+{
+ std::pair<typename Index::iterator,bool> res=i.insert(x);
+ if(!res.second)res.second=i.replace(res.first,x);
+ return res;
+}
+
#endif