]>
Commit | Line | Data |
---|---|---|
b67e2c8c | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 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 | |
454e8283 | 13 | /* MS Visual Studio Projects are monolithic, so we need the following |
14 | * #if to exclude the delay pools code from compile process when not needed. | |
15 | */ | |
9a0a18de | 16 | #if USE_DELAY_POOLS |
c0941a6a | 17 | #include "acl/FilledChecklist.h" |
582c2af2 FC |
18 | #include "client_side_request.h" |
19 | #include "CommRead.h" | |
20 | #include "DelayId.h" | |
b67e2c8c | 21 | #include "DelayPool.h" |
582c2af2 | 22 | #include "DelayPools.h" |
8000a965 | 23 | #include "HttpRequest.h" |
4d5904f7 | 24 | #include "SquidConfig.h" |
a46d2c0e | 25 | |
26 | DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false) | |
62e76326 | 27 | {} |
b67e2c8c | 28 | |
62e76326 | 29 | DelayId::DelayId (unsigned short aPool) : |
f53969cc | 30 | pool_ (aPool), compositeId (NULL), markedAsNoDelay (false) |
b67e2c8c | 31 | { |
bf8fe701 | 32 | debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u"); |
b67e2c8c | 33 | } |
34 | ||
35 | DelayId::~DelayId () | |
62e76326 | 36 | {} |
b67e2c8c | 37 | |
38 | void | |
39 | DelayId::compositePosition(DelayIdComposite::Pointer newPosition) | |
40 | { | |
41 | compositeId = newPosition; | |
42 | } | |
43 | ||
44 | unsigned short | |
45 | DelayId::pool() const | |
46 | { | |
47 | return pool_; | |
48 | } | |
49 | ||
50 | bool | |
51 | DelayId::operator == (DelayId const &rhs) const | |
52 | { | |
53 | /* Doesn't compare composites properly.... | |
26ac0430 | 54 | * only use to test against default ID's |
b67e2c8c | 55 | */ |
56 | return pool_ == rhs.pool_ && compositeId == rhs.compositeId; | |
57 | } | |
58 | ||
62e76326 | 59 | DelayId::operator bool() const |
b67e2c8c | 60 | { |
61 | return pool_ || compositeId.getRaw(); | |
62 | } | |
63 | ||
7ec8c6a2 | 64 | /* create a delay Id for a given request */ |
b67e2c8c | 65 | DelayId |
59a1efb2 | 66 | DelayId::DelayClient(ClientHttpRequest * http) |
b67e2c8c | 67 | { |
190154cf | 68 | HttpRequest *r; |
b67e2c8c | 69 | unsigned short pool; |
70 | assert(http); | |
71 | r = http->request; | |
72 | ||
4dd643d5 | 73 | if (r->client_addr.isNoAddr()) { |
cc192b50 | 74 | debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring"); |
62e76326 | 75 | return DelayId(); |
b67e2c8c | 76 | } |
77 | ||
95dc7ff4 | 78 | for (pool = 0; pool < DelayPools::pools(); ++pool) { |
b50e327b AJ |
79 | |
80 | /* pools require explicit 'allow' to assign a client into them */ | |
81 | if (!DelayPools::delay_data[pool].access) { | |
82 | debugs(77, DBG_IMPORTANT, "delay_pool " << pool << | |
83 | " has no delay_access configured. This means that no clients will ever use it."); | |
84 | continue; | |
85 | } | |
86 | ||
c0941a6a | 87 | ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL); |
3d674977 | 88 | #if FOLLOW_X_FORWARDED_FOR |
26ac0430 AJ |
89 | if (Config.onoff.delay_pool_uses_indirect_client) |
90 | ch.src_addr = r->indirect_client_addr; | |
91 | else | |
92 | #endif /* FOLLOW_X_FORWARDED_FOR */ | |
93 | ch.src_addr = r->client_addr; | |
7ec8c6a2 | 94 | ch.my_addr = r->my_addr; |
62e76326 | 95 | |
4d3a24ca | 96 | if (http->getConn() != NULL) |
a2ac85d9 | 97 | ch.conn(http->getConn()); |
62e76326 | 98 | |
2efeb0b7 | 99 | if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck() == ACCESS_ALLOWED) { |
b50e327b | 100 | |
62e76326 | 101 | DelayId result (pool + 1); |
1e5562e3 | 102 | CompositePoolNode::CompositeSelectionDetails details; |
103 | details.src_addr = ch.src_addr; | |
79fc6915 | 104 | #if USE_AUTH |
1e5562e3 | 105 | details.user = r->auth_user_request; |
79fc6915 | 106 | #endif |
1e5562e3 | 107 | details.tag = r->tag; |
108 | result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details)); | |
62e76326 | 109 | return result; |
110 | } | |
7ec8c6a2 | 111 | } |
112 | ||
b67e2c8c | 113 | return DelayId(); |
114 | } | |
115 | ||
a46d2c0e | 116 | void |
117 | DelayId::setNoDelay(bool const newValue) | |
118 | { | |
119 | markedAsNoDelay = newValue; | |
120 | } | |
121 | ||
b67e2c8c | 122 | /* |
123 | * this returns the number of bytes the client is permitted. it does not take | |
124 | * into account bytes already buffered - that is up to the caller. | |
125 | */ | |
126 | int | |
a748a390 | 127 | DelayId::bytesWanted(int minimum, int maximum) const |
b67e2c8c | 128 | { |
129 | /* unlimited */ | |
62e76326 | 130 | |
a46d2c0e | 131 | if (! (*this) || markedAsNoDelay) |
a748a390 | 132 | return max(minimum, maximum); |
62e76326 | 133 | |
b67e2c8c | 134 | /* limited */ |
a748a390 | 135 | int nbytes = max(minimum, maximum); |
62e76326 | 136 | |
4d3a24ca | 137 | if (compositeId != NULL) |
a748a390 | 138 | nbytes = compositeId->bytesWanted(minimum, nbytes); |
62e76326 | 139 | |
b67e2c8c | 140 | return nbytes; |
141 | } | |
142 | ||
143 | /* | |
2324cda2 | 144 | * this records actual bytes received. always recorded, even if the |
b67e2c8c | 145 | * class is disabled - it's more efficient to just do it than to do all |
146 | * the checks. | |
147 | */ | |
148 | void | |
149 | DelayId::bytesIn(int qty) | |
150 | { | |
151 | if (! (*this)) | |
62e76326 | 152 | return; |
b67e2c8c | 153 | |
a46d2c0e | 154 | if (markedAsNoDelay) |
155 | return; | |
156 | ||
e4a67a80 | 157 | assert ((unsigned short)(pool() - 1) != 0xFFFF); |
b67e2c8c | 158 | |
4d3a24ca | 159 | if (compositeId != NULL) |
62e76326 | 160 | compositeId->bytesIn(qty); |
b67e2c8c | 161 | } |
62e76326 | 162 | |
a46d2c0e | 163 | void |
164 | DelayId::delayRead(DeferredRead const &aRead) | |
165 | { | |
4d3a24ca | 166 | assert (compositeId != NULL); |
a46d2c0e | 167 | compositeId->delayRead(aRead); |
b67e2c8c | 168 | |
a46d2c0e | 169 | } |
454e8283 | 170 | |
9a0a18de | 171 | #endif /* USE_DELAY_POOLS */ |
f53969cc | 172 |