/*
- * $Id: DelayId.cc,v 1.1 2003/02/05 10:36:48 robertc Exp $
+ * $Id$
*
* DEBUG: section 77 Delay Pools
* AUTHOR: Robert Collins <robertc@squid-cache.org>
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
* Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
*/
-#include "config.h"
-
-#if DELAY_POOLS
#include "squid.h"
+
+/* MS Visual Studio Projects are monolithic, so we need the following
+ * #if to exclude the delay pools code from compile process when not needed.
+ */
+#if USE_DELAY_POOLS
+
+#include "squid-old.h"
#include "DelayId.h"
#include "client_side_request.h"
-#include "ACLChecklist.h"
+#include "acl/FilledChecklist.h"
#include "DelayPools.h"
#include "DelayPool.h"
-/*
-#include "DelaySpec.h"
-#include "StoreClient.h"
-#include "Store.h"
-#include "MemObject.h"
-#include "ACL.h"
-#include "Config.h"
-#include "DelayId.h"
-#include "Array.h"
-#include "String.h"
-#include "CommonPool.h"
-#include "CompositePoolNode.h"
-#include "DelayVector.h"
-#include "NullDelayId.h"
-#include "DelayBucket.h"
-*/
-
-DelayId::DelayId () : pool_ (0), compositeId(NULL)
-{
-}
+#include "HttpRequest.h"
+#include "CommRead.h"
-DelayId::DelayId (unsigned short aPool) :
-pool_ (aPool), compositeId (NULL)
+DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
+{}
+
+DelayId::DelayId (unsigned short aPool) :
+ pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
{
+ debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
}
DelayId::~DelayId ()
-{
-}
+{}
void
DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
DelayId::operator == (DelayId const &rhs) const
{
/* Doesn't compare composites properly....
- * only use to test against default ID's
+ * only use to test against default ID's
*/
return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
}
-DelayId::operator bool() const
+DelayId::operator bool() const
{
return pool_ || compositeId.getRaw();
}
+/* create a delay Id for a given request */
DelayId
-DelayId::DelayClient(clientHttpRequest * http)
+DelayId::DelayClient(ClientHttpRequest * http)
{
- request_t *r;
+ HttpRequest *r;
unsigned short pool;
assert(http);
r = http->request;
- if (r->client_addr.s_addr == INADDR_BROADCAST) {
- debug(77, 2) ("delayClient: WARNING: Called with 'allones' address, ignoring\n");
- return DelayId();
+ if (r->client_addr.IsNoAddr()) {
+ debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
+ return DelayId();
+ }
+
+ for (pool = 0; pool < DelayPools::pools(); pool++) {
+
+ /* pools require explicit 'allow' to assign a client into them */
+ if (!DelayPools::delay_data[pool].access) {
+ debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
+ " has no delay_access configured. This means that no clients will ever use it.");
+ continue;
+ }
+
+ ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL);
+#if FOLLOW_X_FORWARDED_FOR
+ if (Config.onoff.delay_pool_uses_indirect_client)
+ ch.src_addr = r->indirect_client_addr;
+ else
+#endif /* FOLLOW_X_FORWARDED_FOR */
+ ch.src_addr = r->client_addr;
+ ch.my_addr = r->my_addr;
+
+ if (http->getConn() != NULL)
+ ch.conn(http->getConn());
+
+ if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck() == ACCESS_ALLOWED) {
+
+ DelayId result (pool + 1);
+ CompositePoolNode::CompositeSelectionDetails details;
+ details.src_addr = ch.src_addr;
+#if USE_AUTH
+ details.user = r->auth_user_request;
+#endif
+ details.tag = r->tag;
+ result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
+ return result;
+ }
}
- ACLChecklist ch;
- ch.src_addr = r->client_addr;
- ch.my_addr = r->my_addr;
- ch.my_port = r->my_port;
- ch.conn = http->conn;
- ch.request = r;
- for (pool = 0; pool < DelayPools::pools(); pool++)
- if (DelayPools::delay_data[pool].theComposite().getRaw() &&
- aclCheckFast(DelayPools::delay_data[pool].access, &ch)) {
- DelayId result (pool + 1);
- result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(ch.src_addr, r->auth_user_request));
- return result;
- }
return DelayId();
}
+void
+DelayId::setNoDelay(bool const newValue)
+{
+ markedAsNoDelay = newValue;
+}
+
/*
* this returns the number of bytes the client is permitted. it does not take
* into account bytes already buffered - that is up to the caller.
*/
int
-DelayId::bytesWanted(int min, int max) const
+DelayId::bytesWanted(int minimum, int maximum) const
{
/* unlimited */
- if (! (*this))
- return XMAX(min, max);
-
+
+ if (! (*this) || markedAsNoDelay)
+ return max(minimum, maximum);
+
/* limited */
- int nbytes = XMAX(min, max);
- if (compositeId.getRaw())
- nbytes = compositeId->bytesWanted(min, nbytes);
+ int nbytes = max(minimum, maximum);
+
+ if (compositeId != NULL)
+ nbytes = compositeId->bytesWanted(minimum, nbytes);
+
return nbytes;
}
/*
- * this records actual bytes recieved. always recorded, even if the
+ * this records actual bytes received. always recorded, even if the
* class is disabled - it's more efficient to just do it than to do all
* the checks.
*/
DelayId::bytesIn(int qty)
{
if (! (*this))
- return;
+ return;
- unsigned short tempPool = pool() - 1;
+ if (markedAsNoDelay)
+ return;
- assert (tempPool != 0xFFFF);
+ assert ((unsigned short)(pool() - 1) != 0xFFFF);
+
+ if (compositeId != NULL)
+ compositeId->bytesIn(qty);
+}
+
+void
+DelayId::delayRead(DeferredRead const &aRead)
+{
+ assert (compositeId != NULL);
+ compositeId->delayRead(aRead);
- if (compositeId.getRaw())
- compositeId->bytesIn(qty);
}
-#endif
+#endif /* USE_DELAY_POOLS */