]> git.ipfire.org Git - thirdparty/squid.git/blame - src/helper/ChildConfig.cc
parserNG: add missing unit test for HTTP/0.9 case
[thirdparty/squid.git] / src / helper / ChildConfig.cc
CommitLineData
bbc27441
AJ
1/*
2 * Copyright (C) 1996-2014 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
f7f3304a 9#include "squid.h"
8a01b99e 10#include "cache_cf.h"
2eceb328 11#include "ConfigParser.h"
582c2af2 12#include "Debug.h"
48d54e4d 13#include "globals.h"
76d9b994 14#include "helper/ChildConfig.h"
54a063a2 15#include "Parsing.h"
48d54e4d 16
074d6a40 17#include <cstring>
48d54e4d 18
aca988c4
AJ
19Helper::ChildConfig::ChildConfig():
20 n_max(0),
21 n_startup(0),
22 n_idle(1),
23 concurrency(0),
24 n_running(0),
25 n_active(0)
26{}
27
76d9b994 28Helper::ChildConfig::ChildConfig(const unsigned int m):
48d54e4d 29 n_max(m),
0db33c21
AR
30 n_startup(0),
31 n_idle(1),
32 concurrency(0),
48d54e4d
AJ
33 n_running(0),
34 n_active(0)
35{}
36
76d9b994
AJ
37Helper::ChildConfig &
38Helper::ChildConfig::updateLimits(const Helper::ChildConfig &rhs)
1af735c7
AJ
39{
40 // Copy the limits only.
41 // Preserve the local state values (n_running and n_active)
42 n_max = rhs.n_max;
43 n_startup = rhs.n_startup;
44 n_idle = rhs.n_idle;
45 concurrency = rhs.concurrency;
48d54e4d
AJ
46 return *this;
47}
48
881c4733 49int
76d9b994 50Helper::ChildConfig::needNew() const
10044c9b 51{
48d54e4d
AJ
52 /* during the startup and reconfigure use our special amount... */
53 if (starting_up || reconfiguring) return n_startup;
54
55 /* keep a minimum of n_idle helpers free... */
56 if ( (n_active + n_idle) < n_max) return n_idle;
57
58 /* dont ever start more than n_max processes. */
59 return (n_max - n_active);
60}
61
62void
76d9b994 63Helper::ChildConfig::parseConfig()
48d54e4d 64{
2eceb328 65 char const *token = ConfigParser::NextToken();
48d54e4d
AJ
66
67 if (!token)
68 self_destruct();
69
70 /* starts with a bare number for the max... back-compatible */
54a063a2 71 n_max = xatoui(token);
48d54e4d 72
54a063a2
TX
73 if (n_max < 1) {
74 debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1.");
48d54e4d 75 self_destruct();
54a063a2 76 }
48d54e4d
AJ
77
78 /* Parse extension options */
2eceb328 79 for (; (token = ConfigParser::NextToken()) ;) {
48d54e4d 80 if (strncmp(token, "startup=", 8) == 0) {
54a063a2 81 n_startup = xatoui(token + 8);
48d54e4d 82 } else if (strncmp(token, "idle=", 5) == 0) {
54a063a2 83 n_idle = xatoui(token + 5);
48d54e4d 84 if (n_idle < 1) {
fa84c01d 85 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead.");
48d54e4d
AJ
86 n_idle = 1;
87 }
88 } else if (strncmp(token, "concurrency=", 12) == 0) {
54a063a2 89 concurrency = xatoui(token + 12);
48d54e4d 90 } else {
54a063a2 91 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << ".");
48d54e4d
AJ
92 self_destruct();
93 }
94 }
95
96 /* simple sanity. */
97
98 if (n_startup > n_max) {
fa84c01d 99 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")");
48d54e4d
AJ
100 n_startup = n_max;
101 }
102
103 if (n_idle > n_max) {
fa84c01d 104 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")");
48d54e4d
AJ
105 n_idle = n_max;
106 }
107}