]> git.ipfire.org Git - thirdparty/squid.git/blame - src/BandwidthBucket.h
Maintenance: rework SASL detection (#1694)
[thirdparty/squid.git] / src / BandwidthBucket.h
CommitLineData
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
ff9d9458
FC
9#ifndef SQUID_SRC_BANDWIDTHBUCKET_H
10#define SQUID_SRC_BANDWIDTHBUCKET_H
b27668ec
EB
11
12#if USE_DELAY_POOLS
13
14#include "comm/IoCallback.h"
15
16class fde;
17
18/// Base class for Squid-to-client bandwidth limiting
19class BandwidthBucket
20{
21public:
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
43protected:
44 /// Increases the bucket level with the writeSpeedLimit speed.
45 void refillBucket();
46
47public:
48 double bucketLevel; ///< how much can be written now
49 bool selectWaiting; ///< is between commSetSelect and commHandleWrite
50
51protected:
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
ff9d9458 59#endif /* SQUID_SRC_BANDWIDTHBUCKET_H */
b27668ec 60