]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayTagged.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / DelayTagged.cc
1
2 /*
3 * $Id$
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 "squid.h"
39
40 #if USE_DELAY_POOLS
41 #include "squid-old.h"
42 #include "comm/Connection.h"
43 #include "DelayTagged.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 DelayTagged::DelayTagged()
62 {
63 DelayPools::registerForUpdates (this);
64 }
65
66 static SplayNode<DelayTaggedBucket::Pointer>::SPLAYFREE DelayTaggedFree;
67
68 DelayTagged::~DelayTagged()
69 {
70 DelayPools::deregisterForUpdates (this);
71 buckets.head->destroy (DelayTaggedFree);
72 }
73
74 static SplayNode<DelayTaggedBucket::Pointer>::SPLAYCMP DelayTaggedCmp;
75
76 int
77 DelayTaggedCmp(DelayTaggedBucket::Pointer const &left, DelayTaggedBucket::Pointer const &right)
78 {
79 /* for rate limiting, case insensitive */
80 return left->tag.caseCmp(right->tag);
81 }
82
83 void
84 DelayTaggedFree(DelayTaggedBucket::Pointer &)
85 {}
86
87 void
88 DelayTaggedStatsWalkee(DelayTaggedBucket::Pointer const &current, void *state)
89 {
90 current->stats ((StoreEntry *)state);
91 }
92
93 void
94 DelayTagged::stats(StoreEntry * sentry)
95 {
96 spec.stats (sentry, "Per Tag");
97
98 if (spec.restore_bps == -1)
99 return;
100
101 storeAppendPrintf(sentry, "\t\tCurrent: ");
102
103 if (!buckets.head) {
104 storeAppendPrintf (sentry, "Not used yet.\n\n");
105 return;
106 }
107
108 buckets.head->walk(DelayTaggedStatsWalkee, sentry);
109 storeAppendPrintf(sentry, "\n\n");
110 }
111
112 void
113 DelayTagged::dump(StoreEntry *entry) const
114 {
115 spec.dump(entry);
116 }
117
118 struct DelayTaggedUpdater {
119 DelayTaggedUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr) {};
120
121 DelaySpec spec;
122 int incr;
123 };
124
125 void
126 DelayTaggedUpdateWalkee(DelayTaggedBucket::Pointer const &current, void *state)
127 {
128 DelayTaggedUpdater *t = (DelayTaggedUpdater *)state;
129 /* This doesn't change the value of the DelayTaggedBucket, so is safe */
130 const_cast<DelayTaggedBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
131 }
132
133 void
134 DelayTagged::update(int incr)
135 {
136 DelayTaggedUpdater updater(spec, incr);
137 buckets.head->walk (DelayTaggedUpdateWalkee, &updater);
138 kickReads();
139 }
140
141 void
142 DelayTagged::parse()
143 {
144 spec.parse();
145 }
146
147 DelayIdComposite::Pointer
148
149 DelayTagged::id(CompositePoolNode::CompositeSelectionDetails &details)
150 {
151 if (!details.tag.size())
152 return new NullDelayId;
153
154 return new Id(this, details.tag);
155 }
156
157 void *
158 DelayTagged::Id::operator new(size_t size)
159 {
160 DelayPools::MemoryUsed += sizeof (Id);
161 return ::operator new (size);
162 }
163
164 void
165 DelayTagged::Id::operator delete (void *address)
166 {
167 DelayPools::MemoryUsed -= sizeof (Id);
168 ::operator delete (address);
169 }
170
171 void *
172 DelayTaggedBucket::operator new(size_t size)
173 {
174 DelayPools::MemoryUsed += sizeof (DelayTaggedBucket);
175 return ::operator new (size);
176 }
177
178 void
179 DelayTaggedBucket::operator delete (void *address)
180 {
181 DelayPools::MemoryUsed -= sizeof (DelayTaggedBucket);
182 ::operator delete (address);
183 }
184
185 DelayTaggedBucket::DelayTaggedBucket(String &aTag) : tag (aTag)
186 {
187 debugs(77, 3, "DelayTaggedBucket::DelayTaggedBucket");
188 }
189
190 DelayTaggedBucket::~DelayTaggedBucket()
191 {
192 debugs(77, 3, "DelayTaggedBucket::~DelayTaggedBucket");
193 }
194
195 void
196 DelayTaggedBucket::stats (StoreEntry *entry) const
197 {
198 storeAppendPrintf(entry, " :" SQUIDSTRINGPH , SQUIDSTRINGPRINT(tag));
199 theBucket.stats (entry);
200 }
201
202 DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged, String &aTag) : theTagged(aDelayTagged)
203 {
204 theBucket = new DelayTaggedBucket(aTag);
205 DelayTaggedBucket::Pointer const *existing = theTagged->buckets.find(theBucket, DelayTaggedCmp);
206
207 if (existing) {
208 theBucket = *existing;
209 return;
210 }
211
212 theBucket->theBucket.init(theTagged->spec);
213 theTagged->buckets.head = theTagged->buckets.head->insert (theBucket, DelayTaggedCmp);
214 }
215
216 DelayTagged::Id::~Id()
217 {
218 debugs(77, 3, "DelayTagged::Id::~Id");
219 }
220
221 int
222 DelayTagged::Id::bytesWanted (int min, int max) const
223 {
224 return theBucket->theBucket.bytesWanted(min,max);
225 }
226
227 void
228 DelayTagged::Id::bytesIn(int qty)
229 {
230 theBucket->theBucket.bytesIn(qty);
231 }
232
233 void
234 DelayTagged::Id::delayRead(DeferredRead const &aRead)
235 {
236 theTagged->delayRead(aRead);
237 }
238
239 #endif