From: Amos Jeffries Date: Tue, 3 Feb 2015 11:50:49 +0000 (-0800) Subject: Cleanup: migrate clientStreamNode to CBDATA_CLASS API X-Git-Tag: merge-candidate-3-v1~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b48636132c372f3cc0347f5f84f78caa9c8d486c;p=thirdparty%2Fsquid.git Cleanup: migrate clientStreamNode to CBDATA_CLASS API --- diff --git a/src/clientStream.cc b/src/clientStream.cc index eceff1cc38..e0ca21e595 100644 --- a/src/clientStream.cc +++ b/src/clientStream.cc @@ -44,7 +44,7 @@ \par * Each node including the HEAD of the clientStream has a cbdataReference * held by the stream. Freeing the stream then removes that reference - * and cbdataFree()'s every node. + * and delete's every node. * Any node with other References, and all nodes downstream will only * free when those references are released. * Stream nodes MAY hold references to the data member of the node. @@ -72,7 +72,7 @@ \code mycontext = thisObject->data; thisObject->data = NULL; - clientStreamFree (thisObject->head); + delete thisObject->head; mycontext = NULL; return; \endcode @@ -80,26 +80,22 @@ \todo rather than each node undeleting the next, have a clientStreamDelete that walks the list. */ -/// \ingroup ClientStreamInternal -CBDATA_TYPE(clientStreamNode); +CBDATA_CLASS_INIT(clientStreamNode); -/* Local functions */ -static FREE clientStreamFree; +clientStreamNode::clientStreamNode(CSR * aReadfunc, CSCB * aCallback, CSD * aDetach, CSS * aStatus, ClientStreamData aData) : + readfunc(aReadfunc), + callback(aCallback), + detach(aDetach), + status(aStatus), + data(aData) +{} -/// \ingroup ClientStreamInternal -clientStreamNode * -clientStreamNew(CSR * readfunc, CSCB * callback, CSD * detach, CSS * status, - ClientStreamData data) +clientStreamNode::~clientStreamNode() { - clientStreamNode *temp; - CBDATA_INIT_TYPE_FREECB(clientStreamNode, clientStreamFree); - temp = cbdataAlloc(clientStreamNode); - temp->readfunc = readfunc; - temp->callback = callback; - temp->detach = detach; - temp->status = status; - temp->data = data; - return temp; + debugs(87, 3, "Freeing clientStreamNode " << this); + + removeFromStream(); + data = NULL; } /** @@ -115,8 +111,7 @@ clientStreamInit(dlink_list * list, CSR * func, CSD * rdetach, CSS * readstatus, ClientStreamData readdata, CSCB * callback, CSD * cdetach, ClientStreamData callbackdata, StoreIOBuffer tailBuffer) { - clientStreamNode *temp = clientStreamNew(func, NULL, rdetach, readstatus, - readdata); + clientStreamNode *temp = new clientStreamNode(func, NULL, rdetach, readstatus, readdata); dlinkAdd(cbdataReference(temp), &temp->node, list); temp->head = list; clientStreamInsertHead(list, NULL, callback, cdetach, NULL, callbackdata); @@ -134,11 +129,10 @@ void clientStreamInsertHead(dlink_list * list, CSR * func, CSCB * callback, CSD * detach, CSS * status, ClientStreamData data) { - /* test preconditions */ assert(list != NULL); assert(list->head); - clientStreamNode *temp = clientStreamNew(func, callback, detach, status, data); + clientStreamNode *temp = new clientStreamNode(func, callback, detach, status, data); temp->head = list; debugs(87, 3, "clientStreamInsertHead: Inserted node " << temp << " with data " << data.getRaw() << " after head"); @@ -211,7 +205,7 @@ clientStreamDetach(clientStreamNode * thisObject, ClientHttpRequest * http) cbdataReferenceDone(temp); - cbdataFree(thisObject); + delete thisObject; /* and tell the prev that the detach has occured */ /* @@ -267,8 +261,6 @@ clientStreamStatus(clientStreamNode * thisObject, ClientHttpRequest * http) return prev->status(prev, http); } -/* Local function bodies */ - void clientStreamNode::removeFromStream() { @@ -278,18 +270,6 @@ clientStreamNode::removeFromStream() head = NULL; } -/// \ingroup ClientStreamInternal -void -clientStreamFree(void *foo) -{ - clientStreamNode *thisObject = (clientStreamNode *)foo; - - debugs(87, 3, "Freeing clientStreamNode " << thisObject); - - thisObject->removeFromStream(); - thisObject->data = NULL; -} - clientStreamNode * clientStreamNode::prev() const { diff --git a/src/clientStream.h b/src/clientStream.h index 8a7286473c..bb6fd6d632 100644 --- a/src/clientStream.h +++ b/src/clientStream.h @@ -73,14 +73,18 @@ \li Because of the callback nature of squid, every node would have to keep these parameters in their context anyway, so this reduces programmer overhead. */ -/// \ingroup ClientStreamAPI class clientStreamNode { + CBDATA_CLASS(clientStreamNode); public: + clientStreamNode(CSR * aReadfunc, CSCB * aCallback, CSD * aDetach, CSS * aStatus, ClientStreamData); + ~clientStreamNode(); + clientStreamNode *prev() const; clientStreamNode *next() const; void removeFromStream(); + dlink_node node; dlink_list *head; /* sucks I know, but hey, the interface is limited */ CSR *readfunc; @@ -97,9 +101,6 @@ void clientStreamInit(dlink_list *, CSR *, CSD *, CSS *, ClientStreamData, CSCB /// \ingroup ClientStreamAPI void clientStreamInsertHead(dlink_list *, CSR *, CSCB *, CSD *, CSS *, ClientStreamData); -/// \ingroup ClientStreamAPI -clientStreamNode *clientStreamNew(CSR *, CSCB *, CSD *, CSS *, ClientStreamData); - /** \ingroup ClientStreamAPI *