fixes bug 126755 "try next ip address on connection timeout"

r=dougt, sr=rpotts, a=asa


git-svn-id: svn://10.0.0.236/trunk@116898 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
darin%netscape.com 2002-03-19 22:30:55 +00:00
parent 6d3b59f8a1
commit 4817e6feb2
2 changed files with 45 additions and 16 deletions

View File

@ -531,21 +531,8 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
// on connection failure, reuse next address if one exists
if (mStatus == NS_ERROR_CONNECTION_REFUSED) {
mNetAddress = mNetAddrList.GetNext(mNetAddress);
if (mNetAddress) {
#if defined(PR_LOGGING)
char buf[50];
PR_NetAddrToString(mNetAddress, buf, sizeof(buf));
LOG(("connection failed... trying %s\n", buf));
#endif
PR_Close(mSocketFD);
mSocketFD = nsnull;
// mask error status so we'll return to this state
mStatus = NS_OK;
// need to re-enter Process() asynchronously
mService->AddToWorkQ(this);
LOG(("connection failed [this=%x error=%x]\n", this, mStatus));
if (TryNextAddress()) {
done = PR_TRUE;
continue;
}
@ -563,6 +550,23 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
LOG(("nsSocketTransport: Transport [host=%s:%d this=%x] is in Timeout state.\n",
mHostName, mPort, this));
mStatus = NS_ERROR_NET_TIMEOUT;
// on timeout, reuse next address if one exists ... do this only
// if we haven't already fired OnStartRequest.
if (mReadRequest || mWriteRequest) {
PRBool firedOnStart = PR_TRUE; // initial value doesn't matter
if (mReadRequest)
firedOnStart = mReadRequest->IsInitialized();
if (!firedOnStart && mWriteRequest)
firedOnStart = mWriteRequest->IsInitialized();
if (!firedOnStart && TryNextAddress()) {
// a little bit of hackery here so we'll end up in the
// WaitConnect state...
mCurrentState = eSocketState_WaitConnect;
done = PR_TRUE;
continue;
}
}
break;
default:
@ -611,6 +615,29 @@ nsSocketTransport::Cancel(nsresult status)
return NS_OK;
}
PRBool
nsSocketTransport::TryNextAddress()
{
mNetAddress = mNetAddrList.GetNext(mNetAddress);
if (mNetAddress) {
#if defined(PR_LOGGING)
char buf[64];
PR_NetAddrToString(mNetAddress, buf, sizeof(buf));
LOG((" ...trying next address: %s\n", buf));
#endif
PR_Close(mSocketFD);
mSocketFD = nsnull;
// mask error status so we'll return to this state
mStatus = NS_OK;
// need to re-enter Process() asynchronously
mService->AddToWorkQ(this);
return PR_TRUE;
}
return PR_FALSE;
}
void
nsSocketTransport::CompleteAsyncRead()
{

View File

@ -208,6 +208,8 @@ protected:
nsresult doReadWrite(PRInt16 aSelectFlags);
nsresult doResolveHost();
PRBool TryNextAddress();
void CompleteAsyncRead();
void CompleteAsyncWrite();
@ -378,7 +380,7 @@ public:
void SetSocket(PRFileDesc *aSock) { mSock = aSock; }
PRUint32 GetOffset() { return mOffset; }
void SetOffset(PRUint32 o) { mOffset = o; }
void SetOffset(PRUint32 offset) { mOffset = offset; }
PRBool GotWouldBlock() { return mError == PR_WOULD_BLOCK_ERROR; }
PRBool GotError() { return mError != 0; }
PRErrorCode GetError() { return mError; }