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>
10 * SQUID Web Proxy Cache http://www.squid-cache.org/
11 * ----------------------------------------------------------
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.
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.
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.
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.
37 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
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.
49 #include "client_side_request.h"
50 #include "acl/FilledChecklist.h"
51 #include "DelayPools.h"
52 #include "DelayPool.h"
53 #include "HttpRequest.h"
56 DelayId::DelayId () : pool_ (0), compositeId(NULL
), markedAsNoDelay(false)
59 DelayId::DelayId (unsigned short aPool
) :
60 pool_ (aPool
), compositeId (NULL
), markedAsNoDelay (false)
62 debugs(77, 3, "DelayId::DelayId: Pool " << aPool
<< "u");
69 DelayId::compositePosition(DelayIdComposite::Pointer newPosition
)
71 compositeId
= newPosition
;
81 DelayId::operator == (DelayId
const &rhs
) const
83 /* Doesn't compare composites properly....
84 * only use to test against default ID's
86 return pool_
== rhs
.pool_
&& compositeId
== rhs
.compositeId
;
89 DelayId::operator bool() const
91 return pool_
|| compositeId
.getRaw();
94 /* create a delay Id for a given request */
96 DelayId::DelayClient(ClientHttpRequest
* http
)
103 if (r
->client_addr
.IsNoAddr()) {
104 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
108 for (pool
= 0; pool
< DelayPools::pools(); pool
++) {
110 /* pools require explicit 'allow' to assign a client into them */
111 if (!DelayPools::delay_data
[pool
].access
) {
112 debugs(77, DBG_IMPORTANT
, "delay_pool " << pool
<<
113 " has no delay_access configured. This means that no clients will ever use it.");
117 ACLFilledChecklist
ch(DelayPools::delay_data
[pool
].access
, r
, NULL
);
118 #if FOLLOW_X_FORWARDED_FOR
119 if (Config
.onoff
.delay_pool_uses_indirect_client
)
120 ch
.src_addr
= r
->indirect_client_addr
;
122 #endif /* FOLLOW_X_FORWARDED_FOR */
123 ch
.src_addr
= r
->client_addr
;
124 ch
.my_addr
= r
->my_addr
;
126 if (http
->getConn() != NULL
)
127 ch
.conn(http
->getConn());
129 if (DelayPools::delay_data
[pool
].theComposite().getRaw() && ch
.fastCheck()) {
131 DelayId
result (pool
+ 1);
132 CompositePoolNode::CompositeSelectionDetails details
;
133 details
.src_addr
= ch
.src_addr
;
134 details
.user
= r
->auth_user_request
;
135 details
.tag
= r
->tag
;
136 result
.compositePosition(DelayPools::delay_data
[pool
].theComposite()->id(details
));
145 DelayId::setNoDelay(bool const newValue
)
147 markedAsNoDelay
= newValue
;
151 * this returns the number of bytes the client is permitted. it does not take
152 * into account bytes already buffered - that is up to the caller.
155 DelayId::bytesWanted(int minimum
, int maximum
) const
159 if (! (*this) || markedAsNoDelay
)
160 return max(minimum
, maximum
);
163 int nbytes
= max(minimum
, maximum
);
165 if (compositeId
!= NULL
)
166 nbytes
= compositeId
->bytesWanted(minimum
, nbytes
);
172 * this records actual bytes received. always recorded, even if the
173 * class is disabled - it's more efficient to just do it than to do all
177 DelayId::bytesIn(int qty
)
185 assert ((unsigned short)(pool() - 1) != 0xFFFF);
187 if (compositeId
!= NULL
)
188 compositeId
->bytesIn(qty
);
192 DelayId::delayRead(DeferredRead
const &aRead
)
194 assert (compositeId
!= NULL
);
195 compositeId
->delayRead(aRead
);
199 #endif /* USE_DELAY_POOLS */