]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add RegisteredRunner for HTCP (#2143) auto master
authorAmos Jeffries <yadij@users.noreply.github.com>
Tue, 2 Sep 2025 05:46:16 +0000 (05:46 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Tue, 2 Sep 2025 10:00:10 +0000 (10:00 +0000)
src/htcp.cc
src/htcp.h
src/main.cc

index cf6b3b612040a2fd4f98f0fd156c53743df42648..99b3c429dba7892967a6bc4948ff37a0fe70b46c 100644 (file)
@@ -13,6 +13,7 @@
 #include "acl/Acl.h"
 #include "acl/FilledChecklist.h"
 #include "base/AsyncCallbacks.h"
+#include "base/RunnersRegistry.h"
 #include "CachePeer.h"
 #include "CachePeers.h"
 #include "comm.h"
@@ -1432,15 +1433,12 @@ htcpRecv(int fd, void *)
     Comm::SetSelect(fd, COMM_SELECT_READ, htcpRecv, nullptr, 0);
 }
 
-/*
- * ======================================================================
- * PUBLIC FUNCTIONS
- * ======================================================================
- */
-
-void
-htcpOpenPorts(void)
+static void
+htcpOpenPorts()
 {
+    if (!IamWorkerProcess())
+        return;
+
     if (Config.Port.htcp <= 0) {
         debugs(31, Important(21), "HTCP Disabled.");
         return;
@@ -1612,8 +1610,8 @@ htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &, CachePee
  * htcpSocketShutdown only closes the 'in' socket if it is
  * different than the 'out' socket.
  */
-void
-htcpSocketShutdown(void)
+static void
+htcpSocketShutdown()
 {
     if (!Comm::IsConnOpen(htcpIncomingConn))
         return;
@@ -1641,9 +1639,12 @@ htcpSocketShutdown(void)
     Comm::SetSelect(htcpOutgoingConn->fd, COMM_SELECT_READ, nullptr, nullptr, 0);
 }
 
-void
-htcpClosePorts(void)
+static void
+htcpClosePorts()
 {
+    if (!IamWorkerProcess())
+        return;
+
     htcpSocketShutdown();
 
     if (htcpOutgoingConn != nullptr) {
@@ -1652,6 +1653,16 @@ htcpClosePorts(void)
     }
 }
 
+class HtcpRr : public RegisteredRunner
+{
+public:
+    void useConfig() override { htcpOpenPorts(); }
+    void startReconfigure() override { htcpClosePorts(); }
+    void syncConfig() override { htcpOpenPorts(); }
+    void startShutdown() override { htcpClosePorts(); }
+};
+DefineRunnerRegistrator(HtcpRr);
+
 static void
 htcpLogHtcp(Ip::Address &caddr, const int opcode, const LogTags_ot logcode, const char *url, AccessLogEntryPointer al)
 {
index 4bf9aadc7fa9987b67f7f3cd8e34ae1de87d5553..b7422b2c560f22ce78add77c04aedd291a000bb9 100644 (file)
@@ -43,9 +43,6 @@ public:
 /// \ingroup ServerProtocolHTCP
 void neighborsHtcpReply(const cache_key *, HtcpReplyData *, const Ip::Address &);
 
-/// \ingroup ServerProtocolHTCP
-void htcpOpenPorts(void);
-
 class CachePeer;
 
 /**
@@ -66,13 +63,6 @@ int htcpQuery(StoreEntry * e, HttpRequest * req, CachePeer * p);
 /// \ingroup ServerProtocolHTCP
 void htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &method, CachePeer * p, htcp_clr_reason reason);
 
-/// \ingroup ServerProtocolHTCP
-void htcpSocketShutdown(void);
-
-/// \ingroup ServerProtocolHTCP
-void htcpClosePorts(void);
-
 #endif /* USE_HTCP */
-
 #endif /* SQUID_SRC_HTCP_H */
 
index 790971ae437d5e321b41f2ac0ee67a1a7b2f225b..c18dde60d71a51a19054502253aed703c04ea1e7 100644 (file)
@@ -42,7 +42,6 @@
 #include "fs_io.h"
 #include "FwdState.h"
 #include "globals.h"
-#include "htcp.h"
 #include "http/Stream.h"
 #include "HttpHeader.h"
 #include "HttpReply.h"
@@ -778,9 +777,6 @@ serverConnectionsOpen(void)
     if (IamWorkerProcess()) {
         clientOpenListenSockets();
         icpOpenPorts();
-#if USE_HTCP
-        htcpOpenPorts();
-#endif
         icmpEngine.Open();
         netdbInit();
         Acl::Node::Initialize();
@@ -796,10 +792,6 @@ serverConnectionsClose(void)
     if (IamWorkerProcess()) {
         clientConnectionsClose();
         icpConnectionShutdown();
-#if USE_HTCP
-        htcpSocketShutdown();
-#endif
-
         icmpEngine.Close();
     }
 }
@@ -818,9 +810,6 @@ mainReconfigureStart(void)
     // Initiate asynchronous closing sequence
     serverConnectionsClose();
     icpClosePorts();
-#if USE_HTCP
-    htcpClosePorts();
-#endif
 #if USE_OPENSSL
     Ssl::TheGlobalContextStorage().reconfigureStart();
 #endif
@@ -1404,7 +1393,9 @@ RegisterModules()
 #if USE_AUTH
     CallRunnerRegistrator(PeerUserHashRr);
 #endif
-
+#if USE_HTCP
+    CallRunnerRegistrator(HtcpRr);
+#endif
 #if USE_OPENSSL
     CallRunnerRegistrator(sslBumpCfgRr);
 #endif
@@ -2025,9 +2016,6 @@ SquidShutdown()
     redirectShutdown();
     externalAclShutdown();
     icpClosePorts();
-#if USE_HTCP
-    htcpClosePorts();
-#endif
     releaseServerSockets();
     commCloseAllSockets();