2 * Copyright (C) 1996-2015 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
)
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
);
88 #if FOLLOW_X_FORWARDED_FOR
89 if (Config
.onoff
.delay_pool_uses_indirect_client
)
90 ch
.src_addr
= r
->indirect_client_addr
;
92 #endif /* FOLLOW_X_FORWARDED_FOR */
93 ch
.src_addr
= r
->client_addr
;
94 ch
.my_addr
= r
->my_addr
;
96 if (http
->getConn() != NULL
)
97 ch
.conn(http
->getConn());
99 if (DelayPools::delay_data
[pool
].theComposite().getRaw() && ch
.fastCheck() == ACCESS_ALLOWED
) {
101 DelayId
result (pool
+ 1);
102 CompositePoolNode::CompositeSelectionDetails details
;
103 details
.src_addr
= ch
.src_addr
;
105 details
.user
= r
->auth_user_request
;
107 details
.tag
= r
->tag
;
108 result
.compositePosition(DelayPools::delay_data
[pool
].theComposite()->id(details
));
117 DelayId::setNoDelay(bool const newValue
)
119 markedAsNoDelay
= newValue
;
123 * this returns the number of bytes the client is permitted. it does not take
124 * into account bytes already buffered - that is up to the caller.
127 DelayId::bytesWanted(int minimum
, int maximum
) const
131 if (! (*this) || markedAsNoDelay
)
132 return max(minimum
, maximum
);
135 int nbytes
= max(minimum
, maximum
);
137 if (compositeId
!= NULL
)
138 nbytes
= compositeId
->bytesWanted(minimum
, nbytes
);
144 * this records actual bytes received. always recorded, even if the
145 * class is disabled - it's more efficient to just do it than to do all
149 DelayId::bytesIn(int qty
)
157 assert ((unsigned short)(pool() - 1) != 0xFFFF);
159 if (compositeId
!= NULL
)
160 compositeId
->bytesIn(qty
);
164 DelayId::delayRead(DeferredRead
const &aRead
)
166 assert (compositeId
!= NULL
);
167 compositeId
->delayRead(aRead
);
171 #endif /* USE_DELAY_POOLS */