=== modified file 'src/CommCalls.cc' --- src/CommCalls.cc 2011-11-22 12:00:59 +0000 +++ src/CommCalls.cc 2011-11-22 12:09:03 +0000 @@ -108,6 +108,12 @@ { } +/* FdeCbParams */ + +FdeCbParams::FdeCbParams(void *aData): + CommCommonCbParams(aData) +{ +} /* CommAcceptCbPtrFun */ @@ -231,3 +237,25 @@ 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 << ')'; +} === modified file 'src/CommCalls.h' --- src/CommCalls.h 2011-11-22 12:00:59 +0000 +++ src/CommCalls.h 2011-11-24 10:58:10 +0000 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 === added file 'src/base/AsyncCbdataCalls.h' --- src/base/AsyncCbdataCalls.h 1970-01-01 00:00:00 +0000 +++ src/base/AsyncCbdataCalls.h 2011-11-24 11:03:10 +0000 @@ -0,0 +1,37 @@ +#ifndef SQUID_BASE_ASYNCCBDATACALLS_H +#define SQUID_BASE_ASYNCCBDATACALLS_H + +#include "base/AsyncCall.h" +#include "base/CbcPointer.h" + +// dialer to run cbdata callback functions as Async Calls +// to ease the transition of these cbdata objects to full Jobs +template +class UnaryCbdataDialer : public CallDialer +{ +public: + typedef void Handler(Argument1 *); + + UnaryCbdataDialer(Handler *aHandler, CbcPointer aArg) : + arg1(aArg), + handler(aHandler) + {} + + virtual bool canDial(AsyncCall &call) { return arg1.valid(); } + void dial(AsyncCall &call) { handler(arg1.get()); } + virtual void print(std::ostream &os) const { os << '(' << arg1 << ')'; } + +public: + CbcPointer arg1; + Handler *handler; +}; + +// helper function to simplify Call creation. +template +UnaryCbdataDialer +cbdataDialer(typename UnaryCbdataDialer::Handler *handler, Argument1 *arg1) +{ + return UnaryCbdataDialer(handler, arg1); +} + +#endif === modified file 'src/base/Makefile.am' --- src/base/Makefile.am 2011-09-27 05:16:58 +0000 +++ src/base/Makefile.am 2011-11-24 00:09:34 +0000 @@ -7,6 +7,7 @@ libbase_la_SOURCES = \ AsyncCall.cc \ AsyncCall.h \ + AsyncCbdataCalls.h \ AsyncJob.h \ AsyncJob.cc \ AsyncJobCalls.h \ === modified file 'src/comm.cc' --- src/comm.cc 2011-11-22 12:00:59 +0000 +++ src/comm.cc 2011-11-23 11:19:52 +0000 @@ -1048,7 +1048,7 @@ #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 @@ #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 @@ #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 @@ 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 === modified file 'src/helper.cc' --- src/helper.cc 2011-11-22 12:00:59 +0000 +++ src/helper.cc 2011-11-24 07:52:12 +0000 @@ -33,6 +33,7 @@ */ #include "squid.h" +#include "base/AsyncCbdataCalls.h" #include "comm.h" #include "comm/Connection.h" #include "comm/Write.h" @@ -53,8 +54,8 @@ static IOCB helperHandleRead; static IOCB helperStatefulHandleRead; -static CLCB helperServerFree; -static CLCB helperStatefulServerFree; +static void helperServerFree(helper_server *srv); +static void helperStatefulServerFree(helper_stateful_server *srv); static void Enqueue(helper * hlp, helper_request *); static helper_request *Dequeue(helper * hlp); static helper_stateful_request *StatefulDequeue(statefulhelper * hlp); @@ -76,6 +77,37 @@ CBDATA_CLASS_INIT(statefulhelper); CBDATA_TYPE(helper_stateful_server); +#if 0 +// dialer to run cbdata object members as Async Calls +// to ease the transition of these cbdata objects to full Jobs +template +class UnaryCbdataDialer : public CallDialer +{ +public: + typedef T Params; + typedef void Handler(T *); + + UnaryCbdataDialer(Handler *aHandler, Params *aParam) : + data(cbdataReference(aParam)), + handler(aHandler) + {} + + ~UnaryCbdataDialer() { cbdataReferenceDone(data); } + + bool canDial(AsyncCall &call) { return true; } + void dial(AsyncCall &call) { + if (cbdataReferenceValid(data)) + handler(data); + } + + void print(std::ostream &os) const {} // dummy for now. + +public: + Params *data; + Handler *handler; +}; +#endif + void HelperServerBase::closePipesSafely() { @@ -233,7 +265,8 @@ if (wfd != rfd) commSetNonBlocking(wfd); - comm_add_close_handler(rfd, helperServerFree, srv); + AsyncCall::Pointer closeCall = asyncCall(5,4, "helperServerFree", cbdataDialer(helperServerFree, srv)); + comm_add_close_handler(rfd, closeCall); AsyncCall::Pointer call = commCbCall(5,4, "helperHandleRead", CommIoCbPtrFun(helperHandleRead, srv)); @@ -353,7 +386,8 @@ if (wfd != rfd) commSetNonBlocking(wfd); - comm_add_close_handler(rfd, helperStatefulServerFree, srv); + AsyncCall::Pointer closeCall = asyncCall(5,4, "helperStatefulServerFree", cbdataDialer(helperStatefulServerFree, srv)); + comm_add_close_handler(rfd, closeCall); AsyncCall::Pointer call = commCbCall(5,4, "helperStatefulHandleRead", CommIoCbPtrFun(helperStatefulHandleRead, srv)); @@ -669,9 +703,8 @@ /* ====================================================================== */ static void -helperServerFree(const CommCloseCbParams ¶ms) +helperServerFree(helper_server *srv) { - helper_server *srv = (helper_server *)params.data; helper *hlp = srv->parent; helper_request *r; int i, concurrency = hlp->childs.concurrency; @@ -704,7 +737,7 @@ if (!srv->flags.shutdown) { assert(hlp->childs.n_active > 0); hlp->childs.n_active--; - debugs(84, DBG_CRITICAL, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " (FD " << params.fd << ") exited"); + debugs(84, DBG_CRITICAL, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " exited"); if (hlp->childs.needNew() > 0) { debugs(80, 1, "Too few " << hlp->id_name << " processes are running (need " << hlp->childs.needNew() << "/" << hlp->childs.n_max << ")"); @@ -736,9 +769,8 @@ } static void -helperStatefulServerFree(const CommCloseCbParams ¶ms) +helperStatefulServerFree(helper_stateful_server *srv) { - helper_stateful_server *srv = (helper_stateful_server *)params.data; statefulhelper *hlp = srv->parent; helper_stateful_request *r; @@ -766,7 +798,7 @@ if (!srv->flags.shutdown) { assert( hlp->childs.n_active > 0); hlp->childs.n_active--; - debugs(84, 0, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " (FD " << params.fd << ") exited"); + debugs(84, 0, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " exited"); if (hlp->childs.needNew() > 0) { debugs(80, 1, "Too few " << hlp->id_name << " processes are running (need " << hlp->childs.needNew() << "/" << hlp->childs.n_max << ")"); === modified file 'src/helper.h' --- src/helper.h 2011-05-13 08:13:01 +0000 +++ src/helper.h 2011-11-24 07:58:18 +0000 @@ -34,6 +34,7 @@ #define SQUID_HELPER_H #include "squid.h" +#include "base/AsyncCall.h" #include "cbdata.h" #include "comm/forward.h" #include "ip/Address.h" @@ -128,7 +129,6 @@ unsigned int shutdown:1; unsigned int reserved:1; } flags; - }; class helper_server : public HelperServerBase @@ -144,6 +144,9 @@ int uses; unsigned int pending; } stats; + +private: + CBDATA_CLASS2(helper_server); }; class helper_stateful_request; @@ -163,6 +166,9 @@ int releases; } stats; void *data; /* State data used by the calling routines */ + +private: + CBDATA_CLASS2(helper_stateful_server); }; class helper_request