]> git.ipfire.org Git - thirdparty/squid.git/blob - src/helper.h
Author: Francesco Chemolli <kinkie@squid-cache.org>
[thirdparty/squid.git] / src / helper.h
1
2 /*
3 * $Id: helper.h,v 1.12 2008/02/26 21:49:34 amosjeffries Exp $
4 *
5 * DEBUG: section 84 Helper process maintenance
6 * AUTHOR: Harvest Derived?
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #ifndef SQUID_HELPER_H
37 #define SQUID_HELPER_H
38
39 #include "squid.h"
40 #include "cbdata.h"
41 #include "IPAddress.h"
42
43 class helper_request;
44
45 typedef struct _helper helper;
46
47 typedef struct _helper_stateful statefulhelper;
48
49 typedef struct _helper_server helper_server;
50
51 typedef struct _helper_stateful_server helper_stateful_server;
52
53 typedef struct _helper_flags helper_flags;
54
55 typedef struct _helper_stateful_flags helper_stateful_flags;
56
57 typedef stateful_helper_callback_t HLPSCB(void *, void *lastserver, char *buf);
58
59 struct _helper {
60 wordlist *cmdline;
61 dlink_list servers;
62 dlink_list queue;
63 const char *id_name;
64 int n_to_start;
65 int n_running;
66 int n_active;
67 int ipc_type;
68 IPAddress addr;
69 unsigned int concurrency;
70 time_t last_queue_warn;
71 time_t last_restart;
72
73 struct {
74 int requests;
75 int replies;
76 int queue_size;
77 int avg_svc_time;
78 } stats;
79 };
80
81 struct _helper_stateful {
82 wordlist *cmdline;
83 dlink_list servers;
84 dlink_list queue;
85 const char *id_name;
86 int n_to_start;
87 int n_running;
88 int n_active;
89 int ipc_type;
90 IPAddress addr;
91 MemAllocator *datapool;
92 HLPSAVAIL *IsAvailable;
93 HLPSONEQ *OnEmptyQueue;
94 time_t last_queue_warn;
95 time_t last_restart;
96
97 struct {
98 int requests;
99 int replies;
100 int queue_size;
101 int avg_svc_time;
102 } stats;
103 };
104
105 struct _helper_server {
106 int index;
107 int pid;
108 IPAddress addr;
109 int rfd;
110 int wfd;
111 MemBuf *wqueue;
112 MemBuf *writebuf;
113 char *rbuf;
114 size_t rbuf_sz;
115 size_t roffset;
116
117 struct timeval dispatch_time;
118
119 struct timeval answer_time;
120
121 dlink_node link;
122 helper *parent;
123 helper_request **requests;
124
125 struct _helper_flags {
126 unsigned int writing:1;
127 unsigned int closing:1;
128 unsigned int shutdown:1;
129 } flags;
130
131 struct {
132 int uses;
133 unsigned int pending;
134 } stats;
135
136 void *hIpc;
137 };
138
139 class helper_stateful_request;
140
141 struct _helper_stateful_server {
142 int index;
143 int pid;
144 IPAddress addr;
145 int rfd;
146 int wfd;
147 /* MemBuf wqueue; */
148 /* MemBuf writebuf; */
149 char *rbuf;
150 size_t rbuf_sz;
151 size_t roffset;
152
153 struct timeval dispatch_time;
154
155 struct timeval answer_time;
156
157 dlink_node link;
158 dlink_list queue;
159 statefulhelper *parent;
160 helper_stateful_request *request;
161
162 struct _helper_stateful_flags {
163 unsigned int busy:1;
164 unsigned int closing:1;
165 unsigned int shutdown:1;
166 stateful_helper_reserve_t reserved;
167 } flags;
168
169 struct {
170 int uses;
171 int submits;
172 int releases;
173 int deferbyfunc;
174 int deferbycb;
175 } stats;
176 int deferred_requests; /* current number of deferred requests */
177 void *data; /* State data used by the calling routines */
178 void *hIpc;
179 };
180
181 class helper_request
182 {
183
184 public:
185 MEMPROXY_CLASS(helper_request);
186 char *buf;
187 HLPCB *callback;
188 void *data;
189
190 struct timeval dispatch_time;
191 };
192
193 MEMPROXY_CLASS_INLINE(helper_request) /**DOCS_NOSEMI*/
194
195 class helper_stateful_request
196 {
197
198 public:
199 MEMPROXY_CLASS(helper_stateful_request);
200 char *buf;
201 HLPSCB *callback;
202 int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available for deferred requests.*/
203 void *data;
204 };
205
206 MEMPROXY_CLASS_INLINE(helper_stateful_request) /**DOCS_NOSEMI*/
207
208 /* helper.c */
209 SQUIDCEXTERN void helperOpenServers(helper * hlp);
210 SQUIDCEXTERN void helperStatefulOpenServers(statefulhelper * hlp);
211 SQUIDCEXTERN void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
212 SQUIDCEXTERN void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver);
213 SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL);
214 SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL);
215 SQUIDCEXTERN void helperShutdown(helper * hlp);
216 SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp);
217 SQUIDCEXTERN helper *helperCreate(const char *);
218 SQUIDCEXTERN statefulhelper *helperStatefulCreate(const char *);
219 SQUIDCEXTERN void helperFree(helper *);
220 SQUIDCEXTERN void helperStatefulFree(statefulhelper *);
221 SQUIDCEXTERN void helperStatefulReset(helper_stateful_server * srv);
222 SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv);
223 SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv);
224 SQUIDCEXTERN helper_stateful_server *helperStatefulDefer(statefulhelper *);
225
226
227
228 #endif /* SQUID_HELPER_H */