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