]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Replaced FDECB callback with a basic async call (#1135)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Sun, 11 Sep 2022 17:24:48 +0000 (17:24 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 11 Sep 2022 18:29:57 +0000 (18:29 +0000)
The "FD passing callback" was misleading because it was not used as a
callback. We just need an async call with a known-to-the-caller
parameter instead. Simplifying CommCalls (by removing this "special
callback") helps improve that API.

src/CommCalls.cc
src/CommCalls.h
src/base/AsyncFunCalls.h
src/comm.cc

index 67b5a8ae9d83e38374fc38bd756ae4ecc25a19cc..f8cee3d8d3e50bc2e831583edbcd645448a64427 100644 (file)
@@ -138,13 +138,6 @@ CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
 {
 }
 
-/* FdeCbParams */
-
-FdeCbParams::FdeCbParams(void *aData):
-    CommCommonCbParams(aData)
-{
-}
-
 /* CommAcceptCbPtrFun */
 
 CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
@@ -265,25 +258,3 @@ CommTimeoutCbPtrFun::print(std::ostream &os) const
     os << ')';
 }
 
-/* FdeCbPtrFun */
-
-FdeCbPtrFun::FdeCbPtrFun(FDECB *aHandler, const FdeCbParams &aParams) :
-    CommDialerParamsT<FdeCbParams>(aParams),
-    handler(aHandler)
-{
-}
-
-void
-FdeCbPtrFun::dial()
-{
-    handler(params);
-}
-
-void
-FdeCbPtrFun::print(std::ostream &os) const
-{
-    os << '(';
-    params.print(os);
-    os << ')';
-}
-
index e56a79196f857ebe20307b1863d4d2abfb8f8970..37d9dcf56f4b5f0741a9f6806262e8fe4223b3c2 100644 (file)
@@ -25,8 +25,6 @@
  *     - I/O (IOCB)
  *     - timeout (CTCB)
  *     - close (CLCB)
- * and a special callback kind for passing pipe FD, disk FD or fd_table index 'FD' to the handler:
- *     - FD passing callback (FDECB)
  */
 
 class CommAcceptCbParams;
@@ -41,9 +39,6 @@ typedef void CTCB(const CommTimeoutCbParams &params);
 class CommCloseCbParams;
 typedef void CLCB(const CommCloseCbParams &params);
 
-class FdeCbParams;
-typedef void FDECB(const FdeCbParams &params);
-
 /*
  * TODO: When there are no function-pointer-based callbacks left, all
  * this complexity can be removed. Jobs that need comm services will just
@@ -141,16 +136,6 @@ public:
     CommTimeoutCbParams(void *aData);
 };
 
-/// Special Calls parameter, for direct use of an FD without a controlling Comm::Connection
-/// This is used for pipe() FD with helpers, and internally by Comm when handling some special FD actions.
-class FdeCbParams: public CommCommonCbParams
-{
-public:
-    FdeCbParams(void *aData);
-    // TODO make this a standalone object with FD value and pointer to fde table entry.
-    // that requires all the existing Comm handlers to be updated first though
-};
-
 // Interface to expose comm callback parameters of all comm dialers.
 // GetCommParams() uses this interface to access comm parameters.
 template <class Params_>
@@ -287,21 +272,6 @@ public:
     CTCB *handler;
 };
 
-/// FD event (FDECB) dialer
-class FdeCbPtrFun: public CallDialer,
-    public CommDialerParamsT<FdeCbParams>
-{
-public:
-    typedef FdeCbParams Params;
-
-    FdeCbPtrFun(FDECB *aHandler, const Params &aParams);
-    void dial();
-    virtual void print(std::ostream &os) const;
-
-public:
-    FDECB *handler;
-};
-
 // AsyncCall to comm handlers implemented as global functions.
 // The dialer is one of the Comm*CbPtrFunT above
 // TODO: Get rid of this class by moving canFire() to canDial() method
index ff2ac84b846771691d773b0e45b1ee749f4b0218..012a524c1cb5cbc01449e65d5f16c2ce20d00f75 100644 (file)
@@ -30,5 +30,37 @@ private:
     Handler *handler; ///< the function to call (or nil)
 };
 
+/// CallDialer for single-parameter stand-alone functions
+template <typename Argument1>
+class UnaryFunDialer: public CallDialer
+{
+public:
+    /// a stand-alone function that receives the parameter given to us
+    using Handler = void (Argument1);
+
+    UnaryFunDialer(Handler * const aHandler, Argument1 anArg1):
+        handler(aHandler),
+        arg1(anArg1)
+    {}
+    virtual ~UnaryFunDialer() = default;
+
+    /* CallDialer API */
+    bool canDial(AsyncCall &) { return bool(handler); }
+    void dial(AsyncCall &) { handler(std::move(arg1)); }
+    virtual void print(std::ostream &os) const final { os << '(' << arg1 << ')'; }
+
+private:
+    Handler *handler; ///< the function to call
+    Argument1 arg1; ///< actual call parameter
+};
+
+/// helper function to simplify UnaryFunDialer creation
+template <typename Argument1>
+UnaryFunDialer<Argument1>
+callDialer(void (*handler)(Argument1), Argument1 arg1)
+{
+    return UnaryFunDialer<Argument1>(handler, arg1);
+}
+
 #endif /* SQUID_BASE_ASYNCFUNCALLS_H */
 
index f7516ea3d9138edc51452440b4be97237374aa2e..551d41d61d26407865091b04a65c4fd7b971533a 100644 (file)
@@ -9,6 +9,7 @@
 /* DEBUG: section 05    Socket Functions */
 
 #include "squid.h"
+#include "base/AsyncFunCalls.h"
 #include "ClientInfo.h"
 #include "comm/AcceptLimiter.h"
 #include "comm/comm_internal.h"
@@ -805,19 +806,19 @@ old_comm_reset_close(int fd)
 }
 
 static void
-commStartTlsClose(const FdeCbParams &params)
+commStartTlsClose(const int fd)
 {
-    Security::SessionSendGoodbye(fd_table[params.fd].ssl);
+    Security::SessionSendGoodbye(fd_table[fd].ssl);
 }
 
 static void
-comm_close_complete(const FdeCbParams &params)
+comm_close_complete(const int fd)
 {
-    fde *F = &fd_table[params.fd];
+    auto F = &fd_table[fd];
     F->ssl.reset();
     F->dynamicTlsContext.reset();
-    fd_close(params.fd);        /* update fdstat */
-    close(params.fd);
+    fd_close(fd); /* update fdstat */
+    close(fd);
 
     ++ statCounter.syscalls.sock.closes;
 
@@ -869,10 +870,8 @@ _comm_close(int fd, char const *file, int line)
     // allowing individual advanced callbacks to overwrite it.
 
     if (F->ssl) {
-        AsyncCall::Pointer startCall=commCbCall(5,4, "commStartTlsClose",
-                                                FdeCbPtrFun(commStartTlsClose, nullptr));
-        FdeCbParams &startParams = GetCommParams<FdeCbParams>(startCall);
-        startParams.fd = fd;
+        const auto startCall = asyncCall(5, 4, "commStartTlsClose",
+                                         callDialer(commStartTlsClose, fd));
         ScheduleCallHere(startCall);
     }
 
@@ -902,12 +901,10 @@ _comm_close(int fd, char const *file, int line)
 
     comm_empty_os_read_buffers(fd);
 
-    AsyncCall::Pointer completeCall=commCbCall(5,4, "comm_close_complete",
-                                    FdeCbPtrFun(comm_close_complete, nullptr));
-    FdeCbParams &completeParams = GetCommParams<FdeCbParams>(completeCall);
-    completeParams.fd = fd;
     // must use async call to wait for all callbacks
     // scheduled before comm_close() to finish
+    const auto completeCall = asyncCall(5, 4, "comm_close_complete",
+                                        callDialer(comm_close_complete, fd));
     ScheduleCallHere(completeCall);
 }