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