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