|
|
|
|
@@ -122,7 +122,7 @@ nsSocketTransport::nsSocketTransport():
|
|
|
|
|
mCurrentState(eSocketState_Created),
|
|
|
|
|
mHostName(nsnull),
|
|
|
|
|
mLoadAttributes(LOAD_NORMAL),
|
|
|
|
|
mLock(nsnull),
|
|
|
|
|
mMonitor(nsnull),
|
|
|
|
|
mOperation(eSocketOperation_None),
|
|
|
|
|
mPort(0),
|
|
|
|
|
mPrintHost(nsnull),
|
|
|
|
|
@@ -219,11 +219,11 @@ nsSocketTransport::~nsSocketTransport()
|
|
|
|
|
mSocketFD = nsnull;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mLock) {
|
|
|
|
|
PR_DestroyLock(mLock);
|
|
|
|
|
mLock = nsnull;
|
|
|
|
|
if (mMonitor) {
|
|
|
|
|
PR_DestroyMonitor(mMonitor);
|
|
|
|
|
mMonitor = nsnull;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mWriteBuffer) {
|
|
|
|
|
PR_Free(mWriteBuffer);
|
|
|
|
|
mWriteBuffer = nsnull;
|
|
|
|
|
@@ -279,8 +279,8 @@ nsresult nsSocketTransport::Init(nsSocketTransportService* aService,
|
|
|
|
|
// Create the lock used for synchronizing access to the transport instance.
|
|
|
|
|
//
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
mLock = PR_NewLock();
|
|
|
|
|
if (!mLock) {
|
|
|
|
|
mMonitor = PR_NewMonitor();
|
|
|
|
|
if (!mMonitor) {
|
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -302,7 +302,7 @@ nsresult nsSocketTransport::CheckForTimeout(PRIntervalTime aCurrentTime)
|
|
|
|
|
PRIntervalTime idleInterval;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
idleInterval = aCurrentTime - mLastActiveTime;
|
|
|
|
|
|
|
|
|
|
@@ -333,7 +333,7 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
// This lock protects access to socket transport member data...
|
|
|
|
|
//
|
|
|
|
|
PR_Lock(mLock);
|
|
|
|
|
PR_EnterMonitor(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("+++ Entering nsSocketTransport::Process() [%s:%d %x].\t"
|
|
|
|
|
@@ -409,7 +409,6 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
|
|
|
|
|
//
|
|
|
|
|
// A connection has been established with the server
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mSelectFlags = PR_POLL_EXCEPT;
|
|
|
|
|
|
|
|
|
|
if (GetReadType() != eSocketRead_None) {
|
|
|
|
|
@@ -599,7 +598,7 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
|
|
|
|
|
"CurrentState = %d\n\n",
|
|
|
|
|
mHostName, mPort, this, mStatus, mCurrentState));
|
|
|
|
|
|
|
|
|
|
PR_Unlock(mLock);
|
|
|
|
|
PR_ExitMonitor(mMonitor);
|
|
|
|
|
return mStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -649,14 +648,14 @@ nsresult nsSocketTransport::doResolveHost(void)
|
|
|
|
|
// Give up the SocketTransport lock. This allows the DNS thread to call the
|
|
|
|
|
// nsIDNSListener notifications without blocking...
|
|
|
|
|
//
|
|
|
|
|
PR_Unlock(mLock);
|
|
|
|
|
PR_ExitMonitor(mMonitor);
|
|
|
|
|
|
|
|
|
|
rv = pDNSService->Lookup(nsnull, mHostName, this,
|
|
|
|
|
rv = pDNSService->Lookup(mHostName, this, nsnull,
|
|
|
|
|
getter_AddRefs(mDNSRequest));
|
|
|
|
|
//
|
|
|
|
|
// Aquire the SocketTransport lock again...
|
|
|
|
|
//
|
|
|
|
|
PR_Lock(mLock);
|
|
|
|
|
PR_EnterMonitor(mMonitor);
|
|
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
//
|
|
|
|
|
@@ -979,10 +978,10 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
|
|
|
|
|
// lock which could cause a deadlock by blocking the socket transport
|
|
|
|
|
// thread
|
|
|
|
|
//
|
|
|
|
|
PR_Unlock(mLock);
|
|
|
|
|
PR_ExitMonitor(mMonitor);
|
|
|
|
|
rv = mReadPipeOut->WriteSegments(nsReadFromSocket, (void*)&info,
|
|
|
|
|
MAX_IO_TRANSFER_SIZE, &totalBytesWritten);
|
|
|
|
|
PR_Lock(mLock);
|
|
|
|
|
PR_EnterMonitor(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("WriteSegments [fd=%x]. rv = %x. Bytes read =%d\n",
|
|
|
|
|
@@ -1146,7 +1145,7 @@ nsresult nsSocketTransport::doWriteFromBuffer(PRUint32 *aCount)
|
|
|
|
|
// lock which could cause a deadlock by blocking the socket transport
|
|
|
|
|
// thread
|
|
|
|
|
//
|
|
|
|
|
PR_Unlock(mLock);
|
|
|
|
|
PR_ExitMonitor(mMonitor);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Write the data to the network...
|
|
|
|
|
@@ -1158,7 +1157,7 @@ nsresult nsSocketTransport::doWriteFromBuffer(PRUint32 *aCount)
|
|
|
|
|
//
|
|
|
|
|
rv = mWritePipeIn->ReadSegments(nsWriteToSocket, (void*)mSocketFD,
|
|
|
|
|
transferCount, aCount);
|
|
|
|
|
PR_Lock(mLock);
|
|
|
|
|
PR_EnterMonitor(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("ReadSegments [fd=%x]. rv = %x. Bytes written =%d\n",
|
|
|
|
|
@@ -1324,7 +1323,7 @@ nsSocketTransport::GetBytesExpected (PRInt32 * bytes)
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsSocketTransport::SetBytesExpected (PRInt32 bytes)
|
|
|
|
|
{
|
|
|
|
|
nsAutoLock alock (mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
if (mCurrentState == eSocketState_WaitReadWrite)
|
|
|
|
|
{
|
|
|
|
|
@@ -1364,7 +1363,7 @@ nsSocketTransport::Cancel(void)
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
mCancelOperation = PR_TRUE;
|
|
|
|
|
//
|
|
|
|
|
@@ -1386,7 +1385,7 @@ nsSocketTransport::Suspend(void)
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
mSuspendCount += 1;
|
|
|
|
|
//
|
|
|
|
|
@@ -1414,7 +1413,7 @@ nsSocketTransport::Resume(void)
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
if (mSuspendCount) {
|
|
|
|
|
mSuspendCount -= 1;
|
|
|
|
|
@@ -1464,7 +1463,7 @@ nsSocketTransport::OnFull(nsIPipe* aPipe)
|
|
|
|
|
nsresult rv = aPipe->GetInputStream(getter_AddRefs(in));
|
|
|
|
|
if (NS_SUCCEEDED(rv) && in == mReadPipeIn) {
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(!GetFlag(eSocketRead_Wait), "Already waiting!");
|
|
|
|
|
|
|
|
|
|
@@ -1497,7 +1496,7 @@ nsSocketTransport::OnWrite(nsIPipe* aPipe, PRUint32 aCount)
|
|
|
|
|
rv = aPipe->GetInputStream(getter_AddRefs(in));
|
|
|
|
|
if (NS_SUCCEEDED(rv) && in == mWritePipeIn) {
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
if (GetFlag(eSocketWrite_Wait)) {
|
|
|
|
|
ClearFlag(eSocketWrite_Wait);
|
|
|
|
|
@@ -1530,7 +1529,7 @@ nsSocketTransport::OnEmpty(nsIPipe* aPipe)
|
|
|
|
|
rv = aPipe->GetInputStream(getter_AddRefs(in));
|
|
|
|
|
if (NS_SUCCEEDED(rv) && in == mReadPipeIn) {
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
if (GetFlag(eSocketRead_Wait)) {
|
|
|
|
|
ClearFlag(eSocketRead_Wait);
|
|
|
|
|
@@ -1569,7 +1568,7 @@ nsSocketTransport::OnFound(nsISupports *aContext,
|
|
|
|
|
nsHostEnt *aHostEnt)
|
|
|
|
|
{
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
if (aHostEnt->hostEnt.h_addr_list
|
|
|
|
|
@@ -1607,7 +1606,7 @@ nsSocketTransport::OnStopLookup(nsISupports *aContext,
|
|
|
|
|
nsresult aStatus)
|
|
|
|
|
{
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock lock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("nsSocketTransport::OnStopLookup(...) [%s:%d %x]."
|
|
|
|
|
@@ -1663,7 +1662,7 @@ nsSocketTransport::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("+++ Entering nsSocketTransport::AsyncOpen() [%s:%d %x]\n",
|
|
|
|
|
@@ -1707,7 +1706,7 @@ nsSocketTransport::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("+++ Entering nsSocketTransport::AsyncRead() [%s:%d %x]\t"
|
|
|
|
|
@@ -1768,7 +1767,7 @@ nsSocketTransport::AsyncWrite(nsIInputStream* aFromStream,
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("+++ Entering nsSocketTransport::AsyncWrite() [%s:%d %x]\t"
|
|
|
|
|
@@ -1837,7 +1836,7 @@ nsSocketTransport::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
|
|
|
|
NS_ASSERTION(startPosition == 0, "fix me");
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("+++ Entering nsSocketTransport::OpenInputStream() [%s:%d %x].\n",
|
|
|
|
|
@@ -1888,7 +1887,7 @@ nsSocketTransport::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *re
|
|
|
|
|
NS_ASSERTION(startPosition == 0, "fix me");
|
|
|
|
|
|
|
|
|
|
// Enter the socket transport lock...
|
|
|
|
|
nsAutoLock aLock(mLock);
|
|
|
|
|
nsAutoMonitor mon(mMonitor);
|
|
|
|
|
|
|
|
|
|
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
|
|
|
|
("+++ Entering nsSocketTransport::OpenOutputStream() [%s:%d %x].\n",
|
|
|
|
|
|