private IAsyncResult BeginHandshake(InternalAsyncResult readwriteAsyncResult)
{
//!!
// Move the handshake state to the next state
//if (handShakeState == HandshakeState.Renegotiate)
//{
// handShakeState = HandshakeState.RenegotiateInProcess;
//}
//else
if (handShakeState != HandshakeState.Renegotiate)
{
handShakeState = HandshakeState.InProcess;
}
// Wrap the read/write InternalAsyncResult in the Handshake InternalAsyncResult instance
InternalAsyncResult handshakeAsyncResult = new InternalAsyncResult(new AsyncCallback(AsyncHandshakeComplete), readwriteAsyncResult, null, 0, 0, readwriteAsyncResult.IsWriteOperation, readwriteAsyncResult.ContinueAfterHandshake);
if (ProcessHandshake())
{
//inHandshakeLoop = false;
handShakeState = HandshakeState.Complete;
handshakeAsyncResult.SetComplete();
}
else
{
//!! if (readwriteAsyncResult.IsWriteOperation)
if (write_bio.BytesPending > 0)
{
handshakeAsyncResult.IsWriteOperation = true;
BeginWrite(new byte[0], 0, 0, new AsyncCallback(AsyncHandshakeCallback), handshakeAsyncResult);
}
else
{
handshakeAsyncResult.IsWriteOperation = false;
BeginRead(new byte[0], 0, 0, new AsyncCallback(AsyncHandshakeCallback), handshakeAsyncResult);
}
}
return handshakeAsyncResult;
}