From: Amos Jeffries Date: Sun, 4 Dec 2011 05:39:39 +0000 (-0700) Subject: CBDATA call Dialer template X-Git-Tag: BumpSslServerFirst.take05~12^2~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37dedc58e276153c2afeab768ced3694cac6d7e8;p=thirdparty%2Fsquid.git CBDATA call Dialer template This adds a template for dialing Unary CBDATA wrapper functions with type safety. Avoiding the casting that currently occurs in wrappers and allowing the AsyncCall APIs to be used for these callbacks. --- diff --git a/src/base/AsyncCbdataCalls.h b/src/base/AsyncCbdataCalls.h new file mode 100644 index 0000000000..f15763e364 --- /dev/null +++ b/src/base/AsyncCbdataCalls.h @@ -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, Argument1 *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 Dialer creation. +template +UnaryCbdataDialer +cbdataDialer(typename UnaryCbdataDialer::Handler *handler, Argument1 *arg1) +{ + return UnaryCbdataDialer(handler, arg1); +} + +#endif diff --git a/src/base/Makefile.am b/src/base/Makefile.am index 786671eae1..3ad8e4d2ec 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -7,6 +7,7 @@ noinst_LTLIBRARIES = libbase.la libbase_la_SOURCES = \ AsyncCall.cc \ AsyncCall.h \ + AsyncCbdataCalls.h \ AsyncJob.h \ AsyncJob.cc \ AsyncJobCalls.h \ diff --git a/src/helper.cc b/src/helper.cc index 724fd8b4d0..43e802faa7 100644 --- a/src/helper.cc +++ b/src/helper.cc @@ -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); @@ -233,7 +234,8 @@ helperOpenServers(helper * hlp) 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 +355,8 @@ helperStatefulOpenServers(statefulhelper * hlp) 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 +672,8 @@ helper::~helper() /* ====================================================================== */ 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 +706,7 @@ helperServerFree(const CommCloseCbParams ¶ms) 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 +738,8 @@ helperServerFree(const CommCloseCbParams ¶ms) } 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 +767,7 @@ helperStatefulServerFree(const CommCloseCbParams ¶ms) 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 << ")"); diff --git a/src/helper.h b/src/helper.h index 7d40becbce..a0ddcded4a 100644 --- a/src/helper.h +++ b/src/helper.h @@ -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" @@ -144,6 +145,9 @@ public: int uses; unsigned int pending; } stats; + +private: + CBDATA_CLASS2(helper_server); }; class helper_stateful_request; @@ -163,6 +167,9 @@ public: int releases; } stats; void *data; /* State data used by the calling routines */ + +private: + CBDATA_CLASS2(helper_stateful_server); }; class helper_request