2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 77 Delay Pools */
14 #include "comm/Connection.h"
15 #include "DelayTagged.h"
16 #include "NullDelayId.h"
19 DelayTagged::DelayTagged()
21 DelayPools::registerForUpdates (this);
24 static Splay
<DelayTaggedBucket::Pointer
>::SPLAYFREE DelayTaggedFree
;
26 DelayTagged::~DelayTagged()
28 DelayPools::deregisterForUpdates (this);
29 buckets
.destroy(DelayTaggedFree
);
32 static Splay
<DelayTaggedBucket::Pointer
>::SPLAYCMP DelayTaggedCmp
;
35 DelayTaggedCmp(DelayTaggedBucket::Pointer
const &left
, DelayTaggedBucket::Pointer
const &right
)
37 /* for rate limiting, case insensitive */
38 return left
->tag
.caseCmp(right
->tag
);
42 DelayTaggedFree(DelayTaggedBucket::Pointer
&)
45 struct DelayTaggedStatsVisitor
{
47 explicit DelayTaggedStatsVisitor(StoreEntry
*se
): sentry(se
) {}
48 void operator() (DelayTaggedBucket::Pointer
const ¤t
) {
49 current
->stats(sentry
);
54 DelayTagged::stats(StoreEntry
* sentry
)
56 spec
.stats (sentry
, "Per Tag");
58 if (spec
.restore_bps
== -1)
61 storeAppendPrintf(sentry
, "\t\tCurrent: ");
63 if (buckets
.empty()) {
64 storeAppendPrintf (sentry
, "Not used yet.\n\n");
68 DelayTaggedStatsVisitor
visitor(sentry
);
69 buckets
.visit(visitor
);
70 storeAppendPrintf(sentry
, "\n\n");
74 DelayTagged::dump(StoreEntry
*entry
) const
79 struct DelayTaggedUpdater
{
80 DelayTaggedUpdater (DelaySpec
&_spec
, int _incr
):spec(_spec
),incr(_incr
) {};
87 DelayTaggedUpdateWalkee(DelayTaggedBucket::Pointer
const ¤t
, void *state
)
89 DelayTaggedUpdater
*t
= (DelayTaggedUpdater
*)state
;
90 /* This doesn't change the value of the DelayTaggedBucket, so is safe */
91 const_cast<DelayTaggedBucket
*>(current
.getRaw())->theBucket
.update(t
->spec
, t
->incr
);
94 struct DelayTaggedUpdateVisitor
{
95 DelayTaggedUpdater
*updater
;
96 explicit DelayTaggedUpdateVisitor(DelayTaggedUpdater
*u
) : updater(u
) {}
97 void operator() (DelayTaggedBucket::Pointer
const ¤t
) {
98 const_cast<DelayTaggedBucket
*>(current
.getRaw())->theBucket
.update(updater
->spec
, updater
->incr
);
103 DelayTagged::update(int incr
)
105 DelayTaggedUpdater
updater(spec
, incr
);
106 DelayTaggedUpdateVisitor
visitor(&updater
);
107 buckets
.visit(visitor
);
117 DelayIdComposite::Pointer
119 DelayTagged::id(CompositePoolNode::CompositeSelectionDetails
&details
)
121 if (!details
.tag
.size())
122 return new NullDelayId
;
124 return new Id(this, details
.tag
);
127 DelayTaggedBucket::DelayTaggedBucket(String
&aTag
) : tag (aTag
)
129 debugs(77, 3, "DelayTaggedBucket::DelayTaggedBucket");
132 DelayTaggedBucket::~DelayTaggedBucket()
134 debugs(77, 3, "DelayTaggedBucket::~DelayTaggedBucket");
138 DelayTaggedBucket::stats(StoreEntry
*entry
) const
140 storeAppendPrintf(entry
, " " SQUIDSTRINGPH
":", SQUIDSTRINGPRINT(tag
));
141 theBucket
.stats(entry
);
144 DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged
, String
&aTag
) : theTagged(aDelayTagged
)
146 theBucket
= new DelayTaggedBucket(aTag
);
147 DelayTaggedBucket::Pointer
const *existing
= theTagged
->buckets
.find(theBucket
, DelayTaggedCmp
);
150 theBucket
= *existing
;
154 theBucket
->theBucket
.init(theTagged
->spec
);
155 theTagged
->buckets
.insert (theBucket
, DelayTaggedCmp
);
158 DelayTagged::Id::~Id()
160 debugs(77, 3, "DelayTagged::Id::~Id");
164 DelayTagged::Id::bytesWanted (int min
, int max
) const
166 return theBucket
->theBucket
.bytesWanted(min
,max
);
170 DelayTagged::Id::bytesIn(int qty
)
172 theBucket
->theBucket
.bytesIn(qty
);
176 DelayTagged::Id::delayRead(DeferredRead
const &aRead
)
178 theTagged
->delayRead(aRead
);