]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Kids.cc
Better reporting of REQMOD failures during body processing.
[thirdparty/squid.git] / src / ipc / Kids.cc
CommitLineData
40daaeb8
AR
1/*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8#include "config.h"
9#include "ipc/Kids.h"
10
11Kids TheKids;
9de6c973 12KidName TheKidName;
40daaeb8
AR
13
14Kids::Kids()
15{
16}
17
18/// maintain n kids
19void Kids::init(size_t n)
20{
21 assert(n > 0);
22
23 if (storage.size() > 0)
24 storage.clean();
25
26 storage.reserve(n);
27
10cefb7b 28 char kid_name[32];
ba568924
AR
29
30 // add Kid records for all n main strands
40daaeb8 31 for (size_t i = 1; i <= n; ++i) {
40daaeb8
AR
32 snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)i);
33 storage.push_back(Kid(kid_name));
34 }
10cefb7b 35
ba568924 36 // if coordination is needed, add a Kid record for Coordinator
10cefb7b 37 if (n > 1) {
38 snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(n + 1));
39 storage.push_back(Kid(kid_name));
40 }
40daaeb8
AR
41}
42
43/// returns kid by pid
44Kid* Kids::find(pid_t pid)
45{
46 assert(pid > 0);
47 assert(count() > 0);
48
49 for (size_t i = 0; i < storage.size(); ++i) {
50 if (storage[i].getPid() == pid)
51 return &storage[i];
52 }
53 return NULL;
54}
55
56/// returns the kid by index, useful for kids iteration
57Kid& Kids::get(size_t i)
58{
1dc746da 59 assert(i < count());
40daaeb8
AR
60 return storage[i];
61}
62
63/// whether all kids are hopeless
64bool Kids::allHopeless() const
65{
66 for (size_t i = 0; i < storage.size(); ++i) {
67 if (!storage[i].hopeless())
68 return false;
69 }
70 return true;
71}
72
73/// whether all kids called exited happy
74bool Kids::allExitedHappy() const
75{
76 for (size_t i = 0; i < storage.size(); ++i) {
77 if (!storage[i].exitedHappy())
78 return false;
79 }
80 return true;
81}
82
83/// whether all kids died from a given signal
84bool Kids::allSignaled(int sgnl) const
85{
86 for (size_t i = 0; i < storage.size(); ++i) {
87 if (!storage[i].signaled(sgnl))
88 return false;
89 }
90 return true;
91}
92
93/// returns the number of kids
94size_t Kids::count() const
95{
96 return storage.size();
97}