3 * DEBUG: section 77 Delay Pools
4 * AUTHOR: Robert Collins <robertc@squid-cache.org>
5 * Based upon original delay pools code by
6 * David Luyer <david@luyer.net>
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
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.
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.
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.
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.
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
40 /* MS Visual Studio Projects are monolithic, so we need the following
41 * #if to exclude the delay pools code from compile process when not needed.
44 #include "acl/FilledChecklist.h"
45 #include "client_side_request.h"
48 #include "DelayPool.h"
49 #include "DelayPools.h"
50 #include "HttpRequest.h"
51 #include "SquidConfig.h"
53 DelayId::DelayId () : pool_ (0), compositeId(NULL
), markedAsNoDelay(false)
56 DelayId::DelayId (unsigned short aPool
) :
57 pool_ (aPool
), compositeId (NULL
), markedAsNoDelay (false)
59 debugs(77, 3, "DelayId::DelayId: Pool " << aPool
<< "u");
66 DelayId::compositePosition(DelayIdComposite::Pointer newPosition
)
68 compositeId
= newPosition
;
78 DelayId::operator == (DelayId
const &rhs
) const
80 /* Doesn't compare composites properly....
81 * only use to test against default ID's
83 return pool_
== rhs
.pool_
&& compositeId
== rhs
.compositeId
;
86 DelayId::operator bool() const
88 return pool_
|| compositeId
.getRaw();
91 /* create a delay Id for a given request */
93 DelayId::DelayClient(ClientHttpRequest
* http
)
100 if (r
->client_addr
.IsNoAddr()) {
101 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
105 for (pool
= 0; pool
< DelayPools::pools(); ++pool
) {
107 /* pools require explicit 'allow' to assign a client into them */
108 if (!DelayPools::delay_data
[pool
].access
) {
109 debugs(77, DBG_IMPORTANT
, "delay_pool " << pool
<<
110 " has no delay_access configured. This means that no clients will ever use it.");
114 ACLFilledChecklist
ch(DelayPools::delay_data
[pool
].access
, r
, NULL
);
115 #if FOLLOW_X_FORWARDED_FOR
116 if (Config
.onoff
.delay_pool_uses_indirect_client
)
117 ch
.src_addr
= r
->indirect_client_addr
;
119 #endif /* FOLLOW_X_FORWARDED_FOR */
120 ch
.src_addr
= r
->client_addr
;
121 ch
.my_addr
= r
->my_addr
;
123 if (http
->getConn() != NULL
)
124 ch
.conn(http
->getConn());
126 if (DelayPools::delay_data
[pool
].theComposite().getRaw() && ch
.fastCheck() == ACCESS_ALLOWED
) {
128 DelayId
result (pool
+ 1);
129 CompositePoolNode::CompositeSelectionDetails details
;
130 details
.src_addr
= ch
.src_addr
;
132 details
.user
= r
->auth_user_request
;
134 details
.tag
= r
->tag
;
135 result
.compositePosition(DelayPools::delay_data
[pool
].theComposite()->id(details
));
144 DelayId::setNoDelay(bool const newValue
)
146 markedAsNoDelay
= newValue
;
150 * this returns the number of bytes the client is permitted. it does not take
151 * into account bytes already buffered - that is up to the caller.
154 DelayId::bytesWanted(int minimum
, int maximum
) const
158 if (! (*this) || markedAsNoDelay
)
159 return max(minimum
, maximum
);
162 int nbytes
= max(minimum
, maximum
);
164 if (compositeId
!= NULL
)
165 nbytes
= compositeId
->bytesWanted(minimum
, nbytes
);
171 * this records actual bytes received. always recorded, even if the
172 * class is disabled - it's more efficient to just do it than to do all
176 DelayId::bytesIn(int qty
)
184 assert ((unsigned short)(pool() - 1) != 0xFFFF);
186 if (compositeId
!= NULL
)
187 compositeId
->bytesIn(qty
);
191 DelayId::delayRead(DeferredRead
const &aRead
)
193 assert (compositeId
!= NULL
);
194 compositeId
->delayRead(aRead
);
198 #endif /* USE_DELAY_POOLS */