]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelayId.cc
Update with information on the feature freeze todo items
[thirdparty/squid.git] / src / DelayId.cc
CommitLineData
b67e2c8c 1
2/*
a748a390 3 * $Id: DelayId.cc,v 1.6 2003/03/10 20:12:43 robertc 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
a46d2c0e 42#if !DELAY_POOLS
43#error DELAY_POOLS not enabled
44#endif
b67e2c8c 45#include "squid.h"
46#include "DelayId.h"
47#include "client_side_request.h"
48#include "ACLChecklist.h"
49#include "DelayPools.h"
50#include "DelayPool.h"
8000a965 51#include "HttpRequest.h"
a46d2c0e 52#include "CommRead.h"
53
54DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
62e76326 55{}
b67e2c8c 56
62e76326 57DelayId::DelayId (unsigned short aPool) :
a46d2c0e 58 pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
b67e2c8c 59{
658d5a21 60 debug (77,3)("DelayId::DelayId: Pool %du\n", aPool);
b67e2c8c 61}
62
63DelayId::~DelayId ()
62e76326 64{}
b67e2c8c 65
66void
67DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
68{
69 compositeId = newPosition;
70}
71
72unsigned short
73DelayId::pool() const
74{
75 return pool_;
76}
77
78bool
79DelayId::operator == (DelayId const &rhs) const
80{
81 /* Doesn't compare composites properly....
82 * only use to test against default ID's
83 */
84 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
85}
86
62e76326 87DelayId::operator bool() const
b67e2c8c 88{
89 return pool_ || compositeId.getRaw();
90}
91
92DelayId
93DelayId::DelayClient(clientHttpRequest * http)
94{
95 request_t *r;
96 unsigned short pool;
97 assert(http);
98 r = http->request;
99
100 if (r->client_addr.s_addr == INADDR_BROADCAST) {
62e76326 101 debug(77, 2) ("delayClient: WARNING: Called with 'allones' address, ignoring\n");
102 return DelayId();
b67e2c8c 103 }
104
105 ACLChecklist ch;
106 ch.src_addr = r->client_addr;
107 ch.my_addr = r->my_addr;
108 ch.my_port = r->my_port;
62e76326 109
8000a965 110 if (http->conn)
62e76326 111 ch.conn(cbdataReference(http->conn));
112
8000a965 113 ch.request = requestLink(r);
62e76326 114
b67e2c8c 115 for (pool = 0; pool < DelayPools::pools(); pool++)
62e76326 116 if (DelayPools::delay_data[pool].theComposite().getRaw() &&
117 aclCheckFast(DelayPools::delay_data[pool].access, &ch)) {
118 DelayId result (pool + 1);
119 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(ch.src_addr, r->auth_user_request));
120 return result;
121 }
122
b67e2c8c 123 return DelayId();
124}
125
a46d2c0e 126void
127DelayId::setNoDelay(bool const newValue)
128{
129 markedAsNoDelay = newValue;
130}
131
b67e2c8c 132/*
133 * this returns the number of bytes the client is permitted. it does not take
134 * into account bytes already buffered - that is up to the caller.
135 */
136int
a748a390 137DelayId::bytesWanted(int minimum, int maximum) const
b67e2c8c 138{
139 /* unlimited */
62e76326 140
a46d2c0e 141 if (! (*this) || markedAsNoDelay)
a748a390 142 return max(minimum, maximum);
62e76326 143
b67e2c8c 144 /* limited */
a748a390 145 int nbytes = max(minimum, maximum);
62e76326 146
b67e2c8c 147 if (compositeId.getRaw())
a748a390 148 nbytes = compositeId->bytesWanted(minimum, nbytes);
62e76326 149
b67e2c8c 150 return nbytes;
151}
152
153/*
154 * this records actual bytes recieved. always recorded, even if the
155 * class is disabled - it's more efficient to just do it than to do all
156 * the checks.
157 */
158void
159DelayId::bytesIn(int qty)
160{
161 if (! (*this))
62e76326 162 return;
b67e2c8c 163
a46d2c0e 164 if (markedAsNoDelay)
165 return;
166
b67e2c8c 167 unsigned short tempPool = pool() - 1;
168
169 assert (tempPool != 0xFFFF);
170
171 if (compositeId.getRaw())
62e76326 172 compositeId->bytesIn(qty);
b67e2c8c 173}
62e76326 174
a46d2c0e 175void
176DelayId::delayRead(DeferredRead const &aRead)
177{
178 assert (compositeId.getRaw());
179 compositeId->delayRead(aRead);
b67e2c8c 180
a46d2c0e 181}