clearoldest.cc (806B)
1 #include "ipstore" 2 3 void IPStore::clearoldest() { 4 time_t oldest_time = time(0) + 100; 5 StoreMap::iterator oldest_entry; 6 bool found = false; 7 static int lock; 8 9 mutex_lock(&lock); 10 11 dump(); 12 13 // Find oldest entry. 14 for (StoreMap::iterator iter = store.begin(); 15 iter != store.end(); 16 iter++) { 17 if ((*iter).second.lastaccess < oldest_time) { 18 oldest_time = (*iter).second.lastaccess; 19 oldest_entry = iter; 20 found = true; 21 } 22 } 23 24 // Kill it if we got it. 25 if (found) { 26 if (config.debug()) { 27 Timestamp tm((*oldest_entry).second.lastaccess); 28 debugmsg("Erasing oldest IP store entry: " << 29 inet2string(oldest_entry->first) << " on " << 30 tm.desc() << '\n'); 31 } 32 store.erase(oldest_entry); 33 } 34 35 mutex_unlock(&lock); 36 dump(); 37 }