]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayBucket.cc
Merged from trunk
[thirdparty/squid.git] / src / DelayBucket.cc
1 /*
2 * $Id: DelayBucket.cc,v 1.8 2008/02/26 21:49:34 amosjeffries Exp $
3 *
4 * DEBUG: section 77 Delay Pools
5 * AUTHOR: Robert Collins <robertc@squid-cache.org>
6 * Based upon original delay pools code by
7 * David Luyer <david@luyer.net>
8 *
9 * SQUID Web Proxy Cache http://www.squid-cache.org/
10 * ----------------------------------------------------------
11 *
12 * Squid is the result of efforts by numerous individuals from
13 * the Internet community; see the CONTRIBUTORS file for full
14 * details. Many organizations have provided support for Squid's
15 * development; see the SPONSORS file for full details. Squid is
16 * Copyrighted (C) 2001 by the Regents of the University of
17 * California; see the COPYRIGHT file for full details. Squid
18 * incorporates software developed and/or copyrighted by other
19 * sources; see the CREDITS file for full details.
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 *
35 *
36 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
37 */
38
39 #include "config.h"
40
41 #if DELAY_POOLS
42 #include "squid.h"
43 #include "DelayBucket.h"
44 #include "DelaySpec.h"
45 #include "Store.h"
46
47 #if DEAD_CODE // ?
48 #include "DelayPools.h"
49 #include "StoreClient.h"
50 #include "MemObject.h"
51 #include "client_side_request.h"
52 #include "ACLChecklist.h"
53 #include "ACL.h"
54 #include "ConfigParser.h"
55 #include "DelayId.h"
56 #include "Array.h"
57 #include "String.h"
58 #include "CommonPool.h"
59 #include "CompositePoolNode.h"
60 #include "DelayPool.h"
61 #include "DelayVector.h"
62 #include "NullDelayId.h"
63 #endif
64
65 void
66 DelayBucket::stats(StoreEntry *entry)const
67 {
68 storeAppendPrintf(entry, "%d", level());
69 }
70
71 void
72 DelayBucket::update(DelaySpec const &rate, int incr)
73 {
74 if (rate.restore_bps != -1 &&
75 (level() += rate.restore_bps * incr) > rate.max_bytes)
76 level() = rate.max_bytes;
77 }
78
79 int
80 DelayBucket::bytesWanted(int minimum, int maximum) const
81 {
82 int result = max(minimum, min(maximum, level()));
83 return result;
84 }
85
86 void
87 DelayBucket::bytesIn(int qty)
88 {
89 level() -= qty;
90 }
91
92 void
93 DelayBucket::init(DelaySpec const &rate)
94 {
95 level() = (int) (((double)rate.max_bytes *
96 Config.Delay.initial) / 100);
97 }
98
99 #endif