From: Amos Jeffries Date: Thu, 23 Sep 2010 13:51:14 +0000 (-0600) Subject: Author: Alex Rousskov X-Git-Tag: SQUID_3_1_9~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c9be1ba34a82fc1d44f8f0432ab71ed1d611370;p=thirdparty%2Fsquid.git Author: Alex Rousskov Added HttpMsg::Pointer typedef and convenience HttpMsg::Pointer operators. --- diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 36876db547..1da6b01118 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -42,10 +42,16 @@ // common parts of HttpRequest and HttpReply +template +class HttpMsgPointerT; + + class HttpMsg { public: + typedef HttpMsgPointerT Pointer; + HttpMsg(http_hdr_owner_type owner); virtual ~HttpMsg(); @@ -186,6 +192,17 @@ public: HttpMsgPointerT(const HttpMsgPointerT &p): msg(p.msg) { lock(); } HttpMsgPointerT &operator =(const HttpMsgPointerT &p) { if (msg != p.msg) { unlock(); msg = p.msg; lock(); } return *this; } + HttpMsgPointerT &operator =(Msg *newM) + { if (msg != newM) { unlock(); msg = newM; lock(); } return *this; } + + /// support converting a child msg pointer into a parent msg pointer + template + HttpMsgPointerT(const HttpMsgPointerT &o): msg(o.raw()) { lock(); } + + /// support assigning a child msg pointer to a parent msg pointer + template + HttpMsgPointerT &operator =(const HttpMsgPointerT &o) + { if (msg != o.raw()) { unlock(); msg = o.raw(); lock(); } return *this; } Msg &operator *() { return *msg; } const Msg &operator *() const { return *msg; } @@ -195,6 +212,9 @@ public: operator const Msg *() const { return msg; } // add more as needed + /// public access for HttpMsgPointerT copying and assignment; avoid + Msg *raw() const { return msg; } + protected: void lock() { if (msg) HTTPMSGLOCK(msg); } ///< prevent msg destruction void unlock() { HTTPMSGUNLOCK(msg); } ///< allows/causes msg destruction diff --git a/src/HttpReply.h b/src/HttpReply.h index 9bd8c46ec1..33b471d4a9 100644 --- a/src/HttpReply.h +++ b/src/HttpReply.h @@ -52,6 +52,8 @@ class HttpReply: public HttpMsg { public: + typedef HttpMsgPointerT Pointer; + MEMPROXY_CLASS(HttpReply); HttpReply(); ~HttpReply(); diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 6857bcdf31..119d63c052 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -65,6 +65,8 @@ class HttpRequest: public HttpMsg { public: + typedef HttpMsgPointerT Pointer; + MEMPROXY_CLASS(HttpRequest); HttpRequest(); HttpRequest(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath);