Fast path pre-completed Input reads
This commit is contained in:
parent
afe944c053
commit
cf77efc2ff
|
|
@ -116,13 +116,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
Complete();
|
Complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AbortAwaiting()
|
|
||||||
{
|
|
||||||
_awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted");
|
|
||||||
|
|
||||||
Complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Complete()
|
private void Complete()
|
||||||
{
|
{
|
||||||
var awaitableState = Interlocked.Exchange(
|
var awaitableState = Interlocked.Exchange(
|
||||||
|
|
@ -177,6 +170,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AbortAwaiting()
|
||||||
|
{
|
||||||
|
_awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted");
|
||||||
|
|
||||||
|
Complete();
|
||||||
|
}
|
||||||
|
|
||||||
public SocketInput GetAwaiter()
|
public SocketInput GetAwaiter()
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
|
|
@ -10,15 +10,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
public static ValueTask<int> ReadAsync(this SocketInput input, byte[] buffer, int offset, int count)
|
public static ValueTask<int> ReadAsync(this SocketInput input, byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
while (true)
|
while (input.IsCompleted)
|
||||||
{
|
{
|
||||||
if (!input.IsCompleted)
|
|
||||||
{
|
|
||||||
return input.ReadAsyncAwaited(buffer, offset, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
var begin = input.ConsumingStart();
|
var begin = input.ConsumingStart();
|
||||||
|
|
||||||
int actual;
|
int actual;
|
||||||
var end = begin.CopyTo(buffer, offset, count, out actual);
|
var end = begin.CopyTo(buffer, offset, count, out actual);
|
||||||
input.ConsumingComplete(end, end);
|
input.ConsumingComplete(end, end);
|
||||||
|
|
@ -32,6 +26,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return input.ReadAsyncAwaited(buffer, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<int> ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count)
|
private static async Task<int> ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count)
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
||||||
#else
|
#else
|
||||||
public static Task CompletedTask = Task.FromResult<object>(null);
|
public static Task CompletedTask = Task.FromResult<object>(null);
|
||||||
#endif
|
#endif
|
||||||
|
public static Task<int> ZeroTask = Task.FromResult(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue