]> git.ipfire.org Git - thirdparty/squid.git/blob - src/helper.h
Merge from trunk rev.13584
[thirdparty/squid.git] / src / helper.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 84 Helper process maintenance */
10
11 #ifndef SQUID_HELPER_H
12 #define SQUID_HELPER_H
13
14 #include "base/AsyncCall.h"
15 #include "base/InstanceId.h"
16 #include "cbdata.h"
17 #include "comm/forward.h"
18 #include "dlink.h"
19 #include "HelperChildConfig.h"
20 #include "HelperReply.h"
21 #include "ip/Address.h"
22
23 class helper_request;
24
25 typedef void HLPCB(void *, const HelperReply &reply);
26
27 class helper
28 {
29 public:
30 inline helper(const char *name) :
31 cmdline(NULL),
32 id_name(name),
33 ipc_type(0),
34 last_queue_warn(0),
35 last_restart(0),
36 eom('\n') {
37 memset(&stats, 0, sizeof(stats));
38 }
39 ~helper();
40
41 public:
42 wordlist *cmdline;
43 dlink_list servers;
44 dlink_list queue;
45 const char *id_name;
46 HelperChildConfig childs; ///< Configuration settings for number running.
47 int ipc_type;
48 Ip::Address addr;
49 time_t last_queue_warn;
50 time_t last_restart;
51 char eom; ///< The char which marks the end of (response) message, normally '\n'
52
53 struct _stats {
54 int requests;
55 int replies;
56 int queue_size;
57 int avg_svc_time;
58 } stats;
59
60 private:
61 CBDATA_CLASS2(helper);
62 };
63
64 class statefulhelper : public helper
65 {
66 public:
67 inline statefulhelper(const char *name) : helper(name), datapool(NULL), IsAvailable(NULL), OnEmptyQueue(NULL) {};
68 inline ~statefulhelper() {};
69
70 public:
71 MemAllocator *datapool;
72 HLPSAVAIL *IsAvailable;
73 HLPSONEQ *OnEmptyQueue;
74
75 private:
76 CBDATA_CLASS2(statefulhelper);
77 };
78
79 /**
80 * Fields shared between stateless and stateful helper servers.
81 */
82 class HelperServerBase
83 {
84 public:
85 /** Closes pipes to the helper safely.
86 * Handles the case where the read and write pipes are the same FD.
87 */
88 void closePipesSafely();
89
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.
93 */
94 void closeWritePipeSafely();
95
96 public:
97 /// Helper program identifier; does not change when contents do,
98 /// including during assignment
99 const InstanceId<HelperServerBase> index;
100 int pid;
101 Ip::Address addr;
102 Comm::ConnectionPointer readPipe;
103 Comm::ConnectionPointer writePipe;
104 void *hIpc;
105
106 char *rbuf;
107 size_t rbuf_sz;
108 size_t roffset;
109
110 struct timeval dispatch_time;
111 struct timeval answer_time;
112
113 dlink_node link;
114
115 struct _helper_flags {
116 bool busy;
117 bool writing;
118 bool closing;
119 bool shutdown;
120 bool reserved;
121 } flags;
122
123 struct {
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)
128 } stats;
129 void initStats();
130 };
131
132 class MemBuf;
133
134 class helper_server : public HelperServerBase
135 {
136 public:
137 MemBuf *wqueue;
138 MemBuf *writebuf;
139
140 helper *parent;
141 helper_request **requests;
142
143 private:
144 CBDATA_CLASS2(helper_server);
145 };
146
147 class helper_stateful_request;
148
149 class helper_stateful_server : public HelperServerBase
150 {
151 public:
152 /* MemBuf wqueue; */
153 /* MemBuf writebuf; */
154
155 statefulhelper *parent;
156 helper_stateful_request *request;
157
158 void *data; /* State data used by the calling routines */
159
160 private:
161 CBDATA_CLASS2(helper_stateful_server);
162 };
163
164 class helper_request
165 {
166
167 public:
168 MEMPROXY_CLASS(helper_request);
169 char *buf;
170 HLPCB *callback;
171 void *data;
172
173 struct timeval dispatch_time;
174 };
175
176 MEMPROXY_CLASS_INLINE(helper_request);
177
178 class helper_stateful_request
179 {
180
181 public:
182 MEMPROXY_CLASS(helper_stateful_request);
183 char *buf;
184 HLPCB *callback;
185 int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */
186 void *data;
187 };
188
189 MEMPROXY_CLASS_INLINE(helper_stateful_request);
190
191 /* helper.c */
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);
202
203 #endif /* SQUID_HELPER_H */