Bug 997688 - nsSocketTransport should track SocketTransportService via smart ptr r=sworkman

This commit is contained in:
Patrick McManus 2014-04-15 23:00:39 -04:00
parent def020062f
commit 3308cdbd52
2 changed files with 22 additions and 20 deletions

View File

@ -764,6 +764,7 @@ nsSocketTransport::nsSocketTransport()
, mFD(MOZ_THIS_IN_INITIALIZER_LIST())
, mFDref(0)
, mFDconnected(false)
, mSocketTransportService(gSocketTransportService)
, mInput(MOZ_THIS_IN_INITIALIZER_LIST())
, mOutput(MOZ_THIS_IN_INITIALIZER_LIST())
, mQoSBits(0x00)
@ -774,8 +775,6 @@ nsSocketTransport::nsSocketTransport()
{
SOCKET_LOG(("creating nsSocketTransport @%p\n", this));
NS_ADDREF(gSocketTransportService);
mTimeouts[TIMEOUT_CONNECT] = UINT16_MAX; // no timeout
mTimeouts[TIMEOUT_READ_WRITE] = UINT16_MAX; // no timeout
}
@ -791,9 +790,6 @@ nsSocketTransport::~nsSocketTransport()
PL_strfree(mTypes[i]);
free(mTypes);
}
nsSocketTransportService *serv = gSocketTransportService;
NS_RELEASE(serv); // nulls argument
}
nsresult
@ -961,7 +957,7 @@ nsSocketTransport::PostEvent(uint32_t type, nsresult status, nsISupports *param)
if (!event)
return NS_ERROR_OUT_OF_MEMORY;
return gSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL);
return mSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL);
}
void
@ -1219,19 +1215,19 @@ nsSocketTransport::InitiateSocket()
// FIFO ordering (which wouldn't even be that valuable IMO). see bug
// 194402 for more info.
//
if (!gSocketTransportService->CanAttachSocket()) {
if (!mSocketTransportService->CanAttachSocket()) {
nsCOMPtr<nsIRunnable> event =
new nsSocketEvent(this, MSG_RETRY_INIT_SOCKET);
if (!event)
return NS_ERROR_OUT_OF_MEMORY;
return gSocketTransportService->NotifyWhenCanAttachSocket(event);
return mSocketTransportService->NotifyWhenCanAttachSocket(event);
}
//
// if we already have a connected socket, then just attach and return.
//
if (mFD.IsInitialized()) {
rv = gSocketTransportService->AttachSocket(mFD, this);
rv = mSocketTransportService->AttachSocket(mFD, this);
if (NS_SUCCEEDED(rv))
mAttached = true;
return rv;
@ -1273,7 +1269,7 @@ nsSocketTransport::InitiateSocket()
// The Windows default of 8KB is too small and as of vista sp1, autotuning
// only applies to receive window
int32_t sndBufferSize;
gSocketTransportService->GetSendBufferSize(&sndBufferSize);
mSocketTransportService->GetSendBufferSize(&sndBufferSize);
if (sndBufferSize > 0) {
opt.option = PR_SockOpt_SendBufferSize;
opt.value.send_buffer_size = sndBufferSize;
@ -1287,7 +1283,7 @@ nsSocketTransport::InitiateSocket()
}
// inform socket transport about this newly created socket...
rv = gSocketTransportService->AttachSocket(fd, this);
rv = mSocketTransportService->AttachSocket(fd, this);
if (NS_FAILED(rv)) {
PR_Close(fd);
return rv;
@ -1464,7 +1460,7 @@ nsSocketTransport::RecoverFromError()
// Retry if that connection is made.
if (!tryAgain) {
bool autodialEnabled;
gSocketTransportService->GetAutodialEnabled(&autodialEnabled);
mSocketTransportService->GetAutodialEnabled(&autodialEnabled);
if (autodialEnabled) {
tryAgain = nsNativeConnectionHelper::OnConnectionFailed(
NS_ConvertUTF8toUTF16(SocketHost()).get());
@ -1966,7 +1962,7 @@ nsSocketTransport::OpenInputStream(uint32_t flags,
if (NS_FAILED(rv)) return rv;
// async copy from socket to pipe
rv = NS_AsyncCopy(&mInput, pipeOut, gSocketTransportService,
rv = NS_AsyncCopy(&mInput, pipeOut, mSocketTransportService,
NS_ASYNCCOPY_VIA_WRITESEGMENTS, segsize);
if (NS_FAILED(rv)) return rv;
@ -2012,7 +2008,7 @@ nsSocketTransport::OpenOutputStream(uint32_t flags,
if (NS_FAILED(rv)) return rv;
// async copy from socket to pipe
rv = NS_AsyncCopy(pipeIn, &mOutput, gSocketTransportService,
rv = NS_AsyncCopy(pipeIn, &mOutput, mSocketTransportService,
NS_ASYNCCOPY_VIA_READSEGMENTS, segsize);
if (NS_FAILED(rv)) return rv;
@ -2451,7 +2447,7 @@ nsSocketTransport::SetKeepaliveEnabledInternal(bool aEnable)
// Only enable if keepalives are globally enabled, but ensure other
// options are set correctly on the fd.
bool enable = aEnable && gSocketTransportService->IsKeepaliveEnabled();
bool enable = aEnable && mSocketTransportService->IsKeepaliveEnabled();
nsresult rv = fd.SetKeepaliveVals(enable,
mKeepaliveIdleTimeS,
mKeepaliveRetryIntervalS,
@ -2483,21 +2479,21 @@ nsSocketTransport::EnsureKeepaliveValsAreInitialized()
nsresult rv = NS_OK;
int32_t val = -1;
if (mKeepaliveIdleTimeS == -1) {
rv = gSocketTransportService->GetKeepaliveIdleTime(&val);
rv = mSocketTransportService->GetKeepaliveIdleTime(&val);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mKeepaliveIdleTimeS = val;
}
if (mKeepaliveRetryIntervalS == -1) {
rv = gSocketTransportService->GetKeepaliveRetryInterval(&val);
rv = mSocketTransportService->GetKeepaliveRetryInterval(&val);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mKeepaliveRetryIntervalS = val;
}
if (mKeepaliveProbeCount == -1) {
rv = gSocketTransportService->GetKeepaliveProbeCount(&val);
rv = mSocketTransportService->GetKeepaliveProbeCount(&val);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -2534,7 +2530,7 @@ nsSocketTransport::SetKeepaliveEnabled(bool aEnable)
this, aEnable ? "enabled" : "disabled",
mKeepaliveIdleTimeS, mKeepaliveRetryIntervalS,
mKeepaliveProbeCount,
gSocketTransportService->IsKeepaliveEnabled() ?
mSocketTransportService->IsKeepaliveEnabled() ?
"enabled" : "disabled"));
// Set mKeepaliveEnabled here so that state is maintained; it is possible
@ -2583,7 +2579,7 @@ nsSocketTransport::SetKeepaliveVals(int32_t aIdleTime,
nsresult rv = NS_OK;
if (mKeepaliveProbeCount == -1) {
int32_t val = -1;
nsresult rv = gSocketTransportService->GetKeepaliveProbeCount(&val);
nsresult rv = mSocketTransportService->GetKeepaliveProbeCount(&val);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

View File

@ -23,6 +23,7 @@
#include "nsASocketHandler.h"
#include "prerror.h"
#include "nsAutoPtr.h"
class nsSocketTransport;
class nsICancelable;
@ -329,6 +330,11 @@ private:
nsrefcnt mFDref; // mFD is closed when mFDref goes to zero.
bool mFDconnected; // mFD is available to consumer when TRUE.
// A delete protector reference to gSocketTransportService held for lifetime
// of 'this'. Sometimes used interchangably with gSocketTransportService due
// to scoping.
nsRefPtr<nsSocketTransportService> mSocketTransportService;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsITransportEventSink> mEventSink;
nsCOMPtr<nsISupports> mSecInfo;