ClientInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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  ~ClientInfo();
40 
42 
43  struct Protocol {
45  memset(result_hist, 0, sizeof(result_hist));
46  }
47 
53  } Http, Icp;
54 
55  struct Cutoff {
56  Cutoff() : time(0), n_req(0), n_denied(0) {}
57 
58  time_t time;
59  int n_req;
60  int n_denied;
61  } cutoff;
62  int n_established; /* number of current established connections */
63  time_t last_seen;
64 #if USE_DELAY_POOLS
67 
71  bool eventWaiting;
72 
73  // all those functions access Comm fd_table and are defined in comm.cc
74  bool hasQueue() const;
75  bool hasQueue(const CommQuotaQueue*) const;
76  unsigned int quotaEnqueue(int fd);
77  int quotaPeekFd() const;
78  unsigned int quotaPeekReserv() const;
79  void quotaDequeue();
80  void kickQuotaQueue();
81  void writeOrDequeue();
83 
84  /* BandwidthBucket API */
85  virtual int quota() override;
86  virtual bool applyQuota(int &nleft, Comm::IoCallback *state) override;
87  virtual void scheduleWrite(Comm::IoCallback *state) override;
88  virtual void onFdClosed() override;
89  virtual void reduceBucket(int len) override;
90 
91  void quotaDumpQueue();
92 
103  void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark);
104 #endif /* USE_DELAY_POOLS */
105 };
106 
107 #if USE_DELAY_POOLS
108 // a queue of Comm clients waiting for I/O quota controlled by delay pools
110 {
112 
113 public:
114  CommQuotaQueue(ClientInfo *info);
115  ~CommQuotaQueue();
116 
117  bool empty() const { return fds.empty(); }
118  size_t size() const { return fds.size(); }
119  int front() const { return fds.front(); }
120  unsigned int enqueue(int fd);
121  void dequeue();
122 
124 
125  // these counters might overflow; that is OK because they are for IDs only
126  int ins;
127  int outs;
128 
129 private:
130  // TODO: optimize using a Ring- or List-based store?
131  typedef std::deque<int> Store;
133 };
134 #endif /* USE_DELAY_POOLS */
135 
136 #endif
137 
virtual bool applyQuota(int &nleft, Comm::IoCallback *state) override
Definition: comm.cc:1403
CommQuotaQueue(ClientInfo *info)
Definition: comm.cc:1467
void quotaDequeue()
pops queue head from queue
Definition: comm.cc:1352
ByteCounter hit_kbytes_out
Definition: ClientInfo.h:52
unsigned int enqueue(int fd)
places the given fd at the end of the queue; returns reservation ID
Definition: comm.cc:1480
struct ClientInfo::Protocol Icp
int front() const
Definition: ClientInfo.h:119
virtual void reduceBucket(int len) override
Decreases the bucket level.
Definition: comm.cc:1434
int outs
number of dequeue calls, used to check the "reservation" ID
Definition: ClientInfo.h:127
void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark)
Definition: comm.cc:1443
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
Ip::Address addr
Definition: ClientInfo.h:41
ClientInfo(const Ip::Address &)
Definition: client_db.cc:55
@ LOG_TYPE_MAX
Definition: LogTags.h:48
virtual void onFdClosed() override
Performs cleanup when the related file descriptor becomes closed.
Definition: comm.cc:1426
bool eventWaiting
waiting for commHandleWriteHelper event to fire
Definition: ClientInfo.h:71
CommQuotaQueue * quotaQueue
clients waiting for more write quota
Definition: ClientInfo.h:68
struct ClientInfo::Protocol Http
MEMPROXY_CLASS(ClientInfo)
Details about a particular Comm IO callback event.
Definition: IoCallback.h:29
virtual int quota() override
allocate quota for a just dequeued client
Definition: comm.cc:1372
Store fds
descriptor queue
Definition: ClientInfo.h:132
int quotaPeekFd() const
returns the next fd reservation
Definition: comm.cc:1328
bool writeLimitingActive
Is write limiter active.
Definition: ClientInfo.h:65
virtual void scheduleWrite(Comm::IoCallback *state) override
Will plan another write call.
Definition: comm.cc:1417
time_t last_seen
Definition: ClientInfo.h:63
int rationedQuota
precomputed quota preserving fairness among clients
Definition: ClientInfo.h:69
Base class for Squid-to-client bandwidth limiting.
size_t size() const
Definition: ClientInfo.h:118
unsigned int quotaEnqueue(int fd)
client starts waiting in queue; create the queue if necessary
Definition: comm.cc:1344
int ins
number of enqueue calls, used to generate a "reservation" ID
Definition: ClientInfo.h:126
ByteCounter kbytes_in
Definition: ClientInfo.h:50
void dequeue()
removes queue head
Definition: comm.cc:1491
int n_established
Definition: ClientInfo.h:62
bool empty() const
Definition: ClientInfo.h:117
void writeOrDequeue()
either selects the head descriptor for writing or calls quotaDequeue()
Definition: comm.cc:1291
ClientInfo * clientInfo
bucket responsible for quota maintenance
Definition: ClientInfo.h:123
counter for accumulating byte values
Definition: ByteCounter.h:13
bool hasQueue() const
whether any clients are waiting for write quota
Definition: comm.cc:1313
~CommQuotaQueue()
Definition: comm.cc:1473
ByteCounter kbytes_out
Definition: ClientInfo.h:51
void kickQuotaQueue()
Definition: comm.cc:1359
std::deque< int > Store
Definition: ClientInfo.h:131
unsigned int quotaPeekReserv() const
returns the next reserv. to pop
Definition: comm.cc:1336
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
int result_hist[LOG_TYPE_MAX]
Definition: ClientInfo.h:48
void quotaDumpQueue()
dumps quota queue for debugging
int rationedCount
number of clients that will receive rationedQuota
Definition: ClientInfo.h:70
struct ClientInfo::Cutoff cutoff
bool firstTimeConnection
is this first time connection for this client
Definition: ClientInfo.h:66

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors