]>
Commit | Line | Data |
---|---|---|
b27668ec | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 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 | #include "squid.h" | |
10 | ||
11 | #if USE_DELAY_POOLS | |
12 | #include "comm/Connection.h" | |
13 | #include "DelayPools.h" | |
14 | #include "fde.h" | |
15 | #include "MessageBucket.h" | |
16 | ||
17 | MessageBucket::MessageBucket(const int speed, const int initialLevelPercent, | |
18 | const double sizeLimit, MessageDelayPool::Pointer pool) : | |
19 | BandwidthBucket(speed, initialLevelPercent, sizeLimit), | |
20 | theAggregate(pool) {} | |
21 | ||
22 | int | |
23 | MessageBucket::quota() | |
24 | { | |
25 | refillBucket(); | |
26 | theAggregate->refillBucket(); | |
27 | if (theAggregate->noLimit()) | |
28 | return bucketLevel; | |
29 | else if (noLimit()) | |
30 | return theAggregate->level(); | |
31 | else | |
32 | return min(bucketLevel, static_cast<double>(theAggregate->level())); | |
33 | } | |
34 | ||
35 | void | |
36 | MessageBucket::reduceBucket(int len) | |
37 | { | |
38 | BandwidthBucket::reduceBucket(len); | |
39 | theAggregate->bytesIn(len); | |
40 | } | |
41 | ||
42 | void | |
43 | MessageBucket::scheduleWrite(Comm::IoCallback *state) | |
44 | { | |
45 | fde *F = &fd_table[state->conn->fd]; | |
46 | if (!F->writeQuotaHandler->selectWaiting) { | |
47 | F->writeQuotaHandler->selectWaiting = true; | |
48 | // message delay pools limit this write; see checkTimeouts() | |
49 | SetSelect(state->conn->fd, COMM_SELECT_WRITE, Comm::HandleWrite, state, 0); | |
50 | } | |
51 | } | |
52 | ||
53 | #endif /* USE_DELAY_POOLS */ | |
54 |