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