2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 77 Delay Pools */
13 /* MS Visual Studio Projects are monolithic, so we need the following
14 * #if to exclude the delay pools code from compile process when not needed.
17 #include "acl/FilledChecklist.h"
18 #include "client_side_request.h"
21 #include "DelayPool.h"
22 #include "DelayPools.h"
23 #include "HttpRequest.h"
24 #include "SquidConfig.h"
26 DelayId::DelayId () : pool_ (0), compositeId(NULL
), markedAsNoDelay(false)
29 DelayId::DelayId (unsigned short aPool
) :
30 pool_ (aPool
), compositeId (NULL
), markedAsNoDelay (false)
32 debugs(77, 3, "DelayId::DelayId: Pool " << aPool
<< "u");
39 DelayId::compositePosition(DelayIdComposite::Pointer newPosition
)
41 compositeId
= newPosition
;
51 DelayId::operator == (DelayId
const &rhs
) const
53 /* Doesn't compare composites properly....
54 * only use to test against default ID's
56 return pool_
== rhs
.pool_
&& compositeId
== rhs
.compositeId
;
59 DelayId::operator bool() const
61 return pool_
|| compositeId
.getRaw();
64 /* create a delay Id for a given request */
66 DelayId::DelayClient(ClientHttpRequest
* http
, HttpReply
*reply
)
73 if (r
->client_addr
.isNoAddr()) {
74 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
78 for (pool
= 0; pool
< DelayPools::pools(); ++pool
) {
80 /* pools require explicit 'allow' to assign a client into them */
81 if (!DelayPools::delay_data
[pool
].access
) {
82 debugs(77, DBG_IMPORTANT
, "delay_pool " << pool
<<
83 " has no delay_access configured. This means that no clients will ever use it.");
87 ACLFilledChecklist
ch(DelayPools::delay_data
[pool
].access
, r
, NULL
);
92 #if FOLLOW_X_FORWARDED_FOR
93 if (Config
.onoff
.delay_pool_uses_indirect_client
)
94 ch
.src_addr
= r
->indirect_client_addr
;
96 #endif /* FOLLOW_X_FORWARDED_FOR */
97 ch
.src_addr
= r
->client_addr
;
98 ch
.my_addr
= r
->my_addr
;
100 if (http
->getConn() != NULL
)
101 ch
.conn(http
->getConn());
103 if (DelayPools::delay_data
[pool
].theComposite().getRaw() && ch
.fastCheck() == ACCESS_ALLOWED
) {
105 DelayId
result (pool
+ 1);
106 CompositePoolNode::CompositeSelectionDetails details
;
107 details
.src_addr
= ch
.src_addr
;
109 details
.user
= r
->auth_user_request
;
111 details
.tag
= r
->tag
;
112 result
.compositePosition(DelayPools::delay_data
[pool
].theComposite()->id(details
));
121 DelayId::setNoDelay(bool const newValue
)
123 markedAsNoDelay
= newValue
;
127 * this returns the number of bytes the client is permitted. it does not take
128 * into account bytes already buffered - that is up to the caller.
131 DelayId::bytesWanted(int minimum
, int maximum
) const
135 if (! (*this) || markedAsNoDelay
)
136 return max(minimum
, maximum
);
139 int nbytes
= max(minimum
, maximum
);
141 if (compositeId
!= NULL
)
142 nbytes
= compositeId
->bytesWanted(minimum
, nbytes
);
148 * this records actual bytes received. always recorded, even if the
149 * class is disabled - it's more efficient to just do it than to do all
153 DelayId::bytesIn(int qty
)
161 assert ((unsigned short)(pool() - 1) != 0xFFFF);
163 if (compositeId
!= NULL
)
164 compositeId
->bytesIn(qty
);
168 DelayId::delayRead(DeferredRead
const &aRead
)
170 assert (compositeId
!= NULL
);
171 compositeId
->delayRead(aRead
);
175 #endif /* USE_DELAY_POOLS */