From: rousskov <> Date: Wed, 13 Feb 2008 06:51:37 +0000 (+0000) Subject: Merging async-call branch changes to HEAD: X-Git-Tag: BASIC_TPROXY4~98 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1fab16b88693a2660c2939afd2f78ec1ab2f005;p=thirdparty%2Fsquid.git Merging async-call branch changes to HEAD: Async-call work replaces event-based asynchronous calls with stand-alone implementation. The common async call API allows Squid core do call, debug, and troubleshoot all callback handlers in a uniform way. An async "job" API is introduced to manage independent logical threads or work such as protocol transaction handlers on client, server, and ICAP sides. These jobs should communicate with each other using async calls to minimize dependencies and avoid reentrant callback loops. These changes will eventually improve overall code quality, debugging quality, and Squid robustness. Below you will find log messages from the async-call branch that are relevant to the file(s) being committed. Added initial implelentation of AsyncCall-based wrappers for comm callbacks. The comm layer no longer calls callbacks from the select loop. Instead, the select loop schedules async calls. Scheduled calls are then called from the main loop (like all other async calls), after the select loop completes. Removed accept loop. We cannot loop because async calls do not get fired during the loop and, hence, cannot register new callbacks for new ready FDs. The loop is implicit now. When the next callback is registered, we check whether the last accept(2) call was successful or OPTIMISTIC_IO is defined and call acceptNext() again if yes. AcceptNext() may schedule another async call (using the being-submitted callback) if the socket was still ready. Since callbacks are fired until there are no callabacks left, we still have an accept loop. Removed CommDispatcher as unused. Removed unused IOFCB, IOWCB, and CWCB. Removed class fdc_t. After CommCallbackData removal, fdc_t was only used to check that a FD is "active" and to check that a FD is half_closed. fd_table flags.open seems to be identical to the "active" state flag so we use that now, via newly added isOpen() static function. AbortChecker already maintains half_closed status. The accept-specific functionality is still implemented by AcceptFD class. Removed fdc_t used to marshall accept-ralted calls to AcceptFD anyway. fdc_table now stores AcceptFDs directly. I did not rename the table to ease merging with other code, but added a TODO for that. Removed calls to comm_iocallbackpending(). They were added to "Speed up processing of queued events significantly, to not cause large delays when under low load" but I do not see how having pending callbacks can be relevant because all pending callbacks are (should be) executed before FDs are probed. Removed unused nullCallback() methods. Removed CommCallbackData and related code. It looks like it remained after one of the big comm rewrites, just to handle accept errors. We can now schedule an async call to notify of those errors and do not seem to need CommCallbackData at all. Removed commfd_completed_events: a list of completed (but not yet fired) callbacks. We simply schedule the async call now instead of maintaining our own list of callbacks to call. This change allows us to eliminate the CommDispatcher class (which was the motivation behind these changes), but I have not done that yet. For comm_io_callback_t, being active seems to be the same as having a callback. Replaced active data member with a method that checks for the callback presence. Relaxed comm_read_cancel() preconditions so that the callers do not have to check all the assertions inside before calling that function. --- diff --git a/src/CommRead.h b/src/CommRead.h index 25202e80d6..6b7d2a24f8 100644 --- a/src/CommRead.h +++ b/src/CommRead.h @@ -1,6 +1,6 @@ /* - * $Id: CommRead.h,v 1.8 2007/04/25 11:30:18 adrian Exp $ + * $Id: CommRead.h,v 1.9 2008/02/12 23:51:37 rousskov Exp $ * * DEBUG: section 5 Comms * AUTHOR: Robert Collins @@ -42,92 +42,15 @@ #include "squid.h" #include "comm.h" +#include "CommCalls.h" #include "List.h" -template - -class CallBack -{ - -public: - CallBack() : handler(NULL), data(NULL){} - - CallBack(C *aHandler, void *someData) : handler(aHandler), data (NULL) - { - if (someData) - data = cbdataReference(someData); - } - - CallBack(CallBack const &old) : handler(old.handler) - { - if (old.data) - data = cbdataReference (old.data); - else - data = NULL; - } - - ~CallBack() - { - replaceData (NULL); - } - - CallBack &operator = (CallBack const & rhs) - { - handler = rhs.handler; - - replaceData (rhs.data); - - return *this; - } - - bool dataValid() - { - return cbdataReferenceValid(data); - } - - bool operator == (CallBack const &rhs) { return handler==rhs.handler && data==rhs.data;} - -#if 0 - // twould be nice - RBC 20030307 - C callback; -#endif - - C *handler; - void *data; - -private: - void replaceData(void *someData) - { - void *temp = NULL; - - if (someData) - temp = cbdataReference(someData); - - if (data) - cbdataReferenceDone(data); - - data = temp; - } -}; - -#if 0 -// twould be nice - RBC 20030307 -void -CallBack::callback(int fd, char *buf, size_t size , comm_err_t errcode, int xerrno, void *tempData) -{ - assert (tempData == data); - handler (fd, buf, size , errcode, xerrno, data); - *this = CallBack(); -} - -#endif - class CommRead { public: CommRead (); - CommRead (int fd, char *buf, int len, IOCB *handler, void *data); + CommRead (int fd, char *buf, int len, AsyncCall::Pointer &callback); void queueCallback(size_t retval, comm_err_t errcode, int xerrno); bool hasCallback() const; void hasCallbackInvariant() const; @@ -135,12 +58,11 @@ public: void tryReading(); void read(); void initiateActualRead(); - void nullCallback(); void doCallback(comm_err_t errcode, int xerrno); int fd; char *buf; int len; - CallBack callback; + AsyncCall::Pointer callback; static void ReadTry(int fd, void *data); };