public override void EndWrite(IAsyncResult asyncResult)
{
#if DEBUG
using (DebugThreadTracking.SetThreadKind(ThreadKinds.User))
{
#endif
_negoState.CheckThrow(true);
if (!_negoState.CanGetSecureStream)
{
InnerStream.EndWrite(asyncResult);
return;
}
if (asyncResult == null)
{
throw new ArgumentNullException(nameof(asyncResult));
}
BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult;
if (bufferResult == null)
{
throw new ArgumentException(SR.Format(SR.net_io_async_result, asyncResult.GetType().FullName), nameof(asyncResult));
}
if (Interlocked.Exchange(ref _NestedWrite, 0) == 0)
{
throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, "EndWrite"));
}
// No "artificial" timeouts implemented so far, InnerStream controls timeout.
bufferResult.InternalWaitForCompletion();
if (bufferResult.Result is Exception)
{
if (bufferResult.Result is IOException)
{
throw (Exception)bufferResult.Result;
}
throw new IOException(SR.net_io_write, (Exception)bufferResult.Result);
}
#if DEBUG
}
#endif
}