From: Amos Jeffries Date: Sun, 7 Apr 2013 12:32:06 +0000 (-0600) Subject: Polish: TunnelStateData constructor/destructor X-Git-Tag: SQUID_3_4_0_1~207 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ca1d33d058ab61ba6cd5c965c5e6c4e25a4dca5;p=thirdparty%2Fsquid.git Polish: TunnelStateData constructor/destructor * convert the C-style tunnelStateFree() functio to a proper destructor. * create a proper constructor for TunnelStateData * include debugging for trace-job.pl to track tunnel jobs setup/teardown --- diff --git a/src/tunnel.cc b/src/tunnel.cc index 34a4fda03f..4eb6b19d4f 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -63,10 +63,27 @@ #include #endif +/** + * TunnelStateData is the state engine performing the tasks for + * setup of a TCP tunnel from an existing open client FD to a server + * then shuffling binary data between the resulting FD pair. + */ +/* + * TODO 1: implement a read/write API on ConnStateData to send/receive blocks + * of pre-formatted data. Then we can use that as the client side of the tunnel + * instead of re-implementing it here and occasionally getting the ConnStateData + * read/write state wrong. + * + * TODO 2: then convert this into a AsyncJob, possibly a child of 'Server' + */ class TunnelStateData { public: + TunnelStateData(); + ~TunnelStateData(); + TunnelStateData(const TunnelStateData &); // do not implement + TunnelStateData &operator =(const TunnelStateData &); // do not implement class Connection; void *operator new(size_t); @@ -139,7 +156,6 @@ static CLCB tunnelServerClosed; static CLCB tunnelClientClosed; static CTCB tunnelTimeout; static PSC tunnelPeerSelectComplete; -static void tunnelStateFree(TunnelStateData * tunnelState); static void tunnelConnected(const Comm::ConnectionPointer &server, void *); static void tunnelRelayConnectRequest(const Comm::ConnectionPointer &server, void *); @@ -151,7 +167,7 @@ tunnelServerClosed(const CommCloseCbParams ¶ms) tunnelState->server.conn = NULL; if (tunnelState->noConnections()) { - tunnelStateFree(tunnelState); + delete tunnelState; return; } @@ -169,7 +185,7 @@ tunnelClientClosed(const CommCloseCbParams ¶ms) tunnelState->client.conn = NULL; if (tunnelState->noConnections()) { - tunnelStateFree(tunnelState); + delete tunnelState; return; } @@ -179,16 +195,21 @@ tunnelClientClosed(const CommCloseCbParams ¶ms) } } -static void -tunnelStateFree(TunnelStateData * tunnelState) +TunnelStateData::TunnelStateData() : + url(NULL), + request(NULL), + status_ptr(NULL) { - debugs(26, 3, HERE << "tunnelState=" << tunnelState); - assert(tunnelState != NULL); - assert(tunnelState->noConnections()); - safe_free(tunnelState->url); - tunnelState->serverDestinations.clean(); - HTTPMSGUNLOCK(tunnelState->request); - delete tunnelState; + debugs(26, 3, "TunnelStateData constructed this=" << this); +} + +TunnelStateData::~TunnelStateData() +{ + debugs(26, 3, "TunnelStateData destructed this=" << this); + assert(noConnections()); + xfree(url); + serverDestinations.clean(); + HTTPMSGUNLOCK(request); } TunnelStateData::Connection::~Connection()