Replace Helpers.CompletedTask and Helpers.CanceledTask (#446)
This commit is contained in:
parent
d9c823d3b0
commit
61f7c82d49
|
|
@ -14,18 +14,6 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
internal static readonly byte[] ChunkTerminator = new byte[] { (byte)'0', (byte)'\r', (byte)'\n', (byte)'\r', (byte)'\n' };
|
internal static readonly byte[] ChunkTerminator = new byte[] { (byte)'0', (byte)'\r', (byte)'\n', (byte)'\r', (byte)'\n' };
|
||||||
internal static readonly byte[] CRLF = new byte[] { (byte)'\r', (byte)'\n' };
|
internal static readonly byte[] CRLF = new byte[] { (byte)'\r', (byte)'\n' };
|
||||||
|
|
||||||
internal static Task CompletedTask()
|
|
||||||
{
|
|
||||||
return Task.FromResult<object>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static Task<T> CanceledTask<T>()
|
|
||||||
{
|
|
||||||
TaskCompletionSource<T> tcs = new TaskCompletionSource<T>();
|
|
||||||
tcs.TrySetCanceled();
|
|
||||||
return tcs.Task;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static ConfiguredTaskAwaitable SupressContext(this Task task)
|
internal static ConfiguredTaskAwaitable SupressContext(this Task task)
|
||||||
{
|
{
|
||||||
return task.ConfigureAwait(continueOnCapturedContext: false);
|
return task.ConfigureAwait(continueOnCapturedContext: false);
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
return Helpers.CanceledTask<int>();
|
return Task.FromCanceled<int>(cancellationToken);
|
||||||
}
|
}
|
||||||
// TODO: Verbose log parameters
|
// TODO: Verbose log parameters
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
{
|
{
|
||||||
if (_disposed)
|
if (_disposed)
|
||||||
{
|
{
|
||||||
return Helpers.CompletedTask();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
return FlushInternalAsync(new ArraySegment<byte>(), cancellationToken);
|
return FlushInternalAsync(new ArraySegment<byte>(), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
@ -274,20 +274,20 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
{
|
{
|
||||||
if (_skipWrites)
|
if (_skipWrites)
|
||||||
{
|
{
|
||||||
return Helpers.CompletedTask();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
var started = _requestContext.Response.HasStarted;
|
var started = _requestContext.Response.HasStarted;
|
||||||
if (data.Count == 0 && started)
|
if (data.Count == 0 && started)
|
||||||
{
|
{
|
||||||
// No data to send and we've already sent the headers
|
// No data to send and we've already sent the headers
|
||||||
return Helpers.CompletedTask();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Abort(ThrowWriteExceptions);
|
Abort(ThrowWriteExceptions);
|
||||||
return Helpers.CanceledTask<int>();
|
return Task.FromCanceled<int>(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure all validation is performed before this computes the headers
|
// Make sure all validation is performed before this computes the headers
|
||||||
|
|
@ -535,20 +535,20 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
{
|
{
|
||||||
if (_skipWrites)
|
if (_skipWrites)
|
||||||
{
|
{
|
||||||
return Helpers.CompletedTask();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
var started = _requestContext.Response.HasStarted;
|
var started = _requestContext.Response.HasStarted;
|
||||||
if (count == 0 && started)
|
if (count == 0 && started)
|
||||||
{
|
{
|
||||||
// No data to send and we've already sent the headers
|
// No data to send and we've already sent the headers
|
||||||
return Helpers.CompletedTask();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Abort(ThrowWriteExceptions);
|
Abort(ThrowWriteExceptions);
|
||||||
return Helpers.CanceledTask<int>();
|
return Task.FromCanceled<int>(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are setting buffer size to 1 to prevent FileStream from allocating it's internal buffer
|
// We are setting buffer size to 1 to prevent FileStream from allocating it's internal buffer
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue