]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ClientInfo.h
Remove useless namespace semi-colons
[thirdparty/squid.git] / src / ClientInfo.h
CommitLineData
1c898d4c
AJ
1#ifndef SQUID__SRC_CLIENTINFO_H
2#define SQUID__SRC_CLIENTINFO_H
3
96d89ea0 4#include "ip/Address.h"
1994c73c
AJ
5#include "hash.h"
6#include "enums.h"
7#include "typedefs.h"
b4cd430a
CT
8#include "cbdata.h"
9#include <deque>
10
11#if DELAY_POOLS
12class CommQuotaQueue;
13#endif
1c898d4c 14
04f7fd38
AJ
15class ClientInfo
16{
1c898d4c
AJ
17public:
18 hash_link hash; /* must be first */
19
b7ac5457 20 Ip::Address addr;
1c898d4c
AJ
21
22 struct {
23 int result_hist[LOG_TYPE_MAX];
24 int n_requests;
25 kb_t kbytes_in;
26 kb_t kbytes_out;
27 kb_t hit_kbytes_out;
28 } Http, Icp;
29
30 struct {
31 time_t time;
32 int n_req;
33 int n_denied;
34 } cutoff;
35 int n_established; /* number of current established connections */
36 time_t last_seen;
b4cd430a 37#if DELAY_POOLS
f33d34a8
A
38 double writeSpeedLimit;///< Write speed limit in bytes per second, can be less than 1, if too close to zero this could result in timeouts from client
39 double prevTime; ///< previous time when we checked
b4cd430a
CT
40 double bucketSize; ///< how much can be written now
41 double bucketSizeLimit; ///< maximum bucket size
f33d34a8 42 bool writeLimitingActive; ///< Is write limiter active
b4cd430a
CT
43 bool firstTimeConnection;///< is this first time connection for this client
44
45 CommQuotaQueue *quotaQueue; ///< clients waiting for more write quota
46 int rationedQuota; ///< precomputed quota preserving fairness among clients
47 int rationedCount; ///< number of clients that will receive rationedQuota
48 bool selectWaiting; ///< is between commSetSelect and commHandleWrite
49 bool eventWaiting; ///< waiting for commHandleWriteHelper event to fire
50
51 // all those functions access Comm fd_table and are defined in comm.cc
52 bool hasQueue() const; ///< whether any clients are waiting for write quota
53 bool hasQueue(const CommQuotaQueue*) const; ///< has a given queue
54 unsigned int quotaEnqueue(int fd); ///< client starts waiting in queue; create the queue if necessary
55 int quotaPeekFd() const; ///< retuns the next fd reservation
56 unsigned int quotaPeekReserv() const; ///< returns the next reserv. to pop
57 void quotaDequeue(); ///< pops queue head from queue
58 void kickQuotaQueue(); ///< schedule commHandleWriteHelper call
59 int quotaForDequed(); ///< allocate quota for a just dequeued client
60 void refillBucket(); ///< adds bytes to bucket based on rate and time
61
62 void quotaDumpQueue(); ///< dumps quota queue for debugging
f33d34a8
A
63
64 /**
65 * Configure client write limiting (note:"client" here means - IP). It is called
66 * by httpAccept in client_side.cc, where the initial bucket size (anInitialBurst)
67 * computed, using the configured maximum bucket vavlue and configured initial
68 * bucket value(50% by default).
69 *
70 * \param writeSpeedLimit is speed limit configured in config for this pool
71 * \param initialBurst is initial bucket size to use for this client(i.e. client can burst at first)
72 * \param highWatermark is maximum bucket value
73 */
b4cd430a
CT
74 void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark);
75#endif
76};
77
78#if DELAY_POOLS
79// a queue of Comm clients waiting for I/O quota controlled by delay pools
80class CommQuotaQueue
81{
82public:
83 CommQuotaQueue(ClientInfo *info);
84 ~CommQuotaQueue();
85
86 bool empty() const { return fds.empty(); }
87 size_t size() const { return fds.size(); }
88 int front() const { return fds.front(); }
89 unsigned int enqueue(int fd);
90 void dequeue();
f33d34a8 91
b4cd430a
CT
92 ClientInfo *clientInfo; ///< bucket responsible for quota maintenance
93
94 // these counters might overflow; that is OK because they are for IDs only
95 int ins; ///< number of enqueue calls, used to generate a "reservation" ID
96 int outs; ///< number of dequeue calls, used to check the "reservation" ID
97
98private:
99 // TODO: optimize using a Ring- or List-based store?
100 typedef std::deque<int> Store;
101 Store fds; ///< descriptor queue
102
103 CBDATA_CLASS2(CommQuotaQueue);
1c898d4c 104};
b4cd430a 105#endif /* DELAY_POOLS */
1c898d4c
AJ
106
107#endif