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
|