private void ForceAuthentication(bool receiveFirst, byte[] buffer, AsyncProtocolRequest asyncRequest)
{
if (CheckEnqueueHandshake(buffer, asyncRequest))
{
// Async handshake is enqueued and will resume later.
return;
}
// Either Sync handshake is ready to go or async handshake won the race over write.
// This will tell that we don't know the framing yet (what SSL version is)
_Framing = Framing.Unknown;
try
{
if (receiveFirst)
{
// Listen for a client blob.
StartReceiveBlob(buffer, asyncRequest);
}
else
{
// We start with the first blob.
StartSendBlob(buffer, (buffer == null ? 0 : buffer.Length), asyncRequest);
}
}
catch (Exception e)
{
// Failed auth, reset the framing if any.
_Framing = Framing.Unknown;
_handshakeCompleted = false;
if (SetException(e).SourceException == e)
{
throw;
}
else
{
_exception.Throw();
}
}
finally
{
if (_exception != null)
{
// This a failed handshake. Release waiting IO if any.
FinishHandshake(null, null);
}
}
}