Http{Request|Response}Stream.ValidateState made inlineable
This commit is contained in:
parent
8bca6b3877
commit
773aa6e6ff
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -192,29 +193,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ValidateState(CancellationToken cancellationToken)
|
||||
{
|
||||
switch (_state)
|
||||
var state = _state;
|
||||
if (state == HttpStreamState.Open)
|
||||
{
|
||||
case HttpStreamState.Open:
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
break;
|
||||
case HttpStreamState.Closed:
|
||||
throw new ObjectDisposedException(nameof(HttpRequestStream));
|
||||
case HttpStreamState.Aborted:
|
||||
if (_error != null)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(_error).Throw();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new TaskCanceledException();
|
||||
}
|
||||
break;
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
else if (state == HttpStreamState.Closed)
|
||||
{
|
||||
ThrowObjectDisposedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_error != null)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(_error).Throw();
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowTaskCanceledException();
|
||||
}
|
||||
}
|
||||
|
||||
void ThrowObjectDisposedException() => throw new ObjectDisposedException(nameof(HttpRequestStream));
|
||||
void ThrowTaskCanceledException() => throw new TaskCanceledException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
|
|
@ -148,25 +149,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ValidateState(CancellationToken cancellationToken)
|
||||
{
|
||||
switch (_state)
|
||||
var state = _state;
|
||||
if (state == HttpStreamState.Open || state == HttpStreamState.Aborted)
|
||||
{
|
||||
case HttpStreamState.Open:
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
break;
|
||||
case HttpStreamState.Closed:
|
||||
throw new ObjectDisposedException(nameof(HttpResponseStream), CoreStrings.WritingToResponseBodyAfterResponseCompleted);
|
||||
case HttpStreamState.Aborted:
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// Aborted state only throws on write if cancellationToken requests it
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
break;
|
||||
// Aborted state only throws on write if cancellationToken requests it
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowObjectDisposedException();
|
||||
}
|
||||
|
||||
void ThrowObjectDisposedException()
|
||||
{
|
||||
throw new ObjectDisposedException(nameof(HttpResponseStream), CoreStrings.WritingToResponseBodyAfterResponseCompleted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue