mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-24 17:37:30 +09:00
[network] SocketTransport2 cleanup
This commit is contained in:
parent
6ec59e7984
commit
7f3a7225af
2 changed files with 22 additions and 13 deletions
|
|
@ -931,7 +931,6 @@ nsresult
|
||||||
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
|
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "wrong thread");
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "wrong thread");
|
||||||
NS_ASSERTION(!mFD.IsInitialized(), "already initialized");
|
|
||||||
|
|
||||||
char buf[kNetAddrMaxCStrBufSize];
|
char buf[kNetAddrMaxCStrBufSize];
|
||||||
NetAddrToString(addr, buf, sizeof(buf));
|
NetAddrToString(addr, buf, sizeof(buf));
|
||||||
|
|
@ -957,6 +956,7 @@ nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mLock);
|
MutexAutoLock lock(mLock);
|
||||||
|
|
||||||
|
NS_ASSERTION(!mFD.IsInitialized(), "already initialized");
|
||||||
mFD = fd;
|
mFD = fd;
|
||||||
mFDref = 1;
|
mFDref = 1;
|
||||||
mFDconnected = 1;
|
mFDconnected = 1;
|
||||||
|
|
@ -1320,11 +1320,14 @@ nsSocketTransport::InitiateSocket()
|
||||||
//
|
//
|
||||||
// if we already have a connected socket, then just attach and return.
|
// 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);
|
rv = mSocketTransportService->AttachSocket(mFD, this);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
mAttached = true;
|
mAttached = true;
|
||||||
return rv;
|
return rv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -1390,18 +1393,18 @@ nsSocketTransport::InitiateSocket()
|
||||||
PR_SetSocketOption(fd, &opt);
|
PR_SetSocketOption(fd, &opt);
|
||||||
#endif
|
#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
|
// assign mFD so that we can properly handle OnSocketDetached before we've
|
||||||
// established a connection.
|
// established a connection.
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mLock);
|
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;
|
mFD = fd;
|
||||||
mFDref = 1;
|
mFDref = 1;
|
||||||
mFDconnected = false;
|
mFDconnected = false;
|
||||||
|
|
@ -1546,8 +1549,12 @@ nsSocketTransport::RecoverFromError()
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
// OK to check this outside mLock
|
#ifdef DEBUG
|
||||||
NS_ASSERTION(!mFDconnected, "socket should not be connected");
|
{
|
||||||
|
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
|
// all connection failures need to be reported to DNS so that the next
|
||||||
// time we will use a different address if available.
|
// time we will use a different address if available.
|
||||||
|
|
|
||||||
|
|
@ -350,11 +350,13 @@ private:
|
||||||
|
|
||||||
void OnMsgInputPending()
|
void OnMsgInputPending()
|
||||||
{
|
{
|
||||||
|
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
|
||||||
if (mState == STATE_TRANSFERRING)
|
if (mState == STATE_TRANSFERRING)
|
||||||
mPollFlags |= (PR_POLL_READ | PR_POLL_EXCEPT);
|
mPollFlags |= (PR_POLL_READ | PR_POLL_EXCEPT);
|
||||||
}
|
}
|
||||||
void OnMsgOutputPending()
|
void OnMsgOutputPending()
|
||||||
{
|
{
|
||||||
|
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
|
||||||
if (mState == STATE_TRANSFERRING)
|
if (mState == STATE_TRANSFERRING)
|
||||||
mPollFlags |= (PR_POLL_WRITE | PR_POLL_EXCEPT);
|
mPollFlags |= (PR_POLL_WRITE | PR_POLL_EXCEPT);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue