DelaySpec.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 #if USE_DELAY_POOLS
14 #include "cache_cf.h"
15 #include "DelaySpec.h"
16 #include "Parsing.h"
17 #include "Store.h"
18 
19 DelaySpec::DelaySpec() : restore_bps(-1), max_bytes (-1)
20 {}
21 
22 void
23 DelaySpec::stats (StoreEntry * sentry, char const *label) const
24 {
25  if (restore_bps == -1) {
26  storeAppendPrintf(sentry, "\t%s:\n\t\tDisabled.\n\n", label);
27  return;
28  }
29 
30  storeAppendPrintf(sentry, "\t%s:\n", label);
31  storeAppendPrintf(sentry, "\t\tMax: %" PRId64 "\n", max_bytes);
32  storeAppendPrintf(sentry, "\t\tRestore: %d\n", restore_bps);
33 }
34 
35 void
37 {
38  storeAppendPrintf(entry, " %d/%" PRId64 "", restore_bps, max_bytes);
39 }
40 
41 void
43 {
44  // get the token.
45  char *token = ConfigParser::NextToken();
46  if (!token) {
47  self_destruct();
48  return;
49  }
50 
51  // no-limit value
52  if (strcmp(token, "none") == 0 || token[0] == '-') {
53  restore_bps = -1;
54  max_bytes = -1;
55  return;
56  }
57 
58  // parse the first digits into restore_bps
59  const char *p = nullptr;
60  if (!StringToInt(token, restore_bps, &p, 10) || *p != '/') {
61  debugs(77, DBG_CRITICAL, "ERROR: invalid delay rate '" << token << "'. Expecting restore/max or 'none'.");
62  self_destruct();
63  }
64  p++; // increment past the '/'
65 
66  // parse the rest into max_bytes
67  if (!StringToInt64(p, max_bytes, nullptr, 10)) {
68  debugs(77, DBG_CRITICAL, "ERROR: restore rate in '" << token << "' is not a number.");
69  self_destruct();
70  }
71 }
72 
73 #endif
74 
#define DBG_CRITICAL
Definition: Stream.h:37
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:855
void stats(StoreEntry *sentry, char const *) const
Definition: DelaySpec.cc:23
void self_destruct(void)
Definition: cache_cf.cc:276
void parse()
Definition: DelaySpec.cc:42
int restore_bps
Definition: DelaySpec.h:23
void dump(StoreEntry *) const
Definition: DelaySpec.cc:36
bool StringToInt(const char *s, int &result, const char **p, int base)
Definition: Parsing.cc:217
bool StringToInt64(const char *s, int64_t &result, const char **p, int base)
Definition: Parsing.cc:237
static char * NextToken()
#define PRId64
Definition: types.h:104
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
int64_t max_bytes
Definition: DelaySpec.h:24

 

Introduction

Documentation

Support

Miscellaneous