private void ProcessWrite(byte[] buffer, int offset, int count, LazyAsyncResult asyncResult)
{
_sslState.CheckThrow(authSuccessCheck:true, shutdownCheck:true);
ValidateParameters(buffer, offset, count);
if (Interlocked.Exchange(ref _nestedWrite, 1) == 1)
{
throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, "Write", "write"));
}
// If this is an async operation, get the AsyncProtocolRequest to use.
// We do this only after we verify we're the sole write operation in flight.
AsyncProtocolRequest asyncRequest = GetOrCreateProtocolRequest(ref _writeProtocolRequest, asyncResult);
bool failed = false;
try
{
StartWriting(buffer, offset, count, asyncRequest);
}
catch (Exception e)
{
_sslState.FinishWrite();
failed = true;
if (e is IOException)
{
throw;
}
throw new IOException(SR.net_io_write, e);
}
finally
{
if (asyncRequest == null || failed)
{
_nestedWrite = 0;
}
}
}