From 8e9feec8729c9836638e20bc1f81c957af9edcce Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Thu, 26 Jan 2012 16:04:54 -0500 Subject: [PATCH] bug 670277 - Fix WARNING: NS_ENSURE_TRUE(mState == STATE_TRANSFERRING) r=biesi --- netwerk/base/src/nsSocketTransport2.cpp | 12 +++++++++++- netwerk/base/src/nsSocketTransport2.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/netwerk/base/src/nsSocketTransport2.cpp b/netwerk/base/src/nsSocketTransport2.cpp index 8b02e2eb317..57b2e099b30 100644 --- a/netwerk/base/src/nsSocketTransport2.cpp +++ b/netwerk/base/src/nsSocketTransport2.cpp @@ -722,6 +722,7 @@ nsSocketTransport::nsSocketTransport() , mInputClosed(true) , mOutputClosed(true) , mResolving(false) + , mNetAddrIsSet(false) , mLock("nsSocketTransport.mLock") , mFD(nsnull) , mFDref(0) @@ -858,6 +859,7 @@ nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const PRNetAddr *addr mPollFlags = (PR_POLL_READ | PR_POLL_WRITE | PR_POLL_EXCEPT); mPollTimeout = mTimeouts[TIMEOUT_READ_WRITE]; mState = STATE_TRANSFERRING; + mNetAddrIsSet = true; mFD = fd; mFDref = 1; @@ -1399,6 +1401,10 @@ nsSocketTransport::OnSocketConnected() mPollTimeout = mTimeouts[TIMEOUT_READ_WRITE]; mState = STATE_TRANSFERRING; + // Set the mNetAddrIsSet flag only when state has reached TRANSFERRING + // because we need to make sure its value does not change due to failover + mNetAddrIsSet = true; + // assign mFD (must do this within the transport lock), but take care not // to trample over mFDref if mFD is already set. { @@ -1915,7 +1921,11 @@ nsSocketTransport::GetPeerAddr(PRNetAddr *addr) // we can freely access mNetAddr from any thread without being // inside a critical section. - NS_ENSURE_TRUE(mState == STATE_TRANSFERRING, NS_ERROR_NOT_AVAILABLE); + if (!mNetAddrIsSet) { + SOCKET_LOG(("nsSocketTransport::GetPeerAddr [this=%p state=%d] " + "NOT_AVAILABLE because not yet connected.", this, mState)); + return NS_ERROR_NOT_AVAILABLE; + } memcpy(addr, &mNetAddr, sizeof(mNetAddr)); return NS_OK; diff --git a/netwerk/base/src/nsSocketTransport2.h b/netwerk/base/src/nsSocketTransport2.h index dbffea49617..53c53027c15 100644 --- a/netwerk/base/src/nsSocketTransport2.h +++ b/netwerk/base/src/nsSocketTransport2.h @@ -226,7 +226,11 @@ private: nsCOMPtr mDNSRequest; nsCOMPtr mDNSRecord; + + // mNetAddr is valid from GetPeerAddr() once we have + // reached STATE_TRANSFERRING. It must not change after that. PRNetAddr mNetAddr; + bool mNetAddrIsSet; // socket methods (these can only be called on the socket thread):