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