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 // HttpLog.h should generally be included first
7 #include "HttpLog.h"
8 
9 // Log on level :5, instead of default :4.
10 #undef LOG
11 #define LOG(args) LOG5(args)
12 #undef LOG_ENABLED
13 #define LOG_ENABLED() LOG5_ENABLED()
14 
15 #include "ConnectionHandle.h"
16 
17 namespace mozilla {
18 namespace net {
19 
~ConnectionHandle()20 ConnectionHandle::~ConnectionHandle() {
21   if (mConn) {
22     nsresult rv = gHttpHandler->ReclaimConnection(mConn);
23     if (NS_FAILED(rv)) {
24       LOG(
25           ("ConnectionHandle::~ConnectionHandle\n"
26            "    failed to reclaim connection\n"));
27     }
28   }
29 }
30 
NS_IMPL_ISUPPORTS0(ConnectionHandle)31 NS_IMPL_ISUPPORTS0(ConnectionHandle)
32 
33 nsresult ConnectionHandle::OnHeadersAvailable(nsAHttpTransaction* trans,
34                                               nsHttpRequestHead* req,
35                                               nsHttpResponseHead* resp,
36                                               bool* reset) {
37   return mConn->OnHeadersAvailable(trans, req, resp, reset);
38 }
39 
CloseTransaction(nsAHttpTransaction * trans,nsresult reason)40 void ConnectionHandle::CloseTransaction(nsAHttpTransaction* trans,
41                                         nsresult reason) {
42   mConn->CloseTransaction(trans, reason);
43 }
44 
TakeTransport(nsISocketTransport ** aTransport,nsIAsyncInputStream ** aInputStream,nsIAsyncOutputStream ** aOutputStream)45 nsresult ConnectionHandle::TakeTransport(nsISocketTransport** aTransport,
46                                          nsIAsyncInputStream** aInputStream,
47                                          nsIAsyncOutputStream** aOutputStream) {
48   return mConn->TakeTransport(aTransport, aInputStream, aOutputStream);
49 }
50 
IsPersistent()51 bool ConnectionHandle::IsPersistent() {
52   MOZ_ASSERT(OnSocketThread());
53   return mConn->IsPersistent();
54 }
55 
IsReused()56 bool ConnectionHandle::IsReused() {
57   MOZ_ASSERT(OnSocketThread());
58   return mConn->IsReused();
59 }
60 
DontReuse()61 void ConnectionHandle::DontReuse() {
62   MOZ_ASSERT(OnSocketThread());
63   mConn->DontReuse();
64 }
65 
PushBack(const char * buf,uint32_t bufLen)66 nsresult ConnectionHandle::PushBack(const char* buf, uint32_t bufLen) {
67   return mConn->PushBack(buf, bufLen);
68 }
69 
TakeHttpConnection()70 already_AddRefed<HttpConnectionBase> ConnectionHandle::TakeHttpConnection() {
71   // return our connection object to the caller and clear it internally
72   // do not drop our reference - the caller now owns it.
73   MOZ_ASSERT(mConn);
74   return mConn.forget();
75 }
76 
HttpConnection()77 already_AddRefed<HttpConnectionBase> ConnectionHandle::HttpConnection() {
78   RefPtr<HttpConnectionBase> rv(mConn);
79   return rv.forget();
80 }
81 
TopBrowsingContextIdChanged(uint64_t id)82 void ConnectionHandle::TopBrowsingContextIdChanged(uint64_t id) {
83   // Do nothing.
84 }
85 
86 }  // namespace net
87 }  // namespace mozilla
88