]> git.ipfire.org Git - thirdparty/squid.git/blame - src/helper.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / helper.h
CommitLineData
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
37dedc58 36#include "base/AsyncCall.h"
aa839030 37#include "cbdata.h"
e0d28505 38#include "comm/forward.h"
582c2af2 39#include "dlink.h"
e0d28505 40#include "ip/Address.h"
48d54e4d 41#include "HelperChildConfig.h"
aa839030 42
43class helper_request;
44
dcb802aa 45typedef void HLPSCB(void *, void *lastserver, char *buf);
aa839030 46
10044c9b
A
47class helper
48{
48d54e4d 49public:
0af9303a 50 inline helper(const char *name) : cmdline(NULL), id_name(name), eom('\n') {}
48d54e4d
AJ
51 ~helper();
52
53public:
aa839030 54 wordlist *cmdline;
55 dlink_list servers;
56 dlink_list queue;
57 const char *id_name;
48d54e4d 58 HelperChildConfig childs; ///< Configuration settings for number running.
aa839030 59 int ipc_type;
b7ac5457 60 Ip::Address addr;
aa839030 61 time_t last_queue_warn;
62 time_t last_restart;
0af9303a 63 char eom; ///< The char which marks the end of (response) message, normally '\n'
aa839030 64
48d54e4d 65 struct _stats {
aa839030 66 int requests;
67 int replies;
68 int queue_size;
69 int avg_svc_time;
2fadd50d 70 } stats;
48d54e4d
AJ
71
72private:
73 CBDATA_CLASS2(helper);
aa839030 74};
75
10044c9b
A
76class statefulhelper : public helper
77{
48d54e4d
AJ
78public:
79 inline statefulhelper(const char *name) : helper(name) {};
80 inline ~statefulhelper() {};
81
82public:
a3efa961 83 MemAllocator *datapool;
aa839030 84 HLPSAVAIL *IsAvailable;
85 HLPSONEQ *OnEmptyQueue;
aa839030 86
48d54e4d
AJ
87private:
88 CBDATA_CLASS2(statefulhelper);
aa839030 89};
90
48d54e4d
AJ
91/*
92 * Fields shared between stateless and stateful helper servers.
93 */
10044c9b
A
94class HelperServerBase
95{
e0d28505
AJ
96public:
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
48d54e4d 108public:
aa839030 109 int index;
110 int pid;
b7ac5457 111 Ip::Address addr;
e0d28505
AJ
112 Comm::ConnectionPointer readPipe;
113 Comm::ConnectionPointer writePipe;
48d54e4d
AJ
114 void *hIpc;
115
aa839030 116 char *rbuf;
117 size_t rbuf_sz;
57d55dfa 118 size_t roffset;
aa839030 119
120 struct timeval dispatch_time;
aa839030 121 struct timeval answer_time;
122
123 dlink_node link;
e0d28505
AJ
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
48d54e4d
AJ
133};
134
582c2af2
FC
135class MemBuf;
136
10044c9b
A
137class helper_server : public HelperServerBase
138{
48d54e4d
AJ
139public:
140 MemBuf *wqueue;
141 MemBuf *writebuf;
142
aa839030 143 helper *parent;
144 helper_request **requests;
145
26ac0430 146 struct {
aa839030 147 int uses;
148 unsigned int pending;
3d0ac046 149 } stats;
37dedc58
AJ
150
151private:
152 CBDATA_CLASS2(helper_server);
aa839030 153};
154
155class helper_stateful_request;
156
10044c9b
A
157class helper_stateful_server : public HelperServerBase
158{
48d54e4d 159public:
aa839030 160 /* MemBuf wqueue; */
161 /* MemBuf writebuf; */
aa839030 162
aa839030 163 statefulhelper *parent;
164 helper_stateful_request *request;
165
26ac0430 166 struct {
aa839030 167 int uses;
168 int submits;
169 int releases;
3d0ac046 170 } stats;
aa839030 171 void *data; /* State data used by the calling routines */
37dedc58
AJ
172
173private:
174 CBDATA_CLASS2(helper_stateful_server);
aa839030 175};
51ee7c82 176
177class helper_request
178{
179
180public:
b001e822 181 MEMPROXY_CLASS(helper_request);
51ee7c82 182 char *buf;
183 HLPCB *callback;
184 void *data;
185
186 struct timeval dispatch_time;
51ee7c82 187};
188
d85b8894 189MEMPROXY_CLASS_INLINE(helper_request);
b001e822 190
51ee7c82 191class helper_stateful_request
192{
193
194public:
b001e822 195 MEMPROXY_CLASS(helper_stateful_request);
51ee7c82 196 char *buf;
197 HLPSCB *callback;
d20ce97d 198 int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */
51ee7c82 199 void *data;
51ee7c82 200};
201
d85b8894 202MEMPROXY_CLASS_INLINE(helper_stateful_request);
b001e822 203
aa839030 204/* helper.c */
205SQUIDCEXTERN void helperOpenServers(helper * hlp);
206SQUIDCEXTERN void helperStatefulOpenServers(statefulhelper * hlp);
207SQUIDCEXTERN void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
208SQUIDCEXTERN void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver);
9522b380 209SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL);
210SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL);
aa839030 211SQUIDCEXTERN void helperShutdown(helper * hlp);
212SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp);
aa839030 213SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv);
214SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv);
aa839030 215
51ee7c82 216#endif /* SQUID_HELPER_H */