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