]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ClientInfo.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID__SRC_CLIENTINFO_H
10 #define SQUID__SRC_CLIENTINFO_H
15 #include "ip/Address.h"
27 hash_link hash
; /* must be first */
32 int result_hist
[ LOG_TYPE_MAX
];
44 int n_established
; /* number of current established connections */
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
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
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
71 void quotaDumpQueue (); ///< dumps quota queue for debugging
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).
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
83 void setWriteLimiter ( const int aWriteSpeedLimit
, const double anInitialBurst
, const double aHighWatermark
);
84 #endif /* USE_DELAY_POOLS */
88 // a queue of Comm clients waiting for I/O quota controlled by delay pools
92 CommQuotaQueue ( ClientInfo
* info
);
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
);
101 ClientInfo
* clientInfo
; ///< bucket responsible for quota maintenance
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
108 // TODO: optimize using a Ring- or List-based store?
109 typedef std :: deque
< int > Store
;
110 Store fds
; ///< descriptor queue
112 CBDATA_CLASS2 ( CommQuotaQueue
);
114 #endif /* USE_DELAY_POOLS */