]>
Commit | Line | Data |
---|---|---|
51ee7c82 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
51ee7c82 | 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. | |
51ee7c82 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 84 Helper process maintenance */ |
10 | ||
51ee7c82 | 11 | #ifndef SQUID_HELPER_H |
12 | #define SQUID_HELPER_H | |
13 | ||
37dedc58 | 14 | #include "base/AsyncCall.h" |
e237d339 | 15 | #include "base/InstanceId.h" |
aa839030 | 16 | #include "cbdata.h" |
e0d28505 | 17 | #include "comm/forward.h" |
582c2af2 | 18 | #include "dlink.h" |
24438ec5 | 19 | #include "helper/forward.h" |
48d54e4d | 20 | #include "HelperChildConfig.h" |
602d9612 | 21 | #include "ip/Address.h" |
aa839030 | 22 | |
10044c9b A |
23 | class helper |
24 | { | |
48d54e4d | 25 | public: |
c8347c53 AJ |
26 | inline helper(const char *name) : |
27 | cmdline(NULL), | |
28 | id_name(name), | |
29 | ipc_type(0), | |
30 | last_queue_warn(0), | |
31 | last_restart(0), | |
32 | eom('\n') { | |
33 | memset(&stats, 0, sizeof(stats)); | |
34 | } | |
48d54e4d AJ |
35 | ~helper(); |
36 | ||
37 | public: | |
aa839030 | 38 | wordlist *cmdline; |
39 | dlink_list servers; | |
40 | dlink_list queue; | |
41 | const char *id_name; | |
48d54e4d | 42 | HelperChildConfig childs; ///< Configuration settings for number running. |
aa839030 | 43 | int ipc_type; |
b7ac5457 | 44 | Ip::Address addr; |
aa839030 | 45 | time_t last_queue_warn; |
46 | time_t last_restart; | |
0af9303a | 47 | char eom; ///< The char which marks the end of (response) message, normally '\n' |
aa839030 | 48 | |
48d54e4d | 49 | struct _stats { |
aa839030 | 50 | int requests; |
51 | int replies; | |
52 | int queue_size; | |
53 | int avg_svc_time; | |
2fadd50d | 54 | } stats; |
48d54e4d AJ |
55 | |
56 | private: | |
57 | CBDATA_CLASS2(helper); | |
aa839030 | 58 | }; |
59 | ||
10044c9b A |
60 | class statefulhelper : public helper |
61 | { | |
48d54e4d | 62 | public: |
c8347c53 | 63 | inline statefulhelper(const char *name) : helper(name), datapool(NULL), IsAvailable(NULL), OnEmptyQueue(NULL) {}; |
48d54e4d AJ |
64 | inline ~statefulhelper() {}; |
65 | ||
66 | public: | |
a3efa961 | 67 | MemAllocator *datapool; |
aa839030 | 68 | HLPSAVAIL *IsAvailable; |
69 | HLPSONEQ *OnEmptyQueue; | |
aa839030 | 70 | |
48d54e4d AJ |
71 | private: |
72 | CBDATA_CLASS2(statefulhelper); | |
aa839030 | 73 | }; |
74 | ||
1f7ba0b4 | 75 | /** |
48d54e4d AJ |
76 | * Fields shared between stateless and stateful helper servers. |
77 | */ | |
10044c9b A |
78 | class HelperServerBase |
79 | { | |
e0d28505 AJ |
80 | public: |
81 | /** Closes pipes to the helper safely. | |
82 | * Handles the case where the read and write pipes are the same FD. | |
41060bef AJ |
83 | * |
84 | * \param name displayed for the helper being shutdown if logging an error | |
e0d28505 | 85 | */ |
41060bef | 86 | void closePipesSafely(const char *name); |
e0d28505 AJ |
87 | |
88 | /** Closes the reading pipe. | |
89 | * If the read and write sockets are the same the write pipe will | |
90 | * also be closed. Otherwise its left open for later handling. | |
41060bef AJ |
91 | * |
92 | * \param name displayed for the helper being shutdown if logging an error | |
e0d28505 | 93 | */ |
41060bef | 94 | void closeWritePipeSafely(const char *name); |
e0d28505 | 95 | |
48d54e4d | 96 | public: |
e237d339 AJ |
97 | /// Helper program identifier; does not change when contents do, |
98 | /// including during assignment | |
99 | const InstanceId<HelperServerBase> index; | |
aa839030 | 100 | int pid; |
b7ac5457 | 101 | Ip::Address addr; |
e0d28505 AJ |
102 | Comm::ConnectionPointer readPipe; |
103 | Comm::ConnectionPointer writePipe; | |
48d54e4d AJ |
104 | void *hIpc; |
105 | ||
aa839030 | 106 | char *rbuf; |
107 | size_t rbuf_sz; | |
57d55dfa | 108 | size_t roffset; |
aa839030 | 109 | |
110 | struct timeval dispatch_time; | |
aa839030 | 111 | struct timeval answer_time; |
112 | ||
113 | dlink_node link; | |
e0d28505 AJ |
114 | |
115 | struct _helper_flags { | |
be4d35dc FC |
116 | bool writing; |
117 | bool closing; | |
118 | bool shutdown; | |
119 | bool reserved; | |
e0d28505 AJ |
120 | } flags; |
121 | ||
1f7ba0b4 AJ |
122 | struct { |
123 | uint64_t uses; //< requests sent to this helper | |
124 | uint64_t replies; //< replies received from this helper | |
125 | uint64_t pending; //< queued lookups waiting to be sent to this helper | |
126 | uint64_t releases; //< times release() has been called on this helper (if stateful) | |
127 | } stats; | |
128 | void initStats(); | |
48d54e4d AJ |
129 | }; |
130 | ||
582c2af2 FC |
131 | class MemBuf; |
132 | ||
10044c9b A |
133 | class helper_server : public HelperServerBase |
134 | { | |
48d54e4d AJ |
135 | public: |
136 | MemBuf *wqueue; | |
137 | MemBuf *writebuf; | |
138 | ||
aa839030 | 139 | helper *parent; |
24438ec5 | 140 | Helper::Request **requests; |
aa839030 | 141 | |
37dedc58 AJ |
142 | private: |
143 | CBDATA_CLASS2(helper_server); | |
aa839030 | 144 | }; |
145 | ||
10044c9b A |
146 | class helper_stateful_server : public HelperServerBase |
147 | { | |
48d54e4d | 148 | public: |
aa839030 | 149 | /* MemBuf wqueue; */ |
150 | /* MemBuf writebuf; */ | |
aa839030 | 151 | |
aa839030 | 152 | statefulhelper *parent; |
24438ec5 | 153 | Helper::Request *request; |
aa839030 | 154 | |
aa839030 | 155 | void *data; /* State data used by the calling routines */ |
37dedc58 AJ |
156 | |
157 | private: | |
158 | CBDATA_CLASS2(helper_stateful_server); | |
aa839030 | 159 | }; |
51ee7c82 | 160 | |
aa839030 | 161 | /* helper.c */ |
d9c252f2 FC |
162 | void helperOpenServers(helper * hlp); |
163 | void helperStatefulOpenServers(statefulhelper * hlp); | |
164 | void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data); | |
e166785a | 165 | void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPCB * callback, void *data, helper_stateful_server * lastserver); |
d9c252f2 FC |
166 | void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL); |
167 | void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL); | |
168 | void helperShutdown(helper * hlp); | |
169 | void helperStatefulShutdown(statefulhelper * hlp); | |
170 | void helperStatefulReleaseServer(helper_stateful_server * srv); | |
171 | void *helperStatefulServerGetData(helper_stateful_server * srv); | |
aa839030 | 172 | |
51ee7c82 | 173 | #endif /* SQUID_HELPER_H */ |