]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add FdeCbParams parameter object to CommCalls API.
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 4 Dec 2011 05:43:42 +0000 (22:43 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 4 Dec 2011 05:43:42 +0000 (22:43 -0700)
The problem:
  CommCalls API functionality is conflated with comm operational calls
created to do general FD handling (FD as pipe handle, FD as disk handle,
FD as pointer into the fd_table structure). Sometimes because they do
operations mirroring comm handlers and also use FD.  None of this actually
requires the CommCalls layer to be involved though. The Comm::Connection
objects which CommCall TCP handlers pass around is also very inappropriate
for these FD types.

This adds FdeCbParams to CommCalls infrastructure, for use internally and
"lower" than comm API to pass around raw FD values. This should be avoided
on TCP socket FD, but may be used by callers needing FD where
Comm::Connection is inappropriate.

src/CommCalls.cc
src/CommCalls.h
src/comm.cc

index 77ca002d6c1a8a5de9ad24fa37e96930623963c9..a75f33bc8c4f861d82db84d469d9df1ec665ee14 100644 (file)
@@ -108,6 +108,12 @@ CommTimeoutCbParams::CommTimeoutCbParams(void *aData):
 {
 }
 
+/* FdeCbParams */
+
+FdeCbParams::FdeCbParams(void *aData):
+        CommCommonCbParams(aData)
+{
+}
 
 /* CommAcceptCbPtrFun */
 
@@ -231,3 +237,25 @@ CommTimeoutCbPtrFun::print(std::ostream &os) const
     params.print(os);
     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 ef4813a70002b3c0d96c3c64228acd6867ba4a24..dd0612928c91e4f0a40f7a2de618f4e430b30018 100644 (file)
@@ -21,6 +21,8 @@
  *     - 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;
@@ -35,6 +37,9 @@ 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
@@ -79,7 +84,7 @@ public:
     comm_err_t flag;  ///< comm layer result status.
     int xerrno;      ///< The last errno to occur. non-zero if flag is COMM_ERR.
 
-    int fd; // raw FD which the call was about. use conn instead for new code.
+    int fd; ///< FD which the call was about. Set by the async call creator.
 private:
     // should not be needed and not yet implemented
     CommCommonCbParams &operator =(const CommCommonCbParams &params);
@@ -128,6 +133,16 @@ 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_>
@@ -268,6 +283,21 @@ 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 b605f40e9beacbab64f7f38fd097240f944e9f9f..5627d11589ee288ac5bb74e03ea59f059990a18b 100644 (file)
@@ -1048,7 +1048,7 @@ old_comm_reset_close(int fd)
 
 #if USE_SSL
 void
-commStartSslClose(const CommCloseCbParams &params)
+commStartSslClose(const FdeCbParams &params)
 {
     assert(&fd_table[params.fd].ssl);
     ssl_shutdown_method(fd_table[params.fd].ssl);
@@ -1056,7 +1056,7 @@ commStartSslClose(const CommCloseCbParams &params)
 #endif
 
 void
-comm_close_complete(const CommCloseCbParams &params)
+comm_close_complete(const FdeCbParams &params)
 {
 #if USE_SSL
     fde *F = &fd_table[params.fd];
@@ -1119,10 +1119,9 @@ _comm_close(int fd, char const *file, int line)
 
 #if USE_SSL
     if (F->ssl) {
-        // XXX: make this a generic async call passing one FD parameter. No need to use CommCloseCbParams
         AsyncCall::Pointer startCall=commCbCall(5,4, "commStartSslClose",
-                                                CommCloseCbPtrFun(commStartSslClose, NULL));
-        CommCloseCbParams &startParams = GetCommParams<CommCloseCbParams>(startCall);
+                                                FdeCbPtrFun(commStartSslClose, NULL));
+        FdeCbParams &startParams = GetCommParams<FdeCbParams>(startCall);
         startParams.fd = fd;
         ScheduleCallHere(startCall);
     }
@@ -1162,8 +1161,8 @@ _comm_close(int fd, char const *file, int line)
 
 
     AsyncCall::Pointer completeCall=commCbCall(5,4, "comm_close_complete",
-                                    CommCloseCbPtrFun(comm_close_complete, NULL));
-    CommCloseCbParams &completeParams = GetCommParams<CommCloseCbParams>(completeCall);
+                                    FdeCbPtrFun(comm_close_complete, NULL));
+    FdeCbParams &completeParams = GetCommParams<FdeCbParams>(completeCall);
     completeParams.fd = fd;
     // must use async call to wait for all callbacks
     // scheduled before comm_close() to finish