]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayVector.cc
Summary: Merge in external acl refactoring and tagged delay pools.
[thirdparty/squid.git] / src / DelayVector.cc
1
2 /*
3 * $Id: DelayVector.cc,v 1.8 2003/05/20 12:17:38 robertc Exp $
4 *
5 * DEBUG: section 77 Delay Pools
6 * AUTHOR: Robert Collins <robertc@squid-cache.org>
7 * Based upon original delay pools code by
8 * David Luyer <david@luyer.net>
9 *
10 * SQUID Web Proxy Cache http://www.squid-cache.org/
11 * ----------------------------------------------------------
12 *
13 * Squid is the result of efforts by numerous individuals from
14 * the Internet community; see the CONTRIBUTORS file for full
15 * details. Many organizations have provided support for Squid's
16 * development; see the SPONSORS file for full details. Squid is
17 * Copyrighted (C) 2001 by the Regents of the University of
18 * California; see the COPYRIGHT file for full details. Squid
19 * incorporates software developed and/or copyrighted by other
20 * sources; see the CREDITS file for full details.
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
35 *
36 *
37 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
38 */
39
40 #include "config.h"
41
42 #if DELAY_POOLS
43 #include "squid.h"
44 #include "DelayVector.h"
45 #include "CommRead.h"
46
47 void *
48 DelayVector::operator new(size_t size)
49 {
50 DelayPools::MemoryUsed += sizeof (DelayVector);
51 return ::operator new (size);
52 }
53
54 void
55 DelayVector::operator delete (void *address)
56 {
57 DelayPools::MemoryUsed -= sizeof (DelayVector);
58 ::operator delete (address);
59 }
60
61 void
62 DelayVector::deleteSelf() const
63 {
64 delete this;
65 }
66
67 DelayVector::DelayVector()
68 {
69 DelayPools::registerForUpdates (this);
70 }
71
72 DelayVector::~DelayVector()
73 {
74 DelayPools::deregisterForUpdates (this);
75 }
76
77 void
78 DelayVector::stats(StoreEntry * sentry)
79 {
80 iterator pos = pools.begin();
81
82 while (pos != pools.end()) {
83 (*pos)->stats(sentry);
84 ++pos;
85 }
86 }
87
88 void
89 DelayVector::dump(StoreEntry *entry) const
90 {
91 const_iterator pos = pools.begin();
92
93 while (pos != pools.end()) {
94 (*pos)->dump(entry);
95 ++pos;
96 }
97 }
98
99 void
100 DelayVector::update(int incr)
101 {
102 /*
103 * Each pool updates itself,
104 * but we may have deferred reads waiting on the pool as a whole.
105 */
106
107 kickReads();
108 }
109
110 void
111 DelayVector::parse()
112 {
113 iterator pos = pools.begin();
114
115 while (pos != pools.end()) {
116 (*pos)->parse();
117 ++pos;
118 }
119 }
120
121 DelayIdComposite::Pointer
122 DelayVector::id(CompositeSelectionDetails &details)
123 {
124 return new Id(this, details);
125 }
126
127 void
128 DelayVector::push_back(CompositePoolNode::Pointer aNode)
129 {
130 pools.push_back(aNode);
131 }
132
133 void *
134 DelayVector::Id::operator new(size_t size)
135 {
136 DelayPools::MemoryUsed += sizeof (Id);
137 return ::operator new (size);
138 }
139
140 void
141 DelayVector::Id::operator delete (void *address)
142 {
143 DelayPools::MemoryUsed -= sizeof (Id);
144 ::operator delete (address);
145 }
146
147 void
148 DelayVector::Id::deleteSelf() const
149 {
150 delete this;
151 }
152
153 DelayVector::Id::Id(DelayVector::Pointer aDelayVector, CompositeSelectionDetails &details) : theVector(aDelayVector)
154 {
155 debug(77,3)("DelayVector::Id::Id\n");
156 DelayVector::iterator pos = theVector->pools.begin();
157
158 while (pos != theVector->pools.end()) {
159 ids.push_back ((*pos)->id (details));
160 ++pos;
161 }
162 }
163
164 DelayVector::Id::~Id()
165 {
166 debug(77,3)("DelayVector::Id::~Id\n");
167 }
168
169 int
170 DelayVector::Id::bytesWanted (int minimum, int maximum) const
171 {
172 int nbytes = maximum;
173 const_iterator pos = ids.begin();
174
175 while (pos != ids.end()) {
176 nbytes = min (nbytes, (*pos)->bytesWanted(minimum, nbytes));
177 ++pos;
178 }
179
180 nbytes = max(minimum, nbytes);
181 return nbytes;
182 }
183
184 void
185 DelayVector::Id::bytesIn(int qty)
186 {
187 iterator pos = ids.begin();
188
189 while (pos != ids.end()) {
190 (*pos)->bytesIn(qty);
191 ++pos;
192 }
193
194 theVector->kickReads();
195 }
196
197 void
198 DelayVector::Id::delayRead(DeferredRead const &aRead)
199 {
200 theVector->delayRead(aRead);
201 }
202
203 #endif