]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/helper.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / helper.h
index 800a0cadc249449c0a3873cdb364601e838aba9e..5da5c3b752e549694dbf73f7bce27a631d582b93 100644 (file)
 #ifndef SQUID_HELPER_H
 #define SQUID_HELPER_H
 
-#include "squid.h"
+#include "base/AsyncCall.h"
 #include "cbdata.h"
-#include "ip/IpAddress.h"
+#include "comm/forward.h"
+#include "dlink.h"
+#include "ip/Address.h"
 #include "HelperChildConfig.h"
 
 class helper_request;
 
-typedef struct _helper_flags helper_flags;
-
-typedef struct _helper_stateful_flags helper_stateful_flags;
-
 typedef void HLPSCB(void *, void *lastserver, char *buf);
 
 class helper
 {
 public:
-    inline helper(const char *name) : cmdline(NULL), id_name(name) {};
+    inline helper(const char *name) : cmdline(NULL), id_name(name), eom('\n') {}
     ~helper();
 
 public:
@@ -59,9 +57,10 @@ public:
     const char *id_name;
     HelperChildConfig childs;    ///< Configuration settings for number running.
     int ipc_type;
-    IpAddress addr;
+    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 _stats {
         int requests;
@@ -94,12 +93,24 @@ private:
  */
 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;
-    IpAddress addr;
-    int rfd;
-    int wfd;
+    Ip::Address addr;
+    Comm::ConnectionPointer readPipe;
+    Comm::ConnectionPointer writePipe;
     void *hIpc;
 
     char *rbuf;
@@ -110,8 +121,19 @@ public:
     struct timeval answer_time;
 
     dlink_node link;
+
+    struct _helper_flags {
+        unsigned int busy:1;
+        unsigned int writing:1;
+        unsigned int closing:1;
+        unsigned int shutdown:1;
+        unsigned int reserved:1;
+    } flags;
+
 };
 
+class MemBuf;
+
 class helper_server : public HelperServerBase
 {
 public:
@@ -121,16 +143,13 @@ public:
     helper *parent;
     helper_request **requests;
 
-    struct _helper_flags {
-        unsigned int writing:1;
-        unsigned int closing:1;
-        unsigned int shutdown:1;
-    } flags;
-
     struct {
         int uses;
         unsigned int pending;
     } stats;
+
+private:
+    CBDATA_CLASS2(helper_server);
 };
 
 class helper_stateful_request;
@@ -144,19 +163,15 @@ public:
     statefulhelper *parent;
     helper_stateful_request *request;
 
-    struct _helper_stateful_flags {
-        unsigned int busy:1;
-        unsigned int closing:1;
-        unsigned int shutdown:1;
-        unsigned int reserved:1;
-    } flags;
-
     struct {
         int uses;
         int submits;
         int releases;
     } stats;
     void *data;                        /* State data used by the calling routines */
+
+private:
+    CBDATA_CLASS2(helper_stateful_server);
 };
 
 class helper_request
@@ -198,5 +213,4 @@ SQUIDCEXTERN void helperStatefulShutdown(statefulhelper * hlp);
 SQUIDCEXTERN void helperStatefulReleaseServer(helper_stateful_server * srv);
 SQUIDCEXTERN void *helperStatefulServerGetData(helper_stateful_server * srv);
 
-
 #endif /* SQUID_HELPER_H */