]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayTagged.cc
Summary: Oops, another tagged bugfix.
[thirdparty/squid.git] / src / DelayTagged.cc
1
2 /*
3 * $Id: DelayTagged.cc,v 1.3 2003/05/22 11:14:43 robertc Exp $
4 *
5 * DEBUG: section 77 Delay Pools
6 * AUTHOR: Robert Collins <robertc@squid-cache.org>
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 *
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 */
37
38 #include "config.h"
39
40 #if DELAY_POOLS
41 #include "squid.h"
42 #include "DelayTagged.h"
43 #include "authenticate.h"
44 #include "NullDelayId.h"
45 #include "Store.h"
46
47 void *
48 DelayTagged::operator new(size_t size)
49 {
50 DelayPools::MemoryUsed += sizeof (DelayTagged);
51 return ::operator new (size);
52 }
53
54 void
55 DelayTagged::operator delete (void *address)
56 {
57 DelayPools::MemoryUsed -= sizeof (DelayTagged);
58 ::operator delete (address);
59 }
60
61 void
62 DelayTagged::deleteSelf() const
63 {
64 delete this;
65 }
66
67 DelayTagged::DelayTagged()
68 {
69 DelayPools::registerForUpdates (this);
70 }
71
72 static SplayNode<DelayTaggedBucket::Pointer>::SPLAYFREE DelayTaggedFree;
73
74 DelayTagged::~DelayTagged()
75 {
76 DelayPools::deregisterForUpdates (this);
77 buckets.head->destroy (DelayTaggedFree);
78 }
79
80 static SplayNode<DelayTaggedBucket::Pointer>::SPLAYCMP DelayTaggedCmp;
81
82 int
83 DelayTaggedCmp(DelayTaggedBucket::Pointer const &left, DelayTaggedBucket::Pointer const &right)
84 {
85 /* for rate limiting, case insensitive */
86 return left->tag.caseCmp(right->tag.buf());
87 }
88
89 void
90 DelayTaggedFree(DelayTaggedBucket::Pointer &)
91 {}
92
93 void
94 DelayTaggedStatsWalkee(DelayTaggedBucket::Pointer const &current, void *state)
95 {
96 current->stats ((StoreEntry *)state);
97 }
98
99 void
100 DelayTagged::stats(StoreEntry * sentry)
101 {
102 spec.stats (sentry, "Per Tag");
103
104 if (spec.restore_bps == -1)
105 return;
106
107 storeAppendPrintf(sentry, "\t\tCurrent: ");
108
109 if (!buckets.head) {
110 storeAppendPrintf (sentry, "Not used yet.\n\n");
111 return;
112 }
113
114 buckets.head->walk(DelayTaggedStatsWalkee, sentry);
115 storeAppendPrintf(sentry, "\n\n");
116 }
117
118 void
119 DelayTagged::dump(StoreEntry *entry) const
120 {
121 spec.dump(entry);
122 }
123
124 struct DelayTaggedUpdater
125 {
126 DelayTaggedUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr){};
127
128 DelaySpec spec;
129 int incr;
130 };
131
132 void
133 DelayTaggedUpdateWalkee(DelayTaggedBucket::Pointer const &current, void *state)
134 {
135 DelayTaggedUpdater *t = (DelayTaggedUpdater *)state;
136 /* This doesn't change the value of the DelayTaggedBucket, so is safe */
137 const_cast<DelayTaggedBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
138 }
139
140 void
141 DelayTagged::update(int incr)
142 {
143 DelayTaggedUpdater updater(spec, incr);
144 buckets.head->walk (DelayTaggedUpdateWalkee, &updater);
145 kickReads();
146 }
147
148 void
149 DelayTagged::parse()
150 {
151 spec.parse();
152 }
153
154 DelayIdComposite::Pointer
155
156 DelayTagged::id(CompositePoolNode::CompositeSelectionDetails &details)
157 {
158 if (!details.tag.size())
159 return new NullDelayId;
160
161 return new Id(this, details.tag);
162 }
163
164 void *
165 DelayTagged::Id::operator new(size_t size)
166 {
167 DelayPools::MemoryUsed += sizeof (Id);
168 return ::operator new (size);
169 }
170
171 void
172 DelayTagged::Id::operator delete (void *address)
173 {
174 DelayPools::MemoryUsed -= sizeof (Id);
175 ::operator delete (address);
176 }
177
178 void
179 DelayTagged::Id::deleteSelf() const
180 {
181 delete this;
182 }
183
184 void *
185 DelayTaggedBucket::operator new(size_t size)
186 {
187 DelayPools::MemoryUsed += sizeof (DelayTaggedBucket);
188 return ::operator new (size);
189 }
190
191 void
192 DelayTaggedBucket::operator delete (void *address)
193 {
194 DelayPools::MemoryUsed -= sizeof (DelayTaggedBucket);
195 ::operator delete (address);
196 }
197
198 DelayTaggedBucket::DelayTaggedBucket(String &aTag) : tag (aTag)
199 {
200 debug (77,3) ("DelayTaggedBucket::DelayTaggedBucket\n");
201 }
202
203 DelayTaggedBucket::~DelayTaggedBucket()
204 {
205 debug (77,3) ("DelayTaggedBucket::~DelayTaggedBucket\n");
206 }
207
208 void
209 DelayTaggedBucket::stats (StoreEntry *entry) const
210 {
211 storeAppendPrintf(entry, " %s:", tag.buf());
212 theBucket.stats (entry);
213 }
214
215 DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged, String &aTag) : theTagged(aDelayTagged)
216 {
217 theBucket = new DelayTaggedBucket(aTag);
218 DelayTaggedBucket::Pointer const *existing = theTagged->buckets.find(theBucket, DelayTaggedCmp);
219
220 if (existing) {
221 theBucket = *existing;
222 return;
223 }
224
225 theBucket->theBucket.init(theTagged->spec);
226 theTagged->buckets.head = theTagged->buckets.head->insert (theBucket, DelayTaggedCmp);
227 }
228
229 DelayTagged::Id::~Id()
230 {
231 debug (77,3) ("DelayTagged::Id::~Id\n");
232 }
233
234 int
235 DelayTagged::Id::bytesWanted (int min, int max) const
236 {
237 return theBucket->theBucket.bytesWanted(min,max);
238 }
239
240 void
241 DelayTagged::Id::bytesIn(int qty)
242 {
243 theBucket->theBucket.bytesIn(qty);
244 }
245
246 void
247 DelayTagged::Id::delayRead(DeferredRead const &aRead)
248 {
249 theTagged->delayRead(aRead);
250 }
251
252 #endif