summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-02-10 15:10:39 +0000
committerMoonchild <moonchild@palemoon.org>2022-04-03 01:13:32 +0200
commit2bb9285528b55e1baaf8da536a27bc95b1f4c3b0 (patch)
tree3e2b240699053171272c6ded443285b8288ea7a7
parent7d38f200bee6f7c31d66780e543d837aa292050e (diff)
downloaduxp-2bb9285528b55e1baaf8da536a27bc95b1f4c3b0.tar.gz
[network] SocketTransport2 cleanup
-rw-r--r--netwerk/base/nsSocketTransport2.cpp33
-rw-r--r--netwerk/base/nsSocketTransport2.h2
2 files changed, 22 insertions, 13 deletions
diff --git a/netwerk/base/nsSocketTransport2.cpp b/netwerk/base/nsSocketTransport2.cpp
index 3c6804760a..04a258c6d0 100644
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -930,7 +930,6 @@ nsresult
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
{
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "wrong thread");
- NS_ASSERTION(!mFD.IsInitialized(), "already initialized");
char buf[kNetAddrMaxCStrBufSize];
NetAddrToString(addr, buf, sizeof(buf));
@@ -956,6 +955,7 @@ nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
{
MutexAutoLock lock(mLock);
+ NS_ASSERTION(!mFD.IsInitialized(), "already initialized");
mFD = fd;
mFDref = 1;
mFDconnected = 1;
@@ -1319,11 +1319,14 @@ nsSocketTransport::InitiateSocket()
//
// if we already have a connected socket, then just attach and return.
//
- if (mFD.IsInitialized()) {
+ {
+ MutexAutoLock lock(mlock);
+ if (mFD.IsInitialized()) {
rv = mSocketTransportService->AttachSocket(mFD, this);
if (NS_SUCCEEDED(rv))
- mAttached = true;
+ mAttached = true;
return rv;
+ }
}
//
@@ -1389,18 +1392,18 @@ nsSocketTransport::InitiateSocket()
PR_SetSocketOption(fd, &opt);
#endif
- // inform socket transport about this newly created socket...
- rv = mSocketTransportService->AttachSocket(fd, this);
- if (NS_FAILED(rv)) {
- CloseSocket(fd);
- return rv;
- }
- mAttached = true;
-
// assign mFD so that we can properly handle OnSocketDetached before we've
// established a connection.
{
MutexAutoLock lock(mLock);
+ // inform socket transport about this newly created socket...
+ rv = mSocketTransportService->AttachSocket(fd, this);
+ if (NS_FAILED(rv)) {
+ CloseSocket(fd);
+ return rv;
+ }
+ mAttached = true;
+
mFD = fd;
mFDref = 1;
mFDconnected = false;
@@ -1545,8 +1548,12 @@ nsSocketTransport::RecoverFromError()
nsresult rv;
- // OK to check this outside mLock
- NS_ASSERTION(!mFDconnected, "socket should not be connected");
+#ifdef DEBUG
+ {
+ MutexAutoLock lock(mLock);
+ NS_ASSERTION(!mFDconnected, "socket should not be connected");
+ }
+#endif
// all connection failures need to be reported to DNS so that the next
// time we will use a different address if available.
diff --git a/netwerk/base/nsSocketTransport2.h b/netwerk/base/nsSocketTransport2.h
index cb107e6e79..89b75efa57 100644
--- a/netwerk/base/nsSocketTransport2.h
+++ b/netwerk/base/nsSocketTransport2.h
@@ -350,11 +350,13 @@ private:
void OnMsgInputPending()
{
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
if (mState == STATE_TRANSFERRING)
mPollFlags |= (PR_POLL_READ | PR_POLL_EXCEPT);
}
void OnMsgOutputPending()
{
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
if (mState == STATE_TRANSFERRING)
mPollFlags |= (PR_POLL_WRITE | PR_POLL_EXCEPT);
}