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