]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayId.cc
Spelling correction of received
[thirdparty/squid.git] / src / DelayId.cc
1
2 /*
3 * $Id: DelayId.cc,v 1.22 2007/08/27 12:50:42 hno 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 #error DELAY_POOLS not enabled
44 #endif
45 #include "squid.h"
46 #include "DelayId.h"
47 #include "client_side_request.h"
48 #include "ACLChecklist.h"
49 #include "DelayPools.h"
50 #include "DelayPool.h"
51 #include "HttpRequest.h"
52 #include "CommRead.h"
53
54 DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
55 {}
56
57 DelayId::DelayId (unsigned short aPool) :
58 pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
59 {
60 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
61 }
62
63 DelayId::~DelayId ()
64 {}
65
66 void
67 DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
68 {
69 compositeId = newPosition;
70 }
71
72 unsigned short
73 DelayId::pool() const
74 {
75 return pool_;
76 }
77
78 bool
79 DelayId::operator == (DelayId const &rhs) const
80 {
81 /* Doesn't compare composites properly....
82 * only use to test against default ID's
83 */
84 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
85 }
86
87 DelayId::operator bool() const
88 {
89 return pool_ || compositeId.getRaw();
90 }
91
92 /* create a delay Id for a given request */
93 DelayId
94 DelayId::DelayClient(ClientHttpRequest * http)
95 {
96 HttpRequest *r;
97 unsigned short pool;
98 assert(http);
99 r = http->request;
100
101 if (r->client_addr.s_addr == INADDR_BROADCAST) {
102 debugs(77, 2, "delayClient: WARNING: Called with 'allones' address, ignoring");
103 return DelayId();
104 }
105
106 for (pool = 0; pool < DelayPools::pools(); pool++) {
107 ACLChecklist ch;
108 ch.src_addr = r->client_addr;
109 ch.my_addr = r->my_addr;
110 ch.my_port = r->my_port;
111
112 if (http->getConn() != NULL)
113 ch.conn(http->getConn());
114
115 ch.request = HTTPMSGLOCK(r);
116
117 ch.accessList = cbdataReference(DelayPools::delay_data[pool].access);
118
119 /* cbdataReferenceDone() happens in either fastCheck() or ~ACLCheckList */
120
121 if (DelayPools::delay_data[pool].theComposite().getRaw() &&
122 ch.fastCheck()) {
123 DelayId result (pool + 1);
124 CompositePoolNode::CompositeSelectionDetails details;
125 details.src_addr = ch.src_addr;
126 details.user = r->auth_user_request;
127 details.tag = r->tag;
128 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
129 return result;
130 }
131 }
132
133
134 return DelayId();
135 }
136
137 void
138 DelayId::setNoDelay(bool const newValue)
139 {
140 markedAsNoDelay = newValue;
141 }
142
143 /*
144 * this returns the number of bytes the client is permitted. it does not take
145 * into account bytes already buffered - that is up to the caller.
146 */
147 int
148 DelayId::bytesWanted(int minimum, int maximum) const
149 {
150 /* unlimited */
151
152 if (! (*this) || markedAsNoDelay)
153 return max(minimum, maximum);
154
155 /* limited */
156 int nbytes = max(minimum, maximum);
157
158 if (compositeId != NULL)
159 nbytes = compositeId->bytesWanted(minimum, nbytes);
160
161 return nbytes;
162 }
163
164 /*
165 * this records actual bytes received. always recorded, even if the
166 * class is disabled - it's more efficient to just do it than to do all
167 * the checks.
168 */
169 void
170 DelayId::bytesIn(int qty)
171 {
172 if (! (*this))
173 return;
174
175 if (markedAsNoDelay)
176 return;
177
178 assert ((unsigned short)(pool() - 1) != 0xFFFF);
179
180 if (compositeId != NULL)
181 compositeId->bytesIn(qty);
182 }
183
184 void
185 DelayId::delayRead(DeferredRead const &aRead)
186 {
187 assert (compositeId != NULL);
188 compositeId->delayRead(aRead);
189
190 }