]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ClientInfo.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / ClientInfo.h
CommitLineData
bbc27441
AJ
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
1c898d4c
AJ
9#ifndef SQUID__SRC_CLIENTINFO_H
10#define SQUID__SRC_CLIENTINFO_H
11
602d9612
A
12#include "cbdata.h"
13#include "enums.h"
1994c73c 14#include "hash.h"
602d9612 15#include "ip/Address.h"
02c8dde5 16#include "LogTags.h"
1994c73c 17#include "typedefs.h"
b4cd430a
CT
18#include <deque>
19
9a0a18de 20#if USE_DELAY_POOLS
b4cd430a
CT
21class CommQuotaQueue;
22#endif
1c898d4c 23
04f7fd38
AJ
24class ClientInfo
25{
1c898d4c
AJ
26public:
27 hash_link hash; /* must be first */
28
b7ac5457 29 Ip::Address addr;
1c898d4c
AJ
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;
9a0a18de 46#if USE_DELAY_POOLS
f33d34a8
A
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
b4cd430a
CT
49 double bucketSize; ///< how much can be written now
50 double bucketSizeLimit; ///< maximum bucket size
f33d34a8 51 bool writeLimitingActive; ///< Is write limiter active
b4cd430a
CT
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
f33d34a8
A
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 */
b4cd430a 83 void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark);
9a0a18de 84#endif /* USE_DELAY_POOLS */
b4cd430a
CT
85};
86
9a0a18de 87#if USE_DELAY_POOLS
b4cd430a
CT
88// a queue of Comm clients waiting for I/O quota controlled by delay pools
89class CommQuotaQueue
90{
91public:
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();
f33d34a8 100
b4cd430a
CT
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
107private:
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);
1c898d4c 113};
9a0a18de 114#endif /* USE_DELAY_POOLS */
1c898d4c
AJ
115
116#endif