ClientInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 #if USE_DELAY_POOLS
13 #include "BandwidthBucket.h"
14 #endif
15 #include "base/ByteCounter.h"
16 #include "cbdata.h"
17 #include "enums.h"
18 #include "hash.h"
19 #include "ip/Address.h"
20 #include "LogTags.h"
21 #include "mem/forward.h"
22 #include "typedefs.h"
23 
24 #include <deque>
25 
26 #if USE_DELAY_POOLS
27 class CommQuotaQueue;
28 #endif
29 
30 class ClientInfo : public hash_link
31 #if USE_DELAY_POOLS
32  , public BandwidthBucket
33 #endif
34 {
36 
37 public:
38  explicit ClientInfo(const Ip::Address &);
39 #if USE_DELAY_POOLS
40  ~ClientInfo() override;
41 #else
42  ~ClientInfo();
43 #endif
44 
46 
47  struct Protocol {
49  memset(result_hist, 0, sizeof(result_hist));
50  }
51 
57  } Http, Icp;
58 
59  struct Cutoff {
60  Cutoff() : time(0), n_req(0), n_denied(0) {}
61 
62  time_t time;
63  int n_req;
64  int n_denied;
65  } cutoff;
66  int n_established; /* number of current established connections */
67  time_t last_seen;
68 #if USE_DELAY_POOLS
71 
75  bool eventWaiting;
76 
77  // all those functions access Comm fd_table and are defined in comm.cc
78  bool hasQueue() const;
79  bool hasQueue(const CommQuotaQueue*) const;
80  unsigned int quotaEnqueue(int fd);
81  int quotaPeekFd() const;
82  unsigned int quotaPeekReserv() const;
83  void quotaDequeue();
84  void kickQuotaQueue();
85  void writeOrDequeue();
87 
88  /* BandwidthBucket API */
89  int quota() override;
90  bool applyQuota(int &nleft, Comm::IoCallback *state) override;
91  void scheduleWrite(Comm::IoCallback *state) override;
92  void onFdClosed() override;
93  void reduceBucket(int len) override;
94 
95  void quotaDumpQueue();
96 
107  void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark);
108 #endif /* USE_DELAY_POOLS */
109 };
110 
111 #if USE_DELAY_POOLS
112 // a queue of Comm clients waiting for I/O quota controlled by delay pools
114 {
116 
117 public:
118  CommQuotaQueue(ClientInfo *info);
119  ~CommQuotaQueue();
120 
121  bool empty() const { return fds.empty(); }
122  size_t size() const { return fds.size(); }
123  int front() const { return fds.front(); }
124  unsigned int enqueue(int fd);
125  void dequeue();
126 
128 
129  // these counters might overflow; that is OK because they are for IDs only
130  int ins;
131  int outs;
132 
133 private:
134  // TODO: optimize using a Ring- or List-based store?
135  typedef std::deque<int> Store;
137 };
138 #endif /* USE_DELAY_POOLS */
139 
140 #endif /* SQUID_SRC_CLIENTINFO_H */
141 
bool applyQuota(int &nleft, Comm::IoCallback *state) override
Definition: comm.cc:1318
CommQuotaQueue(ClientInfo *info)
Definition: comm.cc:1382
void quotaDequeue()
pops queue head from queue
Definition: comm.cc:1267
ByteCounter hit_kbytes_out
Definition: ClientInfo.h:56
unsigned int enqueue(int fd)
places the given fd at the end of the queue; returns reservation ID
Definition: comm.cc:1395
struct ClientInfo::Protocol Icp
int front() const
Definition: ClientInfo.h:123
void reduceBucket(int len) override
Decreases the bucket level.
Definition: comm.cc:1349
int outs
number of dequeue calls, used to check the "reservation" ID
Definition: ClientInfo.h:131
void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark)
Definition: comm.cc:1358
#define CBDATA_CLASS(type)
Definition: cbdata.h:289
Ip::Address addr
Definition: ClientInfo.h:45
ClientInfo(const Ip::Address &)
Definition: client_db.cc:54
@ LOG_TYPE_MAX
Definition: LogTags.h:66
void onFdClosed() override
Performs cleanup when the related file descriptor becomes closed.
Definition: comm.cc:1341
~ClientInfo() override
Definition: client_db.cc:335
bool eventWaiting
waiting for commHandleWriteHelper event to fire
Definition: ClientInfo.h:75
CommQuotaQueue * quotaQueue
clients waiting for more write quota
Definition: ClientInfo.h:72
struct ClientInfo::Protocol Http
MEMPROXY_CLASS(ClientInfo)
Details about a particular Comm IO callback event.
Definition: IoCallback.h:29
int quota() override
allocate quota for a just dequeued client
Definition: comm.cc:1287
Store fds
descriptor queue
Definition: ClientInfo.h:136
int quotaPeekFd() const
returns the next fd reservation
Definition: comm.cc:1243
bool writeLimitingActive
Is write limiter active.
Definition: ClientInfo.h:69
void scheduleWrite(Comm::IoCallback *state) override
Will plan another write call.
Definition: comm.cc:1332
time_t last_seen
Definition: ClientInfo.h:67
int rationedQuota
precomputed quota preserving fairness among clients
Definition: ClientInfo.h:73
Base class for Squid-to-client bandwidth limiting.
size_t size() const
Definition: ClientInfo.h:122
unsigned int quotaEnqueue(int fd)
client starts waiting in queue; create the queue if necessary
Definition: comm.cc:1259
int ins
number of enqueue calls, used to generate a "reservation" ID
Definition: ClientInfo.h:130
ByteCounter kbytes_in
Definition: ClientInfo.h:54
void dequeue()
removes queue head
Definition: comm.cc:1406
int n_established
Definition: ClientInfo.h:66
bool empty() const
Definition: ClientInfo.h:121
void writeOrDequeue()
either selects the head descriptor for writing or calls quotaDequeue()
Definition: comm.cc:1206
ClientInfo * clientInfo
bucket responsible for quota maintenance
Definition: ClientInfo.h:127
counter for accumulating byte values
Definition: ByteCounter.h:13
bool hasQueue() const
whether any clients are waiting for write quota
Definition: comm.cc:1228
~CommQuotaQueue()
Definition: comm.cc:1388
ByteCounter kbytes_out
Definition: ClientInfo.h:55
void kickQuotaQueue()
Definition: comm.cc:1274
std::deque< int > Store
Definition: ClientInfo.h:135
unsigned int quotaPeekReserv() const
returns the next reserv. to pop
Definition: comm.cc:1251
int result_hist[LOG_TYPE_MAX]
Definition: ClientInfo.h:52
void quotaDumpQueue()
dumps quota queue for debugging
int rationedCount
number of clients that will receive rationedQuota
Definition: ClientInfo.h:74
struct ClientInfo::Cutoff cutoff
bool firstTimeConnection
is this first time connection for this client
Definition: ClientInfo.h:70

 

Introduction

Documentation

Support

Miscellaneous