2 * DEBUG: section 84 Helper process maintenance
3 * AUTHOR: Harvest Derived?
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
33 #ifndef SQUID_HELPER_H
34 #define SQUID_HELPER_H
36 #include "base/AsyncCall.h"
38 #include "comm/forward.h"
40 #include "HelperChildConfig.h"
41 #include "HelperReply.h"
42 #include "ip/Address.h"
46 typedef void HLPCB(void *, const HelperReply
&reply
);
51 inline helper(const char *name
) :
58 memset(&stats
, 0, sizeof(stats
));
67 HelperChildConfig childs
; ///< Configuration settings for number running.
70 time_t last_queue_warn
;
72 char eom
; ///< The char which marks the end of (response) message, normally '\n'
82 CBDATA_CLASS2(helper
);
85 class statefulhelper
: public helper
88 inline statefulhelper(const char *name
) : helper(name
), datapool(NULL
), IsAvailable(NULL
), OnEmptyQueue(NULL
) {};
89 inline ~statefulhelper() {};
92 MemAllocator
*datapool
;
93 HLPSAVAIL
*IsAvailable
;
94 HLPSONEQ
*OnEmptyQueue
;
97 CBDATA_CLASS2(statefulhelper
);
101 * Fields shared between stateless and stateful helper servers.
103 class HelperServerBase
106 /** Closes pipes to the helper safely.
107 * Handles the case where the read and write pipes are the same FD.
109 void closePipesSafely();
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.
115 void closeWritePipeSafely();
121 Comm::ConnectionPointer readPipe
;
122 Comm::ConnectionPointer writePipe
;
129 struct timeval dispatch_time
;
130 struct timeval answer_time
;
134 struct _helper_flags
{
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)
153 class helper_server
: public HelperServerBase
160 helper_request
**requests
;
163 CBDATA_CLASS2(helper_server
);
166 class helper_stateful_request
;
168 class helper_stateful_server
: public HelperServerBase
172 /* MemBuf writebuf; */
174 statefulhelper
*parent
;
175 helper_stateful_request
*request
;
177 void *data
; /* State data used by the calling routines */
180 CBDATA_CLASS2(helper_stateful_server
);
187 MEMPROXY_CLASS(helper_request
);
192 struct timeval dispatch_time
;
195 MEMPROXY_CLASS_INLINE(helper_request
);
197 class helper_stateful_request
201 MEMPROXY_CLASS(helper_stateful_request
);
204 int placeholder
; /* if 1, this is a dummy request waiting for a stateful helper to become available */
208 MEMPROXY_CLASS_INLINE(helper_stateful_request
);
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
);
222 #endif /* SQUID_HELPER_H */