]>
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" |
9837e5f0 | 38 | #include "ip/IpAddress.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; |
ad61a2b4 | 62 | IpAddress 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; |
48d54e4d AJ |
72 | |
73 | private: | |
74 | CBDATA_CLASS2(helper); | |
aa839030 | 75 | }; |
76 | ||
10044c9b A |
77 | class statefulhelper : public helper |
78 | { | |
48d54e4d AJ |
79 | public: |
80 | inline statefulhelper(const char *name) : helper(name) {}; | |
81 | inline ~statefulhelper() {}; | |
82 | ||
83 | public: | |
a3efa961 | 84 | MemAllocator *datapool; |
aa839030 | 85 | HLPSAVAIL *IsAvailable; |
86 | HLPSONEQ *OnEmptyQueue; | |
aa839030 | 87 | |
48d54e4d AJ |
88 | private: |
89 | CBDATA_CLASS2(statefulhelper); | |
aa839030 | 90 | }; |
91 | ||
48d54e4d AJ |
92 | /* |
93 | * Fields shared between stateless and stateful helper servers. | |
94 | */ | |
10044c9b A |
95 | class HelperServerBase |
96 | { | |
48d54e4d | 97 | public: |
aa839030 | 98 | int index; |
99 | int pid; | |
ad61a2b4 | 100 | IpAddress addr; |
aa839030 | 101 | int rfd; |
102 | int wfd; | |
48d54e4d AJ |
103 | void *hIpc; |
104 | ||
aa839030 | 105 | char *rbuf; |
106 | size_t rbuf_sz; | |
57d55dfa | 107 | size_t roffset; |
aa839030 | 108 | |
109 | struct timeval dispatch_time; | |
aa839030 | 110 | struct timeval answer_time; |
111 | ||
112 | dlink_node link; | |
48d54e4d AJ |
113 | }; |
114 | ||
10044c9b A |
115 | class helper_server : public HelperServerBase |
116 | { | |
48d54e4d AJ |
117 | public: |
118 | MemBuf *wqueue; | |
119 | MemBuf *writebuf; | |
120 | ||
aa839030 | 121 | helper *parent; |
122 | helper_request **requests; | |
123 | ||
26ac0430 | 124 | struct _helper_flags { |
3d0ac046 HN |
125 | unsigned int writing:1; |
126 | unsigned int closing:1; | |
127 | unsigned int shutdown:1; | |
128 | } flags; | |
aa839030 | 129 | |
26ac0430 | 130 | struct { |
aa839030 | 131 | int uses; |
132 | unsigned int pending; | |
3d0ac046 | 133 | } stats; |
aa839030 | 134 | }; |
135 | ||
136 | class helper_stateful_request; | |
137 | ||
10044c9b A |
138 | class helper_stateful_server : public HelperServerBase |
139 | { | |
48d54e4d | 140 | public: |
aa839030 | 141 | /* MemBuf wqueue; */ |
142 | /* MemBuf writebuf; */ | |
aa839030 | 143 | |
aa839030 | 144 | statefulhelper *parent; |
145 | helper_stateful_request *request; | |
146 | ||
26ac0430 | 147 | struct _helper_stateful_flags { |
3d0ac046 HN |
148 | unsigned int busy:1; |
149 | unsigned int closing:1; | |
150 | unsigned int shutdown:1; | |
360d26ea | 151 | unsigned int reserved:1; |
3d0ac046 | 152 | } flags; |
aa839030 | 153 | |
26ac0430 | 154 | struct { |
aa839030 | 155 | int uses; |
156 | int submits; | |
157 | int releases; | |
3d0ac046 | 158 | } stats; |
aa839030 | 159 | void *data; /* State data used by the calling routines */ |
160 | }; | |
51ee7c82 | 161 | |
162 | class helper_request | |
163 | { | |
164 | ||
165 | public: | |
b001e822 | 166 | MEMPROXY_CLASS(helper_request); |
51ee7c82 | 167 | char *buf; |
168 | HLPCB *callback; | |
169 | void *data; | |
170 | ||
171 | struct timeval dispatch_time; | |
51ee7c82 | 172 | }; |
173 | ||
d85b8894 | 174 | MEMPROXY_CLASS_INLINE(helper_request); |
b001e822 | 175 | |
51ee7c82 | 176 | class helper_stateful_request |
177 | { | |
178 | ||
179 | public: | |
b001e822 | 180 | MEMPROXY_CLASS(helper_stateful_request); |
51ee7c82 | 181 | char *buf; |
182 | HLPSCB *callback; | |
d20ce97d | 183 | int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */ |
51ee7c82 | 184 | void *data; |
51ee7c82 | 185 | }; |
186 | ||
d85b8894 | 187 | MEMPROXY_CLASS_INLINE(helper_stateful_request); |
b001e822 | 188 | |
aa839030 | 189 | /* helper.c */ |
190 | SQUIDCEXTERN void helperOpenServers(helper * hlp); | |
191 | SQUIDCEXTERN void helperStatefulOpenServers(statefulhelper * hlp); | |
192 | SQUIDCEXTERN void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data); | |
193 | SQUIDCEXTERN void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver); | |
9522b380 | 194 | SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL); |
195 | SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL); | |
aa839030 | 196 | SQUIDCEXTERN void helperShutdown(helper * hlp); |
197 | SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp); | |
aa839030 | 198 | SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv); |
199 | SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv); | |
aa839030 | 200 | |
201 | ||
51ee7c82 | 202 | #endif /* SQUID_HELPER_H */ |