]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelayVector.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / DelayVector.cc
CommitLineData
b67e2c8c 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
26ac0430 3 *
bbc27441
AJ
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.
b67e2c8c 7 */
8
bbc27441
AJ
9/* DEBUG: section 77 Delay Pools */
10
f7f3304a 11#include "squid.h"
b67e2c8c 12
9a0a18de 13#if USE_DELAY_POOLS
1b76e6c1 14#include "comm/Connection.h"
a46d2c0e 15#include "CommRead.h"
582c2af2 16#include "DelayVector.h"
b67e2c8c 17
18void *
19DelayVector::operator new(size_t size)
20{
21 DelayPools::MemoryUsed += sizeof (DelayVector);
22 return ::operator new (size);
23}
24
25void
26DelayVector::operator delete (void *address)
27{
28 DelayPools::MemoryUsed -= sizeof (DelayVector);
29 ::operator delete (address);
30}
31
2e6c0f0f 32DelayVector::DelayVector()
33{
4610ec53 34 DelayPools::registerForUpdates (this);
2e6c0f0f 35}
36
b67e2c8c 37DelayVector::~DelayVector()
2e6c0f0f 38{
4610ec53 39 DelayPools::deregisterForUpdates (this);
2e6c0f0f 40}
b67e2c8c 41
42void
43DelayVector::stats(StoreEntry * sentry)
44{
45 iterator pos = pools.begin();
62e76326 46
b67e2c8c 47 while (pos != pools.end()) {
62e76326 48 (*pos)->stats(sentry);
49 ++pos;
b67e2c8c 50 }
51}
52
53void
54DelayVector::dump(StoreEntry *entry) const
55{
56 const_iterator pos = pools.begin();
62e76326 57
b67e2c8c 58 while (pos != pools.end()) {
62e76326 59 (*pos)->dump(entry);
60 ++pos;
b67e2c8c 61 }
62}
63
64void
65DelayVector::update(int incr)
66{
2e6c0f0f 67 /*
68 * Each pool updates itself,
69 * but we may have deferred reads waiting on the pool as a whole.
70 */
a46d2c0e 71
72 kickReads();
b67e2c8c 73}
74
75void
76DelayVector::parse()
77{
78 iterator pos = pools.begin();
62e76326 79
b67e2c8c 80 while (pos != pools.end()) {
62e76326 81 (*pos)->parse();
82 ++pos;
b67e2c8c 83 }
84}
85
86DelayIdComposite::Pointer
1e5562e3 87DelayVector::id(CompositeSelectionDetails &details)
b67e2c8c 88{
1e5562e3 89 return new Id(this, details);
b67e2c8c 90}
91
92void
93DelayVector::push_back(CompositePoolNode::Pointer aNode)
94{
95 pools.push_back(aNode);
96}
97
98void *
99DelayVector::Id::operator new(size_t size)
100{
101 DelayPools::MemoryUsed += sizeof (Id);
102 return ::operator new (size);
103}
104
105void
106DelayVector::Id::operator delete (void *address)
107{
108 DelayPools::MemoryUsed -= sizeof (Id);
109 ::operator delete (address);
110}
111
1e5562e3 112DelayVector::Id::Id(DelayVector::Pointer aDelayVector, CompositeSelectionDetails &details) : theVector(aDelayVector)
b67e2c8c 113{
bf8fe701 114 debugs(77, 3, "DelayVector::Id::Id");
b67e2c8c 115 DelayVector::iterator pos = theVector->pools.begin();
62e76326 116
1e5562e3 117 while (pos != theVector->pools.end()) {
118 ids.push_back ((*pos)->id (details));
62e76326 119 ++pos;
b67e2c8c 120 }
121}
122
2f44bd34 123DelayVector::Id::~Id()
124{
bf8fe701 125 debugs(77, 3, "DelayVector::Id::~Id");
2f44bd34 126}
127
b67e2c8c 128int
a748a390 129DelayVector::Id::bytesWanted (int minimum, int maximum) const
b67e2c8c 130{
a748a390 131 int nbytes = maximum;
b67e2c8c 132 const_iterator pos = ids.begin();
62e76326 133
b67e2c8c 134 while (pos != ids.end()) {
a748a390 135 nbytes = min (nbytes, (*pos)->bytesWanted(minimum, nbytes));
62e76326 136 ++pos;
b67e2c8c 137 }
62e76326 138
a748a390 139 nbytes = max(minimum, nbytes);
b67e2c8c 140 return nbytes;
141}
142
143void
144DelayVector::Id::bytesIn(int qty)
145{
146 iterator pos = ids.begin();
62e76326 147
b67e2c8c 148 while (pos != ids.end()) {
62e76326 149 (*pos)->bytesIn(qty);
150 ++pos;
b67e2c8c 151 }
a46d2c0e 152
153 theVector->kickReads();
154}
155
156void
157DelayVector::Id::delayRead(DeferredRead const &aRead)
158{
159 theVector->delayRead(aRead);
b67e2c8c 160}
62e76326 161
b67e2c8c 162#endif
f53969cc 163