]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayVector.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / DelayVector.cc
1
2 /*
3 * $Id$
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 "squid.h"
41
42 #if USE_DELAY_POOLS
43 #include "squid-old.h"
44 #include "comm/Connection.h"
45 #include "DelayVector.h"
46 #include "CommRead.h"
47
48 void *
49 DelayVector::operator new(size_t size)
50 {
51 DelayPools::MemoryUsed += sizeof (DelayVector);
52 return ::operator new (size);
53 }
54
55 void
56 DelayVector::operator delete (void *address)
57 {
58 DelayPools::MemoryUsed -= sizeof (DelayVector);
59 ::operator delete (address);
60 }
61
62 DelayVector::DelayVector()
63 {
64 DelayPools::registerForUpdates (this);
65 }
66
67 DelayVector::~DelayVector()
68 {
69 DelayPools::deregisterForUpdates (this);
70 }
71
72 void
73 DelayVector::stats(StoreEntry * sentry)
74 {
75 iterator pos = pools.begin();
76
77 while (pos != pools.end()) {
78 (*pos)->stats(sentry);
79 ++pos;
80 }
81 }
82
83 void
84 DelayVector::dump(StoreEntry *entry) const
85 {
86 const_iterator pos = pools.begin();
87
88 while (pos != pools.end()) {
89 (*pos)->dump(entry);
90 ++pos;
91 }
92 }
93
94 void
95 DelayVector::update(int incr)
96 {
97 /*
98 * Each pool updates itself,
99 * but we may have deferred reads waiting on the pool as a whole.
100 */
101
102 kickReads();
103 }
104
105 void
106 DelayVector::parse()
107 {
108 iterator pos = pools.begin();
109
110 while (pos != pools.end()) {
111 (*pos)->parse();
112 ++pos;
113 }
114 }
115
116 DelayIdComposite::Pointer
117 DelayVector::id(CompositeSelectionDetails &details)
118 {
119 return new Id(this, details);
120 }
121
122 void
123 DelayVector::push_back(CompositePoolNode::Pointer aNode)
124 {
125 pools.push_back(aNode);
126 }
127
128 void *
129 DelayVector::Id::operator new(size_t size)
130 {
131 DelayPools::MemoryUsed += sizeof (Id);
132 return ::operator new (size);
133 }
134
135 void
136 DelayVector::Id::operator delete (void *address)
137 {
138 DelayPools::MemoryUsed -= sizeof (Id);
139 ::operator delete (address);
140 }
141
142 DelayVector::Id::Id(DelayVector::Pointer aDelayVector, CompositeSelectionDetails &details) : theVector(aDelayVector)
143 {
144 debugs(77, 3, "DelayVector::Id::Id");
145 DelayVector::iterator pos = theVector->pools.begin();
146
147 while (pos != theVector->pools.end()) {
148 ids.push_back ((*pos)->id (details));
149 ++pos;
150 }
151 }
152
153 DelayVector::Id::~Id()
154 {
155 debugs(77, 3, "DelayVector::Id::~Id");
156 }
157
158 int
159 DelayVector::Id::bytesWanted (int minimum, int maximum) const
160 {
161 int nbytes = maximum;
162 const_iterator pos = ids.begin();
163
164 while (pos != ids.end()) {
165 nbytes = min (nbytes, (*pos)->bytesWanted(minimum, nbytes));
166 ++pos;
167 }
168
169 nbytes = max(minimum, nbytes);
170 return nbytes;
171 }
172
173 void
174 DelayVector::Id::bytesIn(int qty)
175 {
176 iterator pos = ids.begin();
177
178 while (pos != ids.end()) {
179 (*pos)->bytesIn(qty);
180 ++pos;
181 }
182
183 theVector->kickReads();
184 }
185
186 void
187 DelayVector::Id::delayRead(DeferredRead const &aRead)
188 {
189 theVector->delayRead(aRead);
190 }
191
192 #endif