]>
Commit | Line | Data |
---|---|---|
b27668ec | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
b27668ec EB |
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 BANDWIDTHBUCKET_H | |
10 | #define BANDWIDTHBUCKET_H | |
11 | ||
12 | #if USE_DELAY_POOLS | |
13 | ||
14 | #include "comm/IoCallback.h" | |
15 | ||
16 | class fde; | |
17 | ||
18 | /// Base class for Squid-to-client bandwidth limiting | |
19 | class BandwidthBucket | |
20 | { | |
21 | public: | |
22 | BandwidthBucket(const int speed, const int initialLevelPercent, const double sizeLimit); | |
23 | virtual ~BandwidthBucket() {} | |
24 | ||
25 | static BandwidthBucket *SelectBucket(fde *f); | |
26 | ||
27 | /// \returns the number of bytes this bucket allows to write, | |
28 | /// also considering aggregates, if any. Negative quota means | |
29 | /// no limitations by this bucket. | |
30 | virtual int quota() = 0; | |
31 | /// Adjusts nleft to not exceed the current bucket quota value, | |
32 | /// if needed. | |
33 | virtual bool applyQuota(int &nleft, Comm::IoCallback *state); | |
34 | /// Will plan another write call. | |
35 | virtual void scheduleWrite(Comm::IoCallback *state) = 0; | |
36 | /// Performs cleanup when the related file descriptor becomes closed. | |
37 | virtual void onFdClosed() { selectWaiting = false; } | |
38 | /// Decreases the bucket level. | |
39 | virtual void reduceBucket(const int len); | |
40 | /// Whether this bucket will not do bandwidth limiting. | |
41 | bool noLimit() const { return writeSpeedLimit < 0; } | |
42 | ||
43 | protected: | |
44 | /// Increases the bucket level with the writeSpeedLimit speed. | |
45 | void refillBucket(); | |
46 | ||
47 | public: | |
48 | double bucketLevel; ///< how much can be written now | |
49 | bool selectWaiting; ///< is between commSetSelect and commHandleWrite | |
50 | ||
51 | protected: | |
52 | double prevTime; ///< previous time when we checked | |
53 | double writeSpeedLimit; ///< Write speed limit in bytes per second. | |
54 | double bucketSizeLimit; ///< maximum bucket size | |
55 | }; | |
56 | ||
57 | #endif /* USE_DELAY_POOLS */ | |
58 | ||
59 | #endif | |
60 |