]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelaySpec.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / DelaySpec.cc
CommitLineData
b67e2c8c 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 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
8a01b99e 14#include "cache_cf.h"
b67e2c8c 15#include "DelaySpec.h"
c8709c9f 16#include "Parsing.h"
582c2af2 17#include "Store.h"
b67e2c8c 18
19DelaySpec::DelaySpec() : restore_bps(-1), max_bytes (-1)
62e76326 20{}
b67e2c8c 21
22void
23DelaySpec::stats (StoreEntry * sentry, char const *label) const
24{
25 if (restore_bps == -1) {
62e76326 26 storeAppendPrintf(sentry, "\t%s:\n\t\tDisabled.\n\n", label);
27 return;
b67e2c8c 28 }
62e76326 29
b67e2c8c 30 storeAppendPrintf(sentry, "\t%s:\n", label);
c91ca3ce 31 storeAppendPrintf(sentry, "\t\tMax: %" PRId64 "\n", max_bytes);
b67e2c8c 32 storeAppendPrintf(sentry, "\t\tRestore: %d\n", restore_bps);
33}
34
35void
36DelaySpec::dump (StoreEntry *entry) const
37{
c91ca3ce 38 storeAppendPrintf(entry, " %d/%" PRId64 "", restore_bps, max_bytes);
b67e2c8c 39}
40
41void
42DelaySpec::parse()
43{
6e7502cc
AJ
44 // get the token.
45 char *token = ConfigParser::NextToken();
b67e2c8c 46 if (token == NULL)
62e76326 47 self_destruct();
48
6e7502cc
AJ
49 // no-limit value
50 if (strcmp(token, "none") == 0 || token[0] == '-') {
51 restore_bps = -1;
52 max_bytes = -1;
53 return;
54 }
62e76326 55
6e7502cc
AJ
56 // parse the first digits into restore_bps
57 const char *p = NULL;
58 if (!StringToInt(token, restore_bps, &p, 10) && *p != '/') {
59 debugs(77, DBG_CRITICAL, "ERROR: invalid delay rate '" << token << "'. Expecting restore/max or 'none'.");
60 self_destruct();
61 }
62 p++; // increment past the '/'
62e76326 63
6e7502cc
AJ
64 // parse the rest into max_bytes
65 if (!StringToInt64(p, max_bytes, NULL, 10)) {
66 debugs(77, DBG_CRITICAL, "ERROR: restore rate in '" << token << "' is not a number.");
67 self_destruct();
68 }
b67e2c8c 69}
62e76326 70
b67e2c8c 71#endif
f53969cc 72