File: ipstore

package info (click to toggle)
crossroads 2.65-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,664 kB
  • ctags: 355
  • sloc: cpp: 4,212; perl: 1,658; xml: 269; makefile: 186; sh: 46
file content (45 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef _IPSTORE_
#define _IPSTORE_

#include "sys/sys"
#include "config/config"
#include "timestamp/timestamp"
#include "balancer/balancer"
#include "ThreadsAndMutexes/mutex/mutex"

class IPStore {
public:
    struct ClientData {
	int targetbackend;
	time_t lastaccess;
    };

    struct ClientDataCmp {
	bool operator() (struct in_addr a, struct in_addr b) const {
	    long la, lb;
	    memcpy (&la, &a, sizeof(long));
	    memcpy (&lb, &b, sizeof(long));
	    return (la - lb) < 0;
	}
    };

    typedef  map<struct in_addr, ClientData, ClientDataCmp> StoreMap;
    
    static int target(struct in_addr clientip);
    static void activity(struct in_addr clientip, unsigned curbackend);
    static unsigned anticipated(unsigned bckend);
    static void clear(struct in_addr clientip);
    static void clearoldest();

    static void on()		{ onoff = true; }
    static void off()		{ onoff = false; }
    
private:
    static void dump();
    static void weed();
    
    static StoreMap store;
    static bool onoff;
};

#endif