]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelayId.cc
Policy change for negative_ttl
[thirdparty/squid.git] / src / DelayId.cc
CommitLineData
b67e2c8c 1
2/*
454e8283 3 * $Id: DelayId.cc,v 1.25 2008/01/20 19:46:35 serassio Exp $
b67e2c8c 4 *
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>
9 *
10 * SQUID Web Proxy Cache http://www.squid-cache.org/
11 * ----------------------------------------------------------
12 *
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.
21 *
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.
26 *
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.
31 *
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.
35 *
36 *
37 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
38 */
39
40#include "config.h"
41
454e8283 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.
44 */
45#if DELAY_POOLS
46
b67e2c8c 47#include "squid.h"
48#include "DelayId.h"
49#include "client_side_request.h"
50#include "ACLChecklist.h"
51#include "DelayPools.h"
52#include "DelayPool.h"
8000a965 53#include "HttpRequest.h"
a46d2c0e 54#include "CommRead.h"
55
56DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
62e76326 57{}
b67e2c8c 58
62e76326 59DelayId::DelayId (unsigned short aPool) :
a46d2c0e 60 pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
b67e2c8c 61{
bf8fe701 62 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
b67e2c8c 63}
64
65DelayId::~DelayId ()
62e76326 66{}
b67e2c8c 67
68void
69DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
70{
71 compositeId = newPosition;
72}
73
74unsigned short
75DelayId::pool() const
76{
77 return pool_;
78}
79
80bool
81DelayId::operator == (DelayId const &rhs) const
82{
83 /* Doesn't compare composites properly....
84 * only use to test against default ID's
85 */
86 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
87}
88
62e76326 89DelayId::operator bool() const
b67e2c8c 90{
91 return pool_ || compositeId.getRaw();
92}
93
7ec8c6a2 94/* create a delay Id for a given request */
b67e2c8c 95DelayId
59a1efb2 96DelayId::DelayClient(ClientHttpRequest * http)
b67e2c8c 97{
190154cf 98 HttpRequest *r;
b67e2c8c 99 unsigned short pool;
100 assert(http);
101 r = http->request;
102
cc192b50 103 if (r->client_addr.IsNoAddr()) {
104 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
62e76326 105 return DelayId();
b67e2c8c 106 }
107
607e0693 108 for (pool = 0; pool < DelayPools::pools(); pool++) {
7ec8c6a2 109 ACLChecklist ch;
110 ch.src_addr = r->client_addr;
111 ch.my_addr = r->my_addr;
62e76326 112
4d3a24ca 113 if (http->getConn() != NULL)
a2ac85d9 114 ch.conn(http->getConn());
62e76326 115
6dd9f4bd 116 ch.request = HTTPMSGLOCK(r);
62e76326 117
506768d9 118 ch.accessList = cbdataReference(DelayPools::delay_data[pool].access);
b448c119 119
108d65b2 120 /* cbdataReferenceDone() happens in either fastCheck() or ~ACLCheckList */
121
607e0693 122 if (DelayPools::delay_data[pool].theComposite().getRaw() &&
b448c119 123 ch.fastCheck()) {
62e76326 124 DelayId result (pool + 1);
1e5562e3 125 CompositePoolNode::CompositeSelectionDetails details;
126 details.src_addr = ch.src_addr;
127 details.user = r->auth_user_request;
128 details.tag = r->tag;
129 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
62e76326 130 return result;
131 }
7ec8c6a2 132 }
133
b67e2c8c 134 return DelayId();
135}
136
a46d2c0e 137void
138DelayId::setNoDelay(bool const newValue)
139{
140 markedAsNoDelay = newValue;
141}
142
b67e2c8c 143/*
144 * this returns the number of bytes the client is permitted. it does not take
145 * into account bytes already buffered - that is up to the caller.
146 */
147int
a748a390 148DelayId::bytesWanted(int minimum, int maximum) const
b67e2c8c 149{
150 /* unlimited */
62e76326 151
a46d2c0e 152 if (! (*this) || markedAsNoDelay)
a748a390 153 return max(minimum, maximum);
62e76326 154
b67e2c8c 155 /* limited */
a748a390 156 int nbytes = max(minimum, maximum);
62e76326 157
4d3a24ca 158 if (compositeId != NULL)
a748a390 159 nbytes = compositeId->bytesWanted(minimum, nbytes);
62e76326 160
b67e2c8c 161 return nbytes;
162}
163
164/*
2324cda2 165 * this records actual bytes received. always recorded, even if the
b67e2c8c 166 * class is disabled - it's more efficient to just do it than to do all
167 * the checks.
168 */
169void
170DelayId::bytesIn(int qty)
171{
172 if (! (*this))
62e76326 173 return;
b67e2c8c 174
a46d2c0e 175 if (markedAsNoDelay)
176 return;
177
e4a67a80 178 assert ((unsigned short)(pool() - 1) != 0xFFFF);
b67e2c8c 179
4d3a24ca 180 if (compositeId != NULL)
62e76326 181 compositeId->bytesIn(qty);
b67e2c8c 182}
62e76326 183
a46d2c0e 184void
185DelayId::delayRead(DeferredRead const &aRead)
186{
4d3a24ca 187 assert (compositeId != NULL);
a46d2c0e 188 compositeId->delayRead(aRead);
b67e2c8c 189
a46d2c0e 190}
454e8283 191
192#endif /* DELAY_POOLS */