public override void EndWrite(IAsyncResult asyncResult)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(this);
NetEventSource.Info(this, $"asyncResult:{asyncResult}");
}
if (asyncResult == null)
{
throw new ArgumentNullException(nameof(asyncResult));
}
HttpResponseStreamAsyncResult castedAsyncResult = asyncResult as HttpResponseStreamAsyncResult;
if (castedAsyncResult == null || castedAsyncResult.AsyncObject != this)
{
throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
}
if (castedAsyncResult.EndCalled)
{
throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, nameof(EndWrite)));
}
castedAsyncResult.EndCalled = true;
// wait & then check for errors
object returnValue = castedAsyncResult.InternalWaitForCompletion();
Exception exception = returnValue as Exception;
if (exception != null)
{
if (NetEventSource.IsEnabled) NetEventSource.Error(this, "Rethrowing exception:" + exception);
_closed = true;
_httpContext.Abort();
throw exception;
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}