summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-02-10 15:10:39 +0000
committerMoonchild <moonchild@palemoon.org>2022-02-10 15:10:39 +0000
commit6a57234b7fa8153ff8cf7006a9b33038b0b6933b (patch)
treeff1937cf3ad9d5c45d28a535949d56a0b44d2d4c
parente7007842aed6b169e22bbfe83eed04969686484d (diff)
downloadaura-central-6a57234b7fa8153ff8cf7006a9b33038b0b6933b.tar.gz
[network] SocketTransport2 cleanup
-rw-r--r--system/network/base/nsSocketTransport2.cpp41
-rw-r--r--system/network/base/nsSocketTransport2.h2
2 files changed, 29 insertions, 14 deletions
diff --git a/system/network/base/nsSocketTransport2.cpp b/system/network/base/nsSocketTransport2.cpp
index eedf5f895..d2662fa0a 100644
--- a/system/network/base/nsSocketTransport2.cpp
+++ b/system/network/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;
@@ -1030,6 +1030,7 @@ nsSocketTransport::ResolveHost()
this, SocketHost().get(), SocketPort(),
mConnectionFlags & nsSocketTransport::BYPASS_CACHE ?
" bypass cache" : ""));
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
nsresult rv;
@@ -1236,6 +1237,7 @@ nsresult
nsSocketTransport::InitiateSocket()
{
SOCKET_LOG(("nsSocketTransport::InitiateSocket [this=%p]\n", this));
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
nsresult rv;
bool isLocal;
@@ -1319,11 +1321,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;
+ }
}
//
@@ -1388,19 +1393,20 @@ nsSocketTransport::InitiateSocket()
opt.value.linger.linger = 0;
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;
-
+ // up to here, mFD will only be accessed by us
+
// 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 +1551,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.
@@ -1783,6 +1793,7 @@ nsSocketTransport::ReleaseFD_Locked(PRFileDesc *fd)
void
nsSocketTransport::OnSocketEvent(uint32_t type, nsresult status, nsISupports *param)
{
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
SOCKET_LOG(("nsSocketTransport::OnSocketEvent [this=%p type=%u status=%x param=%p]\n",
this, type, status, param));
@@ -1895,6 +1906,7 @@ nsSocketTransport::OnSocketEvent(uint32_t type, nsresult status, nsISupports *pa
void
nsSocketTransport::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
{
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
SOCKET_LOG(("nsSocketTransport::OnSocketReady [this=%p outFlags=%hd]\n",
this, outFlags));
@@ -2403,6 +2415,7 @@ nsSocketTransport::Bind(NetAddr *aLocalAddr)
NS_ENSURE_ARG(aLocalAddr);
MutexAutoLock lock(mLock);
+ MOZ_ASSERT(OnSocketThread(), "not on socket thread");
if (mAttached) {
return NS_ERROR_FAILURE;
}
diff --git a/system/network/base/nsSocketTransport2.h b/system/network/base/nsSocketTransport2.h
index cb107e6e7..89b75efa5 100644
--- a/system/network/base/nsSocketTransport2.h
+++ b/system/network/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);
}