]> git.ipfire.org Git - thirdparty/squid.git/blob - src/helper.h
7d70316a078b092dbc7b197626c17e296056325e
[thirdparty/squid.git] / src / helper.h
1 /*
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.
21 *
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.
26 *
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-old.h"
37 #include "base/AsyncCall.h"
38 #include "cbdata.h"
39 #include "comm/forward.h"
40 #include "ip/Address.h"
41 #include "HelperChildConfig.h"
42
43 class helper_request;
44
45 typedef void HLPSCB(void *, void *lastserver, char *buf);
46
47 class helper
48 {
49 public:
50 inline helper(const char *name) : cmdline(NULL), id_name(name), eom('\n') {}
51 ~helper();
52
53 public:
54 wordlist *cmdline;
55 dlink_list servers;
56 dlink_list queue;
57 const char *id_name;
58 HelperChildConfig childs; ///< Configuration settings for number running.
59 int ipc_type;
60 Ip::Address addr;
61 time_t last_queue_warn;
62 time_t last_restart;
63 char eom; ///< The char which marks the end of (response) message, normally '\n'
64
65 struct _stats {
66 int requests;
67 int replies;
68 int queue_size;
69 int avg_svc_time;
70 } stats;
71
72 private:
73 CBDATA_CLASS2(helper);
74 };
75
76 class statefulhelper : public helper
77 {
78 public:
79 inline statefulhelper(const char *name) : helper(name) {};
80 inline ~statefulhelper() {};
81
82 public:
83 MemAllocator *datapool;
84 HLPSAVAIL *IsAvailable;
85 HLPSONEQ *OnEmptyQueue;
86
87 private:
88 CBDATA_CLASS2(statefulhelper);
89 };
90
91 /*
92 * Fields shared between stateless and stateful helper servers.
93 */
94 class HelperServerBase
95 {
96 public:
97 /** Closes pipes to the helper safely.
98 * Handles the case where the read and write pipes are the same FD.
99 */
100 void closePipesSafely();
101
102 /** Closes the reading pipe.
103 * If the read and write sockets are the same the write pipe will
104 * also be closed. Otherwise its left open for later handling.
105 */
106 void closeWritePipeSafely();
107
108 public:
109 int index;
110 int pid;
111 Ip::Address addr;
112 Comm::ConnectionPointer readPipe;
113 Comm::ConnectionPointer writePipe;
114 void *hIpc;
115
116 char *rbuf;
117 size_t rbuf_sz;
118 size_t roffset;
119
120 struct timeval dispatch_time;
121 struct timeval answer_time;
122
123 dlink_node link;
124
125 struct _helper_flags {
126 unsigned int busy:1;
127 unsigned int writing:1;
128 unsigned int closing:1;
129 unsigned int shutdown:1;
130 unsigned int reserved:1;
131 } flags;
132
133 };
134
135 class helper_server : public HelperServerBase
136 {
137 public:
138 MemBuf *wqueue;
139 MemBuf *writebuf;
140
141 helper *parent;
142 helper_request **requests;
143
144 struct {
145 int uses;
146 unsigned int pending;
147 } stats;
148
149 private:
150 CBDATA_CLASS2(helper_server);
151 };
152
153 class helper_stateful_request;
154
155 class helper_stateful_server : public HelperServerBase
156 {
157 public:
158 /* MemBuf wqueue; */
159 /* MemBuf writebuf; */
160
161 statefulhelper *parent;
162 helper_stateful_request *request;
163
164 struct {
165 int uses;
166 int submits;
167 int releases;
168 } stats;
169 void *data; /* State data used by the calling routines */
170
171 private:
172 CBDATA_CLASS2(helper_stateful_server);
173 };
174
175 class helper_request
176 {
177
178 public:
179 MEMPROXY_CLASS(helper_request);
180 char *buf;
181 HLPCB *callback;
182 void *data;
183
184 struct timeval dispatch_time;
185 };
186
187 MEMPROXY_CLASS_INLINE(helper_request);
188
189 class helper_stateful_request
190 {
191
192 public:
193 MEMPROXY_CLASS(helper_stateful_request);
194 char *buf;
195 HLPSCB *callback;
196 int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */
197 void *data;
198 };
199
200 MEMPROXY_CLASS_INLINE(helper_stateful_request);
201
202 /* helper.c */
203 SQUIDCEXTERN void helperOpenServers(helper * hlp);
204 SQUIDCEXTERN void helperStatefulOpenServers(statefulhelper * hlp);
205 SQUIDCEXTERN void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
206 SQUIDCEXTERN void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver);
207 SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL);
208 SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL);
209 SQUIDCEXTERN void helperShutdown(helper * hlp);
210 SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp);
211 SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv);
212 SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv);
213
214
215 #endif /* SQUID_HELPER_H */