]>
Commit | Line | Data |
---|---|---|
51ee7c82 | 1 | /* |
51ee7c82 | 2 | * DEBUG: section 84 Helper process maintenance |
3 | * AUTHOR: Harvest Derived? | |
4 | * | |
5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
6 | * ---------------------------------------------------------- | |
7 | * | |
8 | * Squid is the result of efforts by numerous individuals from | |
9 | * the Internet community; see the CONTRIBUTORS file for full | |
10 | * details. Many organizations have provided support for Squid's | |
11 | * development; see the SPONSORS file for full details. Squid is | |
12 | * Copyrighted (C) 2001 by the Regents of the University of | |
13 | * California; see the COPYRIGHT file for full details. Squid | |
14 | * incorporates software developed and/or copyrighted by other | |
15 | * sources; see the CREDITS file for full details. | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
26ac0430 | 21 | * |
51ee7c82 | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26ac0430 | 26 | * |
51ee7c82 | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
30 | * | |
31 | */ | |
32 | ||
33 | #ifndef SQUID_HELPER_H | |
34 | #define SQUID_HELPER_H | |
35 | ||
36 | #include "squid.h" | |
aa839030 | 37 | #include "cbdata.h" |
96d89ea0 | 38 | #include "ip/Address.h" |
48d54e4d | 39 | #include "HelperChildConfig.h" |
aa839030 | 40 | |
41 | class helper_request; | |
42 | ||
aa839030 | 43 | typedef struct _helper_flags helper_flags; |
44 | ||
45 | typedef struct _helper_stateful_flags helper_stateful_flags; | |
46 | ||
dcb802aa | 47 | typedef void HLPSCB(void *, void *lastserver, char *buf); |
aa839030 | 48 | |
10044c9b A |
49 | class helper |
50 | { | |
48d54e4d AJ |
51 | public: |
52 | inline helper(const char *name) : cmdline(NULL), id_name(name) {}; | |
53 | ~helper(); | |
54 | ||
55 | public: | |
aa839030 | 56 | wordlist *cmdline; |
57 | dlink_list servers; | |
58 | dlink_list queue; | |
59 | const char *id_name; | |
48d54e4d | 60 | HelperChildConfig childs; ///< Configuration settings for number running. |
aa839030 | 61 | int ipc_type; |
b7ac5457 | 62 | Ip::Address addr; |
aa839030 | 63 | time_t last_queue_warn; |
64 | time_t last_restart; | |
65 | ||
48d54e4d | 66 | struct _stats { |
aa839030 | 67 | int requests; |
68 | int replies; | |
69 | int queue_size; | |
70 | int avg_svc_time; | |
2fadd50d | 71 | } stats; |
95d2589c CT |
72 | /// True if callback expects the whole helper output, as a c-string. |
73 | bool return_full_reply; | |
48d54e4d AJ |
74 | |
75 | private: | |
76 | CBDATA_CLASS2(helper); | |
aa839030 | 77 | }; |
78 | ||
10044c9b A |
79 | class statefulhelper : public helper |
80 | { | |
48d54e4d AJ |
81 | public: |
82 | inline statefulhelper(const char *name) : helper(name) {}; | |
83 | inline ~statefulhelper() {}; | |
84 | ||
85 | public: | |
a3efa961 | 86 | MemAllocator *datapool; |
aa839030 | 87 | HLPSAVAIL *IsAvailable; |
88 | HLPSONEQ *OnEmptyQueue; | |
aa839030 | 89 | |
48d54e4d AJ |
90 | private: |
91 | CBDATA_CLASS2(statefulhelper); | |
aa839030 | 92 | }; |
93 | ||
48d54e4d AJ |
94 | /* |
95 | * Fields shared between stateless and stateful helper servers. | |
96 | */ | |
10044c9b A |
97 | class HelperServerBase |
98 | { | |
48d54e4d | 99 | public: |
aa839030 | 100 | int index; |
101 | int pid; | |
b7ac5457 | 102 | Ip::Address addr; |
aa839030 | 103 | int rfd; |
104 | int wfd; | |
48d54e4d AJ |
105 | void *hIpc; |
106 | ||
aa839030 | 107 | char *rbuf; |
108 | size_t rbuf_sz; | |
57d55dfa | 109 | size_t roffset; |
aa839030 | 110 | |
111 | struct timeval dispatch_time; | |
aa839030 | 112 | struct timeval answer_time; |
113 | ||
114 | dlink_node link; | |
48d54e4d AJ |
115 | }; |
116 | ||
10044c9b A |
117 | class helper_server : public HelperServerBase |
118 | { | |
48d54e4d AJ |
119 | public: |
120 | MemBuf *wqueue; | |
121 | MemBuf *writebuf; | |
122 | ||
aa839030 | 123 | helper *parent; |
124 | helper_request **requests; | |
125 | ||
26ac0430 | 126 | struct _helper_flags { |
3d0ac046 HN |
127 | unsigned int writing:1; |
128 | unsigned int closing:1; | |
129 | unsigned int shutdown:1; | |
130 | } flags; | |
aa839030 | 131 | |
26ac0430 | 132 | struct { |
aa839030 | 133 | int uses; |
134 | unsigned int pending; | |
3d0ac046 | 135 | } stats; |
aa839030 | 136 | }; |
137 | ||
138 | class helper_stateful_request; | |
139 | ||
10044c9b A |
140 | class helper_stateful_server : public HelperServerBase |
141 | { | |
48d54e4d | 142 | public: |
aa839030 | 143 | /* MemBuf wqueue; */ |
144 | /* MemBuf writebuf; */ | |
aa839030 | 145 | |
aa839030 | 146 | statefulhelper *parent; |
147 | helper_stateful_request *request; | |
148 | ||
26ac0430 | 149 | struct _helper_stateful_flags { |
3d0ac046 HN |
150 | unsigned int busy:1; |
151 | unsigned int closing:1; | |
152 | unsigned int shutdown:1; | |
360d26ea | 153 | unsigned int reserved:1; |
3d0ac046 | 154 | } flags; |
aa839030 | 155 | |
26ac0430 | 156 | struct { |
aa839030 | 157 | int uses; |
158 | int submits; | |
159 | int releases; | |
3d0ac046 | 160 | } stats; |
aa839030 | 161 | void *data; /* State data used by the calling routines */ |
162 | }; | |
51ee7c82 | 163 | |
164 | class helper_request | |
165 | { | |
166 | ||
167 | public: | |
b001e822 | 168 | MEMPROXY_CLASS(helper_request); |
51ee7c82 | 169 | char *buf; |
170 | HLPCB *callback; | |
171 | void *data; | |
172 | ||
173 | struct timeval dispatch_time; | |
51ee7c82 | 174 | }; |
175 | ||
d85b8894 | 176 | MEMPROXY_CLASS_INLINE(helper_request); |
b001e822 | 177 | |
51ee7c82 | 178 | class helper_stateful_request |
179 | { | |
180 | ||
181 | public: | |
b001e822 | 182 | MEMPROXY_CLASS(helper_stateful_request); |
51ee7c82 | 183 | char *buf; |
184 | HLPSCB *callback; | |
d20ce97d | 185 | int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */ |
51ee7c82 | 186 | void *data; |
51ee7c82 | 187 | }; |
188 | ||
d85b8894 | 189 | MEMPROXY_CLASS_INLINE(helper_stateful_request); |
b001e822 | 190 | |
aa839030 | 191 | /* helper.c */ |
192 | SQUIDCEXTERN void helperOpenServers(helper * hlp); | |
193 | SQUIDCEXTERN void helperStatefulOpenServers(statefulhelper * hlp); | |
194 | SQUIDCEXTERN void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data); | |
195 | SQUIDCEXTERN void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver); | |
9522b380 | 196 | SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL); |
197 | SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL); | |
aa839030 | 198 | SQUIDCEXTERN void helperShutdown(helper * hlp); |
199 | SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp); | |
aa839030 | 200 | SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv); |
201 | SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv); | |
aa839030 | 202 | |
203 | ||
51ee7c82 | 204 | #endif /* SQUID_HELPER_H */ |