]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayUser.cc
Summary: Merge delay-class-4 fixes into HEAD.
[thirdparty/squid.git] / src / DelayUser.cc
1
2 /*
3 * $Id: DelayUser.cc,v 1.2 2003/02/06 09:57:36 robertc Exp $
4 *
5 * DEBUG: section 77 Delay Pools
6 * AUTHOR: Robert Collins <robertc@squid-cache.org>
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 *
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 */
37
38 #include "config.h"
39
40 #if DELAY_POOLS
41 #include "squid.h"
42 #include "DelayUser.h"
43 #include "authenticate.h"
44 #include "NullDelayId.h"
45 #include "Store.h"
46
47 void *
48 DelayUser::operator new(size_t size)
49 {
50 DelayPools::MemoryUsed += sizeof (DelayUser);
51 return ::operator new (size);
52 }
53
54 void
55 DelayUser::operator delete (void *address)
56 {
57 DelayPools::MemoryUsed -= sizeof (DelayUser);
58 ::operator delete (address);
59 }
60
61 void
62 DelayUser::deleteSelf() const
63 {
64 delete this;
65 }
66
67 DelayUser::DelayUser()
68 {
69 DelayPools::registerForUpdates (this);
70 }
71
72 DelayUser::~DelayUser()
73 {
74 DelayPools::deregisterForUpdates (this);
75 }
76
77 void
78 DelayUser::stats(StoreEntry * sentry)
79 {
80 spec.stats (sentry, "Per User");
81 if (spec.restore_bps == -1)
82 return;
83 storeAppendPrintf(sentry, "\t\tCurrent: ");
84 if (!buckets.size()) {
85 storeAppendPrintf (sentry, "Not used yet.\n\n");
86 return;
87 }
88 iterator pos = buckets.begin();
89 while (pos != buckets.end()) {
90 (*pos)->stats(sentry);
91 ++pos;
92 }
93 storeAppendPrintf(sentry, "\n\n");
94 }
95
96 void
97 DelayUser::dump(StoreEntry *entry) const
98 {
99 spec.dump(entry);
100 }
101
102 void
103 DelayUser::update(int incr)
104 {
105 iterator pos = buckets.begin();
106 while (pos != buckets.end()) {
107 (*pos)->theBucket.update(spec, incr);
108 ++pos;
109 }
110 }
111
112 void
113 DelayUser::parse()
114 {
115 spec.parse();
116 }
117
118 DelayIdComposite::Pointer
119 DelayUser::id(struct in_addr &src_addr, AuthUserRequest *authRequest)
120 {
121 if (!authRequest)
122 return new NullDelayId;
123 return new Id(this, authRequest->auth_user);
124 }
125
126 void *
127 DelayUser::Id::operator new(size_t size)
128 {
129 DelayPools::MemoryUsed += sizeof (Id);
130 return ::operator new (size);
131 }
132
133 void
134 DelayUser::Id::operator delete (void *address)
135 {
136 DelayPools::MemoryUsed -= sizeof (Id);
137 ::operator delete (address);
138 }
139
140 void
141 DelayUser::Id::deleteSelf() const
142 {
143 delete this;
144 }
145
146 void *
147 DelayUserBucket::operator new(size_t size)
148 {
149 DelayPools::MemoryUsed += sizeof (DelayUserBucket);
150 return ::operator new (size);
151 }
152
153 void
154 DelayUserBucket::operator delete (void *address)
155 {
156 DelayPools::MemoryUsed -= sizeof (DelayUserBucket);
157 ::operator delete (address);
158 }
159
160 DelayUserBucket::DelayUserBucket(AuthUser *aUser) : authUser (aUser)
161 {
162 debug (77,3) ("DelayUserBucket::DelayUserBucket\n");
163 authenticateAuthUserLock (authUser);
164 }
165
166 DelayUserBucket::~DelayUserBucket()
167 {
168 authenticateAuthUserUnlock(authUser);
169 debug (77,3) ("DelayUserBucket::~DelayUserBucket\n");
170 }
171
172 void
173 DelayUserBucket::stats (StoreEntry *entry) const
174 {
175 storeAppendPrintf(entry, " %s:", authUser->username());
176 theBucket.stats (entry);
177 }
178
179 DelayUser::Id::Id(DelayUser::Pointer aDelayUser,AuthUser *aUser) : theUser(aDelayUser)
180 {
181 DelayUser::iterator pos = theUser->buckets.begin();
182 while (pos != theUser->buckets.end()) {
183 if ((*pos)->authUser == aUser) {
184 theBucket = (*pos);
185 return;
186 }
187 ++pos;
188 }
189
190 theBucket = new DelayUserBucket(aUser);
191 theBucket->theBucket.init(theUser->spec);
192 theUser->buckets.push_back (theBucket);
193 }
194
195 DelayUser::Id::~Id()
196 {
197 debug (77,3) ("DelayUser::Id::~Id\n");
198 }
199
200 int
201 DelayUser::Id::bytesWanted (int min, int max) const
202 {
203 return theBucket->theBucket.bytesWanted(min,max);
204 }
205
206 void
207 DelayUser::Id::bytesIn(int qty)
208 {
209 theBucket->theBucket.bytesIn(qty);
210 }
211 #endif