2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 84 Helper process maintenance */
11 #ifndef SQUID_HELPER_H
12 #define SQUID_HELPER_H
14 #include "base/AsyncCall.h"
15 #include "base/InstanceId.h"
17 #include "comm/forward.h"
19 #include "HelperChildConfig.h"
20 #include "HelperReply.h"
21 #include "ip/Address.h"
25 typedef void HLPCB(void *, const HelperReply
&reply
);
30 inline helper(const char *name
) :
37 memset(&stats
, 0, sizeof(stats
));
46 HelperChildConfig childs
; ///< Configuration settings for number running.
49 time_t last_queue_warn
;
51 char eom
; ///< The char which marks the end of (response) message, normally '\n'
61 CBDATA_CLASS2(helper
);
64 class statefulhelper
: public helper
67 inline statefulhelper(const char *name
) : helper(name
), datapool(NULL
), IsAvailable(NULL
), OnEmptyQueue(NULL
) {};
68 inline ~statefulhelper() {};
71 MemAllocator
*datapool
;
72 HLPSAVAIL
*IsAvailable
;
73 HLPSONEQ
*OnEmptyQueue
;
76 CBDATA_CLASS2(statefulhelper
);
80 * Fields shared between stateless and stateful helper servers.
82 class HelperServerBase
85 /** Closes pipes to the helper safely.
86 * Handles the case where the read and write pipes are the same FD.
88 void closePipesSafely();
90 /** Closes the reading pipe.
91 * If the read and write sockets are the same the write pipe will
92 * also be closed. Otherwise its left open for later handling.
94 void closeWritePipeSafely();
97 /// Helper program identifier; does not change when contents do,
98 /// including during assignment
99 const InstanceId
<HelperServerBase
> index
;
102 Comm::ConnectionPointer readPipe
;
103 Comm::ConnectionPointer writePipe
;
110 struct timeval dispatch_time
;
111 struct timeval answer_time
;
115 struct _helper_flags
{
124 uint64_t uses
; //< requests sent to this helper
125 uint64_t replies
; //< replies received from this helper
126 uint64_t pending
; //< queued lookups waiting to be sent to this helper
127 uint64_t releases
; //< times release() has been called on this helper (if stateful)
134 class helper_server
: public HelperServerBase
141 helper_request
**requests
;
144 CBDATA_CLASS2(helper_server
);
147 class helper_stateful_request
;
149 class helper_stateful_server
: public HelperServerBase
153 /* MemBuf writebuf; */
155 statefulhelper
*parent
;
156 helper_stateful_request
*request
;
158 void *data
; /* State data used by the calling routines */
161 CBDATA_CLASS2(helper_stateful_server
);
168 MEMPROXY_CLASS(helper_request
);
173 struct timeval dispatch_time
;
176 MEMPROXY_CLASS_INLINE(helper_request
);
178 class helper_stateful_request
182 MEMPROXY_CLASS(helper_stateful_request
);
185 int placeholder
; /* if 1, this is a dummy request waiting for a stateful helper to become available */
189 MEMPROXY_CLASS_INLINE(helper_stateful_request
);
192 void helperOpenServers(helper
* hlp
);
193 void helperStatefulOpenServers(statefulhelper
* hlp
);
194 void helperSubmit(helper
* hlp
, const char *buf
, HLPCB
* callback
, void *data
);
195 void helperStatefulSubmit(statefulhelper
* hlp
, const char *buf
, HLPCB
* callback
, void *data
, helper_stateful_server
* lastserver
);
196 void helperStats(StoreEntry
* sentry
, helper
* hlp
, const char *label
= NULL
);
197 void helperStatefulStats(StoreEntry
* sentry
, statefulhelper
* hlp
, const char *label
= NULL
);
198 void helperShutdown(helper
* hlp
);
199 void helperStatefulShutdown(statefulhelper
* hlp
);
200 void helperStatefulReleaseServer(helper_stateful_server
* srv
);
201 void *helperStatefulServerGetData(helper_stateful_server
* srv
);
203 #endif /* SQUID_HELPER_H */