~ubuntu-branches/ubuntu/precise/crossroads/precise

« back to all changes in this revision

Viewing changes to xr/ipstore/clearoldest.cc

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ritter
  • Date: 2010-07-05 16:27:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100705162700-0g08tfav8ee9y51u
Tags: upstream-2.65
ImportĀ upstreamĀ versionĀ 2.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
8
    Mutex::lock(&store);
 
9
 
 
10
    dump();
 
11
    
 
12
    // Find oldest entry.
 
13
    for (StoreMap::iterator iter = store.begin();
 
14
         iter != store.end();
 
15
         iter++) {
 
16
        if ((*iter).second.lastaccess < oldest_time) {
 
17
            oldest_time = (*iter).second.lastaccess;
 
18
            oldest_entry = iter;
 
19
            found = true;
 
20
        }
 
21
    }
 
22
 
 
23
    // Kill it if we got it.
 
24
    if (found) {
 
25
        if (config.debug()) {
 
26
            Timestamp tm((*oldest_entry).second.lastaccess);
 
27
            _debugmsg(Mstr("Erasing oldest IP store entry: ") +
 
28
                      Mstr(inet_ntoa(oldest_entry->first)) + " on " +
 
29
                      tm.desc() + "\n");
 
30
        }
 
31
        store.erase(oldest_entry);
 
32
    }
 
33
 
 
34
    Mutex::unlock(&store);
 
35
    dump();
 
36
}