fix runl to reset after error so we'll try again, e.g. after first

using a hostname that doesn't resolve.
This commit is contained in:
ehouse 2005-03-20 19:52:21 +00:00
parent 88663b415a
commit 29ca361020

View file

@ -33,15 +33,15 @@ CSendSocket::RunL()
switch ( iSSockState ) { switch ( iSSockState ) {
case ELookingUp: case ELookingUp:
iResolver.Close(); /* we probably won't need this again */ iResolver.Close(); /* we probably won't need this again */
XP_ASSERT( iStatus.Int() == KErrNone );
if ( statusGood ) { if ( statusGood ) {
iNameRecord = iNameEntry(); iNameRecord = iNameEntry();
XP_LOGF( "name resolved" ); XP_LOGF( "name resolved" );
ConnectL( TInetAddr::Cast(iNameRecord.iAddr).Address() ); ConnectL( TInetAddr::Cast(iNameRecord.iAddr).Address() );
} else {
ResetState();
} }
break; break;
case EConnecting: case EConnecting:
XP_ASSERT( statusGood );
if ( statusGood ) { if ( statusGood ) {
iSSockState = EConnected; iSSockState = EConnected;
XP_LOGF( "connect successful" ); XP_LOGF( "connect successful" );
@ -50,22 +50,26 @@ CSendSocket::RunL()
} else if ( iListenPending ) { } else if ( iListenPending ) {
Listen(); Listen();
} }
} else {
ResetState();
} }
break; break;
case ESending: case ESending:
XP_ASSERT( statusGood );
if ( statusGood ) { if ( statusGood ) {
XP_LOGF( "send successful" );
} else {
/* Depending on error, might need to close socket, reconnect, etc.
For now we'll just trust the upper layers to figure out they
didn't get through, or user to resend. */
XP_LOGF( "send failed with error %d", iStatus.Int() );
}
iSSockState = EConnected; iSSockState = EConnected;
iSendBuf.SetLength(0); iSendBuf.SetLength(0);
XP_LOGF( "send successful" );
if ( iListenPending ) { if ( iListenPending ) {
Listen(); Listen();
} }
/* Send was successful. Need to tell anybody? Might want to
update display somehow. */
}
break; break;
case EListening: case EListening:
@ -73,8 +77,8 @@ CSendSocket::RunL()
if ( iDataLen == 0 ) { if ( iDataLen == 0 ) {
/* Do nothing; we need to read again via Listen call */ /* Do nothing; we need to read again via Listen call */
iDataLen = XP_NTOHS( *(XP_U16*)iInBufDesc->Ptr() ); iDataLen = XP_NTOHS( *(XP_U16*)iInBufDesc->Ptr() );
XP_LOGF( "Recv succeeded with length; now looking for %d byte packet", XP_LOGF( "Recv succeeded with length; now looking for %d byte"
iDataLen ); "packet", iDataLen );
} else { } else {
iDataLen = 0; iDataLen = 0;
XP_LOGF( "Got packet! Calling callback" ); XP_LOGF( "Got packet! Calling callback" );
@ -82,27 +86,33 @@ CSendSocket::RunL()
} }
iSSockState = EConnected; iSSockState = EConnected;
Listen(); /* go back to listening */ Listen(); /* go back to listening */
} else {
XP_LOGF( "listen failed with error %d", iStatus.Int() );
ResetState();
} }
} }
} /* RunL */ } /* RunL */
void
CSendSocket::ResetState()
{
iSendBuf.SetLength(0);
iSSockState = ENotConnected;
}
TBool TBool
CSendSocket::Listen() CSendSocket::Listen()
{ {
XP_LOGF( "CSendSocket::Listen" ); XP_LOGF( "CSendSocket::Listen" );
TBool result;
iListenPending = ETrue; iListenPending = ETrue;
if ( IsActive() ) { if ( IsActive() ) {
if ( iSSockState == ESending ) { /* since iListenPending is set, we'll eventually get to listening once
result = ETrue; all the RunL()s get called. Do nothing. */
}
result = EFalse;
} else { } else {
if ( iSSockState == ENotConnected ) { if ( iSSockState == ENotConnected ) {
ConnectL(); ConnectL();
} else { } else if ( iSSockState == EConnected ) {
delete iInBufDesc; delete iInBufDesc;
TInt seekLen = iDataLen == 0? 2: iDataLen; TInt seekLen = iDataLen == 0? 2: iDataLen;
@ -113,11 +123,13 @@ CSendSocket::Listen()
SetActive(); SetActive();
iSSockState = EListening; iSSockState = EListening;
result = ETrue;
iListenPending = EFalse; iListenPending = EFalse;
} else {
XP_LOGF( "iSSockState=%d", iSSockState );
XP_ASSERT( 0 );
} }
} }
return result; return ETrue;
} /* Listen */ } /* Listen */
TBool TBool
@ -292,12 +304,12 @@ CSendSocket::SendL( const XP_U8* aBuf, XP_U16 aLen, const CommsAddrRec* aAddr )
success = EFalse; success = EFalse;
} else if ( aLen > KMaxMsgLen ) { } else if ( aLen > KMaxMsgLen ) {
success = EFalse; success = EFalse;
} else if ( iSendBuf.Length() != 0 ) {
XP_LOGF( "old buffer not sent yet" );
success = EFalse;
} else { } else {
XP_ASSERT( iSendBuf.Length() == 0 );
/* TCP-based protocol requires 16-bits of length, in network /* TCP-based protocol requires 16-bits of length, in network
byte-order, followed by data. */ byte-order, followed by data. */
iSendBuf.SetLength(0);
XP_U16 netLen = XP_HTONS( aLen ); XP_U16 netLen = XP_HTONS( aLen );
iSendBuf.Append( (TUint8*)&netLen, sizeof(netLen) ); iSendBuf.Append( (TUint8*)&netLen, sizeof(netLen) );
iSendBuf.Append( aBuf, aLen ); iSendBuf.Append( aBuf, aLen );