DelayId.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "http/Stream.h"
24 #include "HttpRequest.h"
25 #include "SquidConfig.h"
26 
27 DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
28 {}
29 
30 DelayId::DelayId (unsigned short aPool) :
31  pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
32 {
33  debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
34 }
35 
37 {}
38 
39 void
41 {
42  compositeId = newPosition;
43 }
44 
45 unsigned short
47 {
48  return pool_;
49 }
50 
51 bool
52 DelayId::operator == (DelayId const &rhs) const
53 {
54  /* Doesn't compare composites properly....
55  * only use to test against default ID's
56  */
57  return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
58 }
59 
60 DelayId::operator bool() const
61 {
62  return pool_ || compositeId.getRaw();
63 }
64 
65 /* create a delay Id for a given request */
66 DelayId
68 {
69  HttpRequest *r;
70  unsigned short pool;
71  assert(http);
72  r = http->request;
73 
74  if (r->client_addr.isNoAddr()) {
75  debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
76  return DelayId();
77  }
78 
79  for (pool = 0; pool < DelayPools::pools(); ++pool) {
80 
81  /* pools require explicit 'allow' to assign a client into them */
82  if (!DelayPools::delay_data[pool].access) {
83  debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
84  " has no delay_access configured. This means that no clients will ever use it.");
85  continue;
86  }
87 
88  ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL);
89  if (reply) {
90  ch.reply = reply;
91  HTTPMSGLOCK(reply);
92  }
93 #if FOLLOW_X_FORWARDED_FOR
96  else
97 #endif /* FOLLOW_X_FORWARDED_FOR */
98  ch.src_addr = r->client_addr;
99  ch.my_addr = r->my_addr;
100 
101  if (http->getConn() != NULL)
102  ch.conn(http->getConn());
103 
104  if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) {
105 
106  DelayId result (pool + 1);
108  details.src_addr = ch.src_addr;
109 #if USE_AUTH
110  details.user = r->auth_user_request;
111 #endif
112  details.tag = r->tag;
113  result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
114  return result;
115  }
116  }
117 
118  return DelayId();
119 }
120 
121 void
122 DelayId::setNoDelay(bool const newValue)
123 {
124  markedAsNoDelay = newValue;
125 }
126 
127 /*
128  * this returns the number of bytes the client is permitted. it does not take
129  * into account bytes already buffered - that is up to the caller.
130  */
131 int
132 DelayId::bytesWanted(int minimum, int maximum) const
133 {
134  /* unlimited */
135 
136  if (! (*this) || markedAsNoDelay)
137  return max(minimum, maximum);
138 
139  /* limited */
140  int nbytes = max(minimum, maximum);
141 
142  if (compositeId != NULL)
143  nbytes = compositeId->bytesWanted(minimum, nbytes);
144 
145  return nbytes;
146 }
147 
148 /*
149  * this records actual bytes received. always recorded, even if the
150  * class is disabled - it's more efficient to just do it than to do all
151  * the checks.
152  */
153 void
155 {
156  if (! (*this))
157  return;
158 
159  if (markedAsNoDelay)
160  return;
161 
162  assert ((unsigned short)(pool() - 1) != 0xFFFF);
163 
164  if (compositeId != NULL)
165  compositeId->bytesIn(qty);
166 }
167 
168 void
170 {
171  assert (compositeId != NULL);
172  compositeId->delayRead(aRead);
173 
174 }
175 
176 #endif /* USE_DELAY_POOLS */
177 
unsigned short pool_
Definition: DelayId.h:40
#define assert(EX)
Definition: assert.h:17
Ip::Address my_addr
Definition: HttpRequest.h:143
ConnStateData * getConn() const
DelayIdComposite::Pointer compositeId
Definition: DelayId.h:41
bool markedAsNoDelay
Definition: DelayId.h:42
unsigned short pool() const
Definition: DelayId.cc:46
Ip::Address src_addr
bool isNoAddr() const
Definition: Address.cc:277
static unsigned short pools()
Definition: delay_pools.cc:564
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:154
static DelayPool * delay_data
Definition: DelayPools.h:46
A const & max(A const &lhs, A const &rhs)
ConnStateData * conn() const
The client connection manager.
void delayRead(DeferredRead const &)
Definition: DelayId.cc:169
void setNoDelay(bool const)
Definition: DelayId.cc:122
virtual void delayRead(DeferredRead const &)
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
#define DBG_IMPORTANT
Definition: Debug.h:45
Ip::Address client_addr
Definition: HttpRequest.h:137
String tag
Definition: HttpRequest.h:165
int delay_pool_uses_indirect_client
Definition: SquidConfig.h:327
bool allowed() const
Definition: Acl.h:141
DelayId()
Definition: DelayId.cc:27
struct SquidConfig::@112 onoff
bool operator==(DelayId const &rhs) const
Definition: DelayId.cc:52
allow_t const & fastCheck()
Definition: Checklist.cc:336
virtual int bytesWanted(int min, int max) const =0
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:115
DelayIdComposite::Pointer compositePosition()
void bytesIn(int qty)
Definition: DelayId.cc:154
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:67
Ip::Address indirect_client_addr
Definition: HttpRequest.h:140
~DelayId()
Definition: DelayId.cc:36
C * getRaw() const
Definition: RefCount.h:74
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
virtual void bytesIn(int qty)=0
#define false
Definition: GnuRegex.c:233
int bytesWanted(int min, int max) const
Definition: DelayId.cc:132

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors