]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/helper.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / helper.h
index 8b275085abd7e24d7968f5a7fdba3cad89449f96..5da5c3b752e549694dbf73f7bce27a631d582b93 100644 (file)
@@ -1,7 +1,4 @@
-
 /*
- * $Id: helper.h,v 1.7 2006/09/03 19:10:22 serassio Exp $
- *
  * DEBUG: section 84    Helper process maintenance
  * AUTHOR: Harvest Derived?
  *
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 #ifndef SQUID_HELPER_H
 #define SQUID_HELPER_H
 
-#include "squid.h"
+#include "base/AsyncCall.h"
 #include "cbdata.h"
+#include "comm/forward.h"
+#include "dlink.h"
+#include "ip/Address.h"
+#include "HelperChildConfig.h"
 
 class helper_request;
 
-typedef struct _helper helper;
-
-typedef struct _helper_stateful statefulhelper;
-
-typedef struct _helper_server helper_server;
-
-typedef struct _helper_stateful_server helper_stateful_server;
-
-typedef struct _helper_flags helper_flags;
-
-typedef struct _helper_stateful_flags helper_stateful_flags;
+typedef void HLPSCB(void *, void *lastserver, char *buf);
 
-typedef stateful_helper_callback_t HLPSCB(void *, void *lastserver, char *buf);
-
-struct _helper
+class helper
 {
+public:
+    inline helper(const char *name) : cmdline(NULL), id_name(name), eom('\n') {}
+    ~helper();
+
+public:
     wordlist *cmdline;
     dlink_list servers;
     dlink_list queue;
     const char *id_name;
-    int n_to_start;
-    int n_running;
-    int n_active;
+    HelperChildConfig childs;    ///< Configuration settings for number running.
     int ipc_type;
-    unsigned int concurrency;
+    Ip::Address addr;
     time_t last_queue_warn;
     time_t last_restart;
+    char eom;   ///< The char which marks the end of (response) message, normally '\n'
 
-    struct
-    {
+    struct _stats {
         int requests;
         int replies;
         int queue_size;
         int avg_svc_time;
-    }
+    } stats;
 
-    stats;
+private:
+    CBDATA_CLASS2(helper);
 };
 
-struct _helper_stateful
+class statefulhelper : public helper
 {
-    wordlist *cmdline;
-    dlink_list servers;
-    dlink_list queue;
-    const char *id_name;
-    int n_to_start;
-    int n_running;
-    int n_active;
-    int ipc_type;
+public:
+    inline statefulhelper(const char *name) : helper(name) {};
+    inline ~statefulhelper() {};
+
+public:
     MemAllocator *datapool;
     HLPSAVAIL *IsAvailable;
     HLPSONEQ *OnEmptyQueue;
-    time_t last_queue_warn;
-    time_t last_restart;
 
-    struct
-    {
-        int requests;
-        int replies;
-        int queue_size;
-        int avg_svc_time;
-    }
-
-    stats;
+private:
+    CBDATA_CLASS2(statefulhelper);
 };
 
-struct _helper_server
+/*
+ * Fields shared between stateless and stateful helper servers.
+ */
+class HelperServerBase
 {
+public:
+    /** Closes pipes to the helper safely.
+     * Handles the case where the read and write pipes are the same FD.
+     */
+    void closePipesSafely();
+
+    /** Closes the reading pipe.
+     * If the read and write sockets are the same the write pipe will
+     * also be closed. Otherwise its left open for later handling.
+     */
+    void closeWritePipeSafely();
+
+public:
     int index;
     int pid;
-    int rfd;
-    int wfd;
-    MemBuf *wqueue;
-    MemBuf *writebuf;
+    Ip::Address addr;
+    Comm::ConnectionPointer readPipe;
+    Comm::ConnectionPointer writePipe;
+    void *hIpc;
+
     char *rbuf;
     size_t rbuf_sz;
-    off_t roffset;
+    size_t roffset;
 
     struct timeval dispatch_time;
-
     struct timeval answer_time;
 
     dlink_node link;
-    helper *parent;
-    helper_request **requests;
 
-    struct _helper_flags
-    {
+    struct _helper_flags {
+        unsigned int busy:1;
+        unsigned int writing:1;
+        unsigned int closing:1;
+        unsigned int shutdown:1;
+        unsigned int reserved:1;
+    } flags;
 
-unsigned int writing:
-        1;
+};
 
-unsigned int closing:
-        1;
+class MemBuf;
 
-unsigned int shutdown:
-        1;
-    }
+class helper_server : public HelperServerBase
+{
+public:
+    MemBuf *wqueue;
+    MemBuf *writebuf;
 
-    flags;
+    helper *parent;
+    helper_request **requests;
 
-    struct
-    {
+    struct {
         int uses;
         unsigned int pending;
-    }
+    } stats;
 
-    stats;
-    HANDLE hIpc;
+private:
+    CBDATA_CLASS2(helper_server);
 };
 
 class helper_stateful_request;
 
-struct _helper_stateful_server
+class helper_stateful_server : public HelperServerBase
 {
-    int index;
-    int pid;
-    int rfd;
-    int wfd;
+public:
     /* MemBuf wqueue; */
     /* MemBuf writebuf; */
-    char *rbuf;
-    size_t rbuf_sz;
-    off_t roffset;
-
-    struct timeval dispatch_time;
-
-    struct timeval answer_time;
 
-    dlink_node link;
-    dlink_list queue;
     statefulhelper *parent;
     helper_stateful_request *request;
 
-    struct _helper_stateful_flags
-    {
-
-unsigned int busy:
-        1;
-
-unsigned int closing:
-        1;
-
-unsigned int shutdown:
-        1;
-        stateful_helper_reserve_t reserved;
-    }
-
-    flags;
-
-    struct
-    {
+    struct {
         int uses;
         int submits;
         int releases;
-        int deferbyfunc;
-        int deferbycb;
-    }
-
-    stats;
-    int deferred_requests;     /* current number of deferred requests */
+    } stats;
     void *data;                        /* State data used by the calling routines */
-    HANDLE hIpc;
+
+private:
+    CBDATA_CLASS2(helper_stateful_server);
 };
 
 class helper_request
@@ -218,7 +186,7 @@ public:
     struct timeval dispatch_time;
 };
 
-MEMPROXY_CLASS_INLINE(helper_request)
+MEMPROXY_CLASS_INLINE(helper_request);
 
 class helper_stateful_request
 {
@@ -227,30 +195,22 @@ public:
     MEMPROXY_CLASS(helper_stateful_request);
     char *buf;
     HLPSCB *callback;
-    int placeholder;           /* if 1, this is a dummy request waiting for a stateful helper to become available for deferred requests.*/
+    int placeholder;           /* if 1, this is a dummy request waiting for a stateful helper to become available */
     void *data;
 };
 
-MEMPROXY_CLASS_INLINE(helper_stateful_request)
+MEMPROXY_CLASS_INLINE(helper_stateful_request);
 
 /* helper.c */
 SQUIDCEXTERN void helperOpenServers(helper * hlp);
 SQUIDCEXTERN void helperStatefulOpenServers(statefulhelper * hlp);
 SQUIDCEXTERN void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
 SQUIDCEXTERN void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPSCB * callback, void *data, helper_stateful_server * lastserver);
-SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp);
-SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp);
+SQUIDCEXTERN void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL);
+SQUIDCEXTERN void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL);
 SQUIDCEXTERN void helperShutdown(helper * hlp);
 SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp);
-SQUIDCEXTERN helper *helperCreate(const char *);
-SQUIDCEXTERN statefulhelper *helperStatefulCreate(const char *);
-SQUIDCEXTERN void helperFree(helper *);
-SQUIDCEXTERN void helperStatefulFree(statefulhelper *);
-SQUIDCEXTERN void helperStatefulReset(helper_stateful_server * srv);
 SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv);
 SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv);
-SQUIDCEXTERN helper_stateful_server *helperStatefulDefer(statefulhelper *);
-
-
 
 #endif /* SQUID_HELPER_H */