5 * DEBUG: section 77 Delay Pools
6 * AUTHOR: Robert Collins <robertc@squid-cache.org>
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
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.
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.
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.
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.
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
42 #include "DelayUser.h"
43 #include "auth/UserRequest.h"
44 #include "auth/User.h"
45 #include "NullDelayId.h"
49 DelayUser::operator new(size_t size
)
51 DelayPools::MemoryUsed
+= sizeof (DelayUser
);
52 return ::operator new (size
);
56 DelayUser::operator delete (void *address
)
58 DelayPools::MemoryUsed
-= sizeof (DelayUser
);
59 ::operator delete (address
);
62 DelayUser::DelayUser()
64 DelayPools::registerForUpdates (this);
67 static SplayNode
<DelayUserBucket::Pointer
>::SPLAYFREE DelayUserFree
;
69 DelayUser::~DelayUser()
71 DelayPools::deregisterForUpdates (this);
72 buckets
.head
->destroy (DelayUserFree
);
75 static SplayNode
<DelayUserBucket::Pointer
>::SPLAYCMP DelayUserCmp
;
78 DelayUserCmp(DelayUserBucket::Pointer
const &left
, DelayUserBucket::Pointer
const &right
)
80 /* for rate limiting, case insensitive */
81 return strcasecmp(left
->authUser
->username(), right
->authUser
->username());
85 DelayUserFree(DelayUserBucket::Pointer
&)
89 DelayUserStatsWalkee(DelayUserBucket::Pointer
const ¤t
, void *state
)
91 current
->stats ((StoreEntry
*)state
);
95 DelayUser::stats(StoreEntry
* sentry
)
97 spec
.stats (sentry
, "Per User");
99 if (spec
.restore_bps
== -1)
102 storeAppendPrintf(sentry
, "\t\tCurrent: ");
105 storeAppendPrintf (sentry
, "Not used yet.\n\n");
109 buckets
.head
->walk(DelayUserStatsWalkee
, sentry
);
110 storeAppendPrintf(sentry
, "\n\n");
114 DelayUser::dump(StoreEntry
*entry
) const
119 struct DelayUserUpdater
{
120 DelayUserUpdater (DelaySpec
&_spec
, int _incr
):spec(_spec
),incr(_incr
) {};
127 DelayUserUpdateWalkee(DelayUserBucket::Pointer
const ¤t
, void *state
)
129 DelayUserUpdater
*t
= (DelayUserUpdater
*)state
;
130 /* This doesn't change the value of the DelayUserBucket, so is safe */
131 const_cast<DelayUserBucket
*>(current
.getRaw())->theBucket
.update(t
->spec
, t
->incr
);
135 DelayUser::update(int incr
)
137 DelayUserUpdater
updater(spec
, incr
);
138 buckets
.head
->walk (DelayUserUpdateWalkee
, &updater
);
147 DelayIdComposite::Pointer
148 DelayUser::id(CompositePoolNode::CompositeSelectionDetails
&details
)
151 return new NullDelayId
;
153 return new Id(this, details
.user
->user());
157 DelayUser::Id::operator new(size_t size
)
159 DelayPools::MemoryUsed
+= sizeof (Id
);
160 return ::operator new (size
);
164 DelayUser::Id::operator delete (void *address
)
166 DelayPools::MemoryUsed
-= sizeof (Id
);
167 ::operator delete (address
);
171 DelayUserBucket::operator new(size_t size
)
173 DelayPools::MemoryUsed
+= sizeof (DelayUserBucket
);
174 return ::operator new (size
);
178 DelayUserBucket::operator delete (void *address
)
180 DelayPools::MemoryUsed
-= sizeof (DelayUserBucket
);
181 ::operator delete (address
);
184 DelayUserBucket::DelayUserBucket(AuthUser
*aUser
) : authUser (aUser
)
186 debugs(77, 3, "DelayUserBucket::DelayUserBucket");
191 DelayUserBucket::~DelayUserBucket()
194 debugs(77, 3, "DelayUserBucket::~DelayUserBucket");
198 DelayUserBucket::stats (StoreEntry
*entry
) const
200 storeAppendPrintf(entry
, " %s:", authUser
->username());
201 theBucket
.stats (entry
);
204 DelayUser::Id::Id(DelayUser::Pointer aDelayUser
,AuthUser
*aUser
) : theUser(aDelayUser
)
206 theBucket
= new DelayUserBucket(aUser
);
207 DelayUserBucket::Pointer
const *existing
= theUser
->buckets
.find(theBucket
, DelayUserCmp
);
210 theBucket
= *existing
;
214 theBucket
->theBucket
.init(theUser
->spec
);
215 theUser
->buckets
.head
= theUser
->buckets
.head
->insert (theBucket
, DelayUserCmp
);
220 debugs(77, 3, "DelayUser::Id::~Id");
224 DelayUser::Id::bytesWanted (int min
, int max
) const
226 return theBucket
->theBucket
.bytesWanted(min
,max
);
230 DelayUser::Id::bytesIn(int qty
)
232 theBucket
->theBucket
.bytesIn(qty
);