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