--------------------- PatchSet 6727 Date: 2008/01/28 17:15:21 Author: rousskov Branch: async-calls Tag: (none) Log: Polished comm_remove_close_handler for function-based handlers and explained why the loop inside skips some handlers. Noted that the slow code in comm_remove_close_handler for method-based handlers is only needed to assert() something. It should probably not be compiled unless --disable-optimizations or a similar option is given. Members: src/comm.cc:1.81.4.21->1.81.4.22 Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.81.4.21 retrieving revision 1.81.4.22 diff -u -r1.81.4.21 -r1.81.4.22 --- squid3/src/comm.cc 24 Jan 2008 03:45:19 -0000 1.81.4.21 +++ squid3/src/comm.cc 28 Jan 2008 17:15:21 -0000 1.81.4.22 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.81.4.21 2008/01/24 03:45:19 rousskov Exp $ + * $Id: comm.cc,v 1.81.4.22 2008/01/28 17:15:21 rousskov Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1595,6 +1595,7 @@ } +// remove function-based close handler void comm_remove_close_handler(int fd, PF * handler, void *data) { @@ -1605,19 +1606,21 @@ 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()); - if(aCall == NULL) - continue; - Params ¶ms = GetCommParams(p); - if (aCall->dialer.handler == handler && params.data == data) + typedef CommCbFunPtrCallT Call; + const Call *call = dynamic_cast(p.getRaw()); + if (!call) // method callbacks have their own comm_remove_close_handler + continue; + + typedef CommCloseCbParams Params; + const Params ¶ms = GetCommParams(p); + if (call->dialer.handler == handler && params.data == data) break; /* This is our handler */ } assert(p != NULL); p->cancel("comm_remove_close_handler"); } +// remove method-based close handler void comm_remove_close_handler(int fd, AsyncCall::Pointer &call) { @@ -1625,7 +1628,8 @@ /* Find handler in list */ debugs(5, 5, "comm_remove_close_handler: FD " << fd << ", AsyncCall=" << call); - // Check to see if really exist the given AsyncCall in comm_close handlers + // Check to see if really exist the given AsyncCall in comm_close handlers + // TODO: optimize: this slow code is only needed for the assert() below AsyncCall::Pointer p; for (p = fd_table[fd].closeHandler; p != NULL && p != call; p = p->Next()); assert(p == call);