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