--------------------- PatchSet 6421 Date: 2007/12/24 16:46:49 Author: chtsanti Branch: async-calls Tag: (none) Log: comm_close handlers now scheduled as CommCalls. Major additions/changes: - Add comm_add_close_handler,comm_remove_close_handler functions which takes an AsyncCall as argument - commCallCloseHandlers, comm_add_close_handler and comm_remove_close_handler modified to use CommCalls - Add the CommCloseCbParams and CommCloseCbPtrFun classes TODO: - Convert comm_close handlers to use AsyncCalls - Implement the fde::closeHandler as a list of AsyncCalls and remove the newly added (added in this patch) AsyncCall::setNext and AsyncCall::Next methods - Check again and again if all are OK with comm_close handlers Members: src/AsyncCall.h:1.3.22.19->1.3.22.20 src/CommCalls.cc:1.1.2.2->1.1.2.3 src/CommCalls.h:1.1.2.3->1.1.2.4 src/comm.cc:1.81.4.12->1.81.4.13 src/comm.h:1.26.4.9->1.26.4.10 src/fde.h:1.14->1.14.4.1 Index: squid3/src/AsyncCall.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/AsyncCall.h,v retrieving revision 1.3.22.19 retrieving revision 1.3.22.20 diff -u -r1.3.22.19 -r1.3.22.20 --- squid3/src/AsyncCall.h 21 Dec 2007 15:01:14 -0000 1.3.22.19 +++ squid3/src/AsyncCall.h 24 Dec 2007 16:46:50 -0000 1.3.22.20 @@ -1,6 +1,6 @@ /* - * $Id: AsyncCall.h,v 1.3.22.19 2007/12/21 15:01:14 chtsanti Exp $ + * $Id: AsyncCall.h,v 1.3.22.20 2007/12/24 16:46:50 chtsanti Exp $ */ #ifndef SQUID_ASYNCCALL_H @@ -44,10 +44,20 @@ // can be called from canFire() for debugging; always returns false bool cancel(const char *reason); + + bool canceled() { return isCanceled != NULL; } virtual CallDialer *getDialer() = 0; void print(std::ostream &os); + + void setNext(AsyncCall::Pointer aNext) { + theNext = aNext; + } + + AsyncCall::Pointer &Next() { + return theNext; + } public: const char *const name; Index: squid3/src/CommCalls.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/CommCalls.cc,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/src/CommCalls.cc 5 Dec 2007 04:42:06 -0000 1.1.2.2 +++ squid3/src/CommCalls.cc 24 Dec 2007 16:46:50 -0000 1.1.2.3 @@ -73,6 +73,14 @@ } +/* CommCloseCbParams */ + +CommCloseCbParams::CommCloseCbParams(void *aData): + CommCommonCbParams(aData) +{ +} + + /* CommAcceptCbPtrFun */ CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler, @@ -143,3 +151,26 @@ os << ')'; } + +/* CommCloseCbPtrFun */ + +CommCloseCbPtrFun::CommCloseCbPtrFun(PF *aHandler, + const CommCloseCbParams &aParams): + CommDialerParamsT(aParams), + handler(aHandler) +{ +} + +void +CommCloseCbPtrFun::dial() +{ + handler(params.fd, params.data); +} + +void +CommCloseCbPtrFun::print(std::ostream &os) const +{ + os << '('; + params.print(os); + os << ')'; +} Index: squid3/src/CommCalls.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/CommCalls.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid3/src/CommCalls.h 21 Dec 2007 15:01:14 -0000 1.1.2.3 +++ squid3/src/CommCalls.h 24 Dec 2007 16:46:50 -0000 1.1.2.4 @@ -1,6 +1,6 @@ /* - * $Id: CommCalls.h,v 1.1.2.3 2007/12/21 15:01:14 chtsanti Exp $ + * $Id: CommCalls.h,v 1.1.2.4 2007/12/24 16:46:50 chtsanti Exp $ */ #ifndef SQUID_COMMCALLS_H @@ -84,6 +84,11 @@ size_t size; }; +// close parameters +class CommCloseCbParams: public CommCommonCbParams { +public: + CommCloseCbParams(void *aData); +}; // Interface to expose comm callback parameters of all comm dialers. // GetCommParams() uses this interface to access comm parameters. @@ -181,6 +186,22 @@ }; +// close (PF) dialer +class CommCloseCbPtrFun: public CallDialer, + public CommDialerParamsT +{ +public: + typedef CommCloseCbParams Params; + + CommCloseCbPtrFun(PF *aHandler, const Params &aParams); + void dial(); + + virtual void print(std::ostream &os) const; + +public: + PF *handler; +}; + // AsyncCall to comm handlers implemented as global functions. // The dialer is one of the Comm*CbPtrFunT above Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.81.4.12 retrieving revision 1.81.4.13 diff -u -r1.81.4.12 -r1.81.4.13 --- squid3/src/comm.cc 21 Dec 2007 15:01:14 -0000 1.81.4.12 +++ squid3/src/comm.cc 24 Dec 2007 16:46:50 -0000 1.81.4.13 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.81.4.12 2007/12/21 15:01:14 chtsanti Exp $ + * $Id: comm.cc,v 1.81.4.13 2007/12/24 16:46:50 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1142,16 +1142,17 @@ debugs(5, 5, "commCallCloseHandlers: FD " << fd); while (F->closeHandler != NULL) { - close_handler ch = *F->closeHandler; - conn_close_pool->free(F->closeHandler); /* AAA */ - F->closeHandler = ch.next; - ch.next = NULL; - debugs(5, 5, "commCallCloseHandlers: ch->handler=" << ch.handler << " data=" << ch.data); - - if (cbdataReferenceValid(ch.data)) - ch.handler(fd, ch.data); - - cbdataReferenceDone(ch.data); + AsyncCall::Pointer call = F->closeHandler; + F->closeHandler = call->Next(); + call->setNext(NULL); + // If call is not canceled schedule it for execution else ignore it + if(!call->canceled()){ + debugs(5, 5, "commCallCloseHandlers: ch->handler=" << call); + typedef CommCloseCbParams Params; + Params ¶ms = GetCommParams(call); + params.fd = fd; + ScheduleCallHere(call); + } } } @@ -1360,48 +1361,63 @@ void comm_add_close_handler(int fd, PF * handler, void *data) { - close_handler *newHandler = (close_handler *)conn_close_pool->alloc(); /* AAA */ - close_handler *c; debugs(5, 5, "comm_add_close_handler: FD " << fd << ", handler=" << handler << ", data=" << data); - for (c = fd_table[fd].closeHandler; c; c = c->next) - assert(c->handler != handler || c->data != data); + AsyncCall::Pointer call=commCbCall(5,4, "SomeCloseHandler", + CommCloseCbPtrFun(handler, data)); + comm_add_close_handler(fd, call); +} - newHandler->handler = handler; +void +comm_add_close_handler(int fd, AsyncCall::Pointer &call) +{ + debugs(5, 5, "comm_add_close_handler: FD " << fd << ", AsyncCall=" << call); - newHandler->data = cbdataReference(data); + /*TODO:Check for a similar scheduled AsyncCall*/ +// for (c = fd_table[fd].closeHandler; c; c = c->next) +// assert(c->handler != handler || c->data != data); - newHandler->next = fd_table[fd].closeHandler; + call->setNext(fd_table[fd].closeHandler); - fd_table[fd].closeHandler = newHandler; + fd_table[fd].closeHandler = call; } + void comm_remove_close_handler(int fd, PF * handler, void *data) { assert (isOpen(fd)); - close_handler *p = NULL; - close_handler *last = NULL; /* Find handler in list */ debugs(5, 5, "comm_remove_close_handler: FD " << fd << ", handler=" << handler << ", data=" << data); - for (p = fd_table[fd].closeHandler; p != NULL; last = p, p = p->next) - if (p->handler == handler && p->data == data) + AsyncCall::Pointer p; + for (p = fd_table[fd].closeHandler; p != NULL; p = p->Next()){ + typedef CommCbFunPtrCallT Call; + typedef CommCloseCbParams Params; + Call *aCall = dynamic_cast(p.getRaw()); + Params ¶ms = GetCommParams(p); + if (aCall->dialer.handler == handler && params.data == data) break; /* This is our handler */ - + } assert(p != NULL); + p->cancel("comm_remove_close_handler"); +} - /* Remove list entry */ - if (last) - last->next = p->next; - else - fd_table[fd].closeHandler = p->next; +void +comm_remove_close_handler(int fd, AsyncCall::Pointer &call) +{ + assert (isOpen(fd)); + /* Find handler in list */ + debugs(5, 5, "comm_remove_close_handler: FD " << fd << ", AsyncCall=" << call); - cbdataReferenceDone(p->data); + // Check to see if really exist the given AsyncCall in comm_close handlers + AsyncCall::Pointer p; + for (p = fd_table[fd].closeHandler; p != NULL && p != call; p = p->Next()); + assert(p == call); - conn_close_pool->free(p); + call->cancel("comm_remove_close_handler"); } static void Index: squid3/src/comm.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.h,v retrieving revision 1.26.4.9 retrieving revision 1.26.4.10 diff -u -r1.26.4.9 -r1.26.4.10 --- squid3/src/comm.h 21 Dec 2007 15:01:15 -0000 1.26.4.9 +++ squid3/src/comm.h 24 Dec 2007 16:46:49 -0000 1.26.4.10 @@ -79,7 +79,10 @@ typedef void IOACB(int fd, int nfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data); extern void comm_accept(int fd, IOACB *handler, void *handler_data); extern void comm_add_close_handler(int fd, PF *, void *); +extern void comm_add_close_handler(int fd, AsyncCall::Pointer &); extern void comm_remove_close_handler(int fd, PF *, void *); +extern void comm_remove_close_handler(int fd, AsyncCall::Pointer &); + extern int comm_has_pending_read_callback(int fd); extern bool comm_monitors_read(int fd); Index: squid3/src/fde.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fde.h,v retrieving revision 1.14 retrieving revision 1.14.4.1 diff -u -r1.14 -r1.14.4.1 --- squid3/src/fde.h 13 Aug 2007 17:24:15 -0000 1.14 +++ squid3/src/fde.h 24 Dec 2007 16:46:49 -0000 1.14.4.1 @@ -1,6 +1,6 @@ /* - * $Id: fde.h,v 1.14 2007/08/13 17:24:15 squidadm Exp $ + * $Id: fde.h,v 1.14.4.1 2007/12/24 16:46:49 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -94,7 +94,7 @@ time_t timeout; void *timeout_data; void *lifetime_data; - close_handler *closeHandler; /* linked list */ + AsyncCall::Pointer closeHandler; CommWriteStateData *wstate; /* State data for comm_write */ READ_HANDLER *read_method; WRITE_HANDLER *write_method;