Hi,
My earlier version seemed to be somewhat buggy. Sorry.
Here is a fixed one :). I changed WANT_WRITE case to do
SSL_read again. As I undertsand SSL_read can result in
WANT_WRITE meaning it wants to write something but failed
(due to an underlying wouldblock maybe).
A simple solution would be to call SSL_read again. OR you
could wait on the the socket becoming writable.
I have marked the changes like this: CHANGED.
.....
.....
WSAEventSelect( iSocketID, m_hSocketEvent, FD_READ|FD_CLOSE);
while(1)
{
int iResult = WSAWaitForMultipleEvents( 1, &m_hSocketEvent,
FALSE,INFINITE, FALSE );
if( iResult == WSA_WAIT_EVENT_0 )
{
WSANETWORKEVENTS networkEvents;
iRetCode = WSAEnumNetworkEvents(iSocketID, m_hSocketEvent,
&networkEvents);
long lEvents = networkEvents.lNetworkEvents;
if(lEvents & FD_CLOSE) //close
{
//cleanup and break;
}
//Assuming an active read is all you wanna do
//CHANGED
if(lEvents & FD_READ)
{
int readBytes = Read(szBuffOut,sizeof(szBuffOut));
if(readBytes > 0) //application data
{
//do whatever processing
}
if(readBytes == -2) //error terminate connection
{
//cleanup and break;
}
//if readBytes == -1 then go back to WaitFor...
//I think SSL_read returns zero when it reads handshake
//data so we really donot have to bother about it
//(This comments makes sense when u do an implicit accept)
continue;
}
} //end of if (WAIT_OBJ...
} //end of while
....
//Returns -2 if error,-1 if wait, otherwise bytes read,
Read(char* szBuffOut, int size )
{
doRead:
int iErr = SSL_read(m_sslconn, szBuffOut, size);
if( iErr >= 0) //read bytes, could be handshake as well
return iErr; //return bytes Read
else
{
int iLastErr = SSL_get_error( m_sslconn, iErr );
//CHANGED
if( iLastErr == SSL_ERROR_WANT_READ )
return -1;
if( iLastErr == SSL_WANT_WRITE)
//Assuming that WANT_WRITE shall be relatively rare
//So should not really hog CPU time
goto doRead;
//SSL_ERROR_ZERO_RETURN is actually closure alert, the others
//are other errors
//CHANGED typo error last time.
if ( iLastError == SSL_ERROR_ZERO_RETURN ||
iLastError == SSL_ERROR_SYSCALL ||
iLastError == SSL_ERROR_SSL )
return -2;
} //end of else
} //end of read
This time I hope this is correct and helpful.
If something wrong could anyone point it out?
Are my assumptions correct?
Amit.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]