ConnectionHandle.h (1326B)
1 /* vim:set ts=4 sw=2 sts=2 et cin: */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef ConnectionHandle_h__ 7 #define ConnectionHandle_h__ 8 9 #include "nsAHttpConnection.h" 10 #include "HttpConnectionBase.h" 11 12 namespace mozilla { 13 namespace net { 14 15 //----------------------------------------------------------------------------- 16 // ConnectionHandle 17 // 18 // thin wrapper around a real connection, used to keep track of references 19 // to the connection to determine when the connection may be reused. the 20 // transaction owns a reference to this handle. this extra 21 // layer of indirection greatly simplifies consumer code, avoiding the 22 // need for consumer code to know when to give the connection back to the 23 // connection manager. 24 // 25 class ConnectionHandle : public nsAHttpConnection { 26 public: 27 NS_INLINE_DECL_REFCOUNTING_INHERITED(ConnectionHandle, nsAHttpConnection) 28 NS_DECL_NSAHTTPCONNECTION(mConn) 29 30 explicit ConnectionHandle(HttpConnectionBase* conn) : mConn(conn) {} 31 void Reset() { mConn = nullptr; } 32 33 private: 34 virtual ~ConnectionHandle(); 35 RefPtr<HttpConnectionBase> mConn; 36 }; 37 38 } // namespace net 39 } // namespace mozilla 40 41 #endif // ConnectionHandle_h__