source: squid-ssl/trunk/fuentes/src/DelayId.cc @ 5495

Last change on this file since 5495 was 5495, checked in by Juanma, 2 years ago

Initial release

File size: 4.1 KB
Line 
1/*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 77    Delay Pools */
10
11#include "squid.h"
12
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 */
16#if USE_DELAY_POOLS
17#include "acl/FilledChecklist.h"
18#include "client_side_request.h"
19#include "CommRead.h"
20#include "DelayId.h"
21#include "DelayPool.h"
22#include "DelayPools.h"
23#include "HttpRequest.h"
24#include "SquidConfig.h"
25
26DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
27{}
28
29DelayId::DelayId (unsigned short aPool) :
30    pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
31{
32    debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
33}
34
35DelayId::~DelayId ()
36{}
37
38void
39DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
40{
41    compositeId = newPosition;
42}
43
44unsigned short
45DelayId::pool() const
46{
47    return pool_;
48}
49
50bool
51DelayId::operator == (DelayId const &rhs) const
52{
53    /* Doesn't compare composites properly....
54     * only use to test against default ID's
55     */
56    return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
57}
58
59DelayId::operator bool() const
60{
61    return pool_ || compositeId.getRaw();
62}
63
64/* create a delay Id for a given request */
65DelayId
66DelayId::DelayClient(ClientHttpRequest * http)
67{
68    HttpRequest *r;
69    unsigned short pool;
70    assert(http);
71    r = http->request;
72
73    if (r->client_addr.isNoAddr()) {
74        debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
75        return DelayId();
76    }
77
78    for (pool = 0; pool < DelayPools::pools(); ++pool) {
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
87        ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL);
88#if FOLLOW_X_FORWARDED_FOR
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;
94        ch.my_addr = r->my_addr;
95
96        if (http->getConn() != NULL)
97            ch.conn(http->getConn());
98
99        if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck() == ACCESS_ALLOWED) {
100
101            DelayId result (pool + 1);
102            CompositePoolNode::CompositeSelectionDetails details;
103            details.src_addr = ch.src_addr;
104#if USE_AUTH
105            details.user = r->auth_user_request;
106#endif
107            details.tag = r->tag;
108            result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
109            return result;
110        }
111    }
112
113    return DelayId();
114}
115
116void
117DelayId::setNoDelay(bool const newValue)
118{
119    markedAsNoDelay = newValue;
120}
121
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 */
126int
127DelayId::bytesWanted(int minimum, int maximum) const
128{
129    /* unlimited */
130
131    if (! (*this) || markedAsNoDelay)
132        return max(minimum, maximum);
133
134    /* limited */
135    int nbytes = max(minimum, maximum);
136
137    if (compositeId != NULL)
138        nbytes = compositeId->bytesWanted(minimum, nbytes);
139
140    return nbytes;
141}
142
143/*
144 * this records actual bytes received.  always recorded, even if the
145 * class is disabled - it's more efficient to just do it than to do all
146 * the checks.
147 */
148void
149DelayId::bytesIn(int qty)
150{
151    if (! (*this))
152        return;
153
154    if (markedAsNoDelay)
155        return;
156
157    assert ((unsigned short)(pool() - 1) != 0xFFFF);
158
159    if (compositeId != NULL)
160        compositeId->bytesIn(qty);
161}
162
163void
164DelayId::delayRead(DeferredRead const &aRead)
165{
166    assert (compositeId != NULL);
167    compositeId->delayRead(aRead);
168
169}
170
171#endif /* USE_DELAY_POOLS */
172
Note: See TracBrowser for help on using the repository browser.