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