{
}
-/* FdeCbParams */
-
-FdeCbParams::FdeCbParams(void *aData):
- CommCommonCbParams(aData)
-{
-}
-
/* CommAcceptCbPtrFun */
CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler,
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 << ')';
-}
-
* - 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;
class CommCloseCbParams;
typedef void CLCB(const CommCloseCbParams ¶ms);
-class FdeCbParams;
-typedef void FDECB(const FdeCbParams ¶ms);
-
/*
* TODO: When there are no function-pointer-based callbacks left, all
* this complexity can be removed. Jobs that need comm services will just
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_>
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
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 */
/* DEBUG: section 05 Socket Functions */
#include "squid.h"
+#include "base/AsyncFunCalls.h"
#include "ClientInfo.h"
#include "comm/AcceptLimiter.h"
#include "comm/comm_internal.h"
}
static void
-commStartTlsClose(const FdeCbParams ¶ms)
+commStartTlsClose(const int fd)
{
- Security::SessionSendGoodbye(fd_table[params.fd].ssl);
+ Security::SessionSendGoodbye(fd_table[fd].ssl);
}
static void
-comm_close_complete(const FdeCbParams ¶ms)
+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;
// 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);
}
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);
}