From: Amos Jeffries Date: Sun, 4 Dec 2011 05:43:42 +0000 (-0700) Subject: Add FdeCbParams parameter object to CommCalls API. X-Git-Tag: BumpSslServerFirst.take05~12^2~137 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a17bf80622f8f80d0ce7c0d173ea032a42a520b5;p=thirdparty%2Fsquid.git Add FdeCbParams parameter object to CommCalls API. 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. --- diff --git a/src/CommCalls.cc b/src/CommCalls.cc index 77ca002d6c..a75f33bc8c 100644 --- a/src/CommCalls.cc +++ b/src/CommCalls.cc @@ -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(aParams), + handler(aHandler) +{ +} + +void +FdeCbPtrFun::dial() +{ + handler(params); +} + +void +FdeCbPtrFun::print(std::ostream &os) const +{ + os << '('; + params.print(os); + os << ')'; +} diff --git a/src/CommCalls.h b/src/CommCalls.h index ef4813a700..dd0612928c 100644 --- a/src/CommCalls.h +++ b/src/CommCalls.h @@ -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 ¶ms); 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 @@ -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 ¶ms); @@ -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 @@ -268,6 +283,21 @@ public: CTCB *handler; }; +/// FD event (FDECB) dialer +class FdeCbPtrFun: public CallDialer, + public CommDialerParamsT +{ +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 diff --git a/src/comm.cc b/src/comm.cc index b605f40e9b..5627d11589 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1048,7 +1048,7 @@ old_comm_reset_close(int fd) #if USE_SSL void -commStartSslClose(const CommCloseCbParams ¶ms) +commStartSslClose(const FdeCbParams ¶ms) { assert(&fd_table[params.fd].ssl); ssl_shutdown_method(fd_table[params.fd].ssl); @@ -1056,7 +1056,7 @@ commStartSslClose(const CommCloseCbParams ¶ms) #endif void -comm_close_complete(const CommCloseCbParams ¶ms) +comm_close_complete(const FdeCbParams ¶ms) { #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(startCall); + FdeCbPtrFun(commStartSslClose, NULL)); + FdeCbParams &startParams = GetCommParams(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(completeCall); + FdeCbPtrFun(comm_close_complete, NULL)); + FdeCbParams &completeParams = GetCommParams(completeCall); completeParams.fd = fd; // must use async call to wait for all callbacks // scheduled before comm_close() to finish