From: Amos Jeffries Date: Sun, 5 Jan 2014 19:49:23 +0000 (-0800) Subject: Cleanup: remove ClientSocketContextNew() wrapper function X-Git-Tag: SQUID_3_5_0_1~433 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bead5d2c9c529e12b9794629fc68c137a232f2b6;p=thirdparty%2Fsquid.git Cleanup: remove ClientSocketContextNew() wrapper function This wrapper function for the ClientSocketContext default constructor is better performed as an explicit parametered constructor which prevents accidental use of the default constructor leading to invalid state after creation (a context always requires connectino and parent pointers). --- diff --git a/src/client_side.cc b/src/client_side.cc index a68280d584..b5a00a3527 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -194,9 +194,6 @@ static void clientListenerConnectionOpened(AnyP::PortCfg *s, const Ipc::FdNoteId CBDATA_CLASS_INIT(ClientSocketContext); /* Local functions */ -/* ClientSocketContext */ -static ClientSocketContext *ClientSocketContextNew(const Comm::ConnectionPointer &clientConn, ClientHttpRequest *); -/* other */ static IOCB clientWriteComplete; static IOCB clientWriteBodyComplete; static IOACB httpAccept; @@ -337,11 +334,16 @@ ClientSocketContext::connIsFinished() clientStreamDetach(getTail(), http); } -ClientSocketContext::ClientSocketContext() : http(NULL), reply(NULL), next(NULL), +ClientSocketContext::ClientSocketContext(const Comm::ConnectionPointer &aConn, ClientHttpRequest *aReq) : + clientConnection(aConn), + http(aReq), + reply(NULL), + next(NULL), writtenToSocket(0), mayUseConnection_ (false), connRegistered_ (false) { + assert(http != NULL); memset (reqbuf, '\0', sizeof (reqbuf)); flags.deferred = 0; flags.parsed_ok = 0; @@ -349,17 +351,6 @@ ClientSocketContext::ClientSocketContext() : http(NULL), reply(NULL), next(NULL) deferredparams.rep = NULL; } -ClientSocketContext * -ClientSocketContextNew(const Comm::ConnectionPointer &client, ClientHttpRequest * http) -{ - ClientSocketContext *newContext; - assert(http != NULL); - newContext = new ClientSocketContext; - newContext->http = http; - newContext->clientConnection = client; - return newContext; -} - void ClientSocketContext::writeControlMsg(HttpControlMsg &msg) { @@ -1979,7 +1970,7 @@ parseHttpRequestAbort(ConnStateData * csd, const char *uri) http->req_sz = csd->in.notYetUsed; http->uri = xstrdup(uri); setLogUri (http, uri); - context = ClientSocketContextNew(csd->clientConnection, http); + context = new ClientSocketContext(csd->clientConnection, http); tempBuffer.data = context->reqbuf; tempBuffer.length = HTTP_REQBUF_SZ; clientStreamInit(&http->client_stream, clientGetMoreData, clientReplyDetach, @@ -2320,7 +2311,7 @@ parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_ http = new ClientHttpRequest(csd); http->req_sz = HttpParserRequestLen(hp); - result = ClientSocketContextNew(csd->clientConnection, http); + result = new ClientSocketContext(csd->clientConnection, http); tempBuffer.data = result->reqbuf; tempBuffer.length = HTTP_REQBUF_SZ; diff --git a/src/client_side.h b/src/client_side.h index ec95d11cc5..ddb3d52325 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -83,7 +83,7 @@ class ClientSocketContext : public RefCountable public: typedef RefCount Pointer; - ClientSocketContext(); + ClientSocketContext(const Comm::ConnectionPointer &aConn, ClientHttpRequest *aReq); ~ClientSocketContext(); bool startOfOutput() const; void writeComplete(const Comm::ConnectionPointer &conn, char *bufnotused, size_t size, comm_err_t errflag); diff --git a/src/tests/stub_client_side.cc b/src/tests/stub_client_side.cc index 77d9ff4692..2a167e0fee 100644 --- a/src/tests/stub_client_side.cc +++ b/src/tests/stub_client_side.cc @@ -4,8 +4,8 @@ #define STUB_API "client_side.cc" #include "tests/STUB.h" -ClientSocketContext::ClientSocketContext() STUB -ClientSocketContext::~ClientSocketContext() STUB +//ClientSocketContext::ClientSocketContext(const ConnectionPointer&, ClientHttpRequest*) STUB +//ClientSocketContext::~ClientSocketContext() STUB bool ClientSocketContext::startOfOutput() const STUB_RETVAL(false) void ClientSocketContext::writeComplete(const Comm::ConnectionPointer &conn, char *bufnotused, size_t size, comm_err_t errflag) STUB void ClientSocketContext::keepaliveNextRequest() STUB