Fast path pre-completed Input reads

This commit is contained in:
Ben Adams 2015-12-23 10:20:25 +00:00
parent afe944c053
commit cf77efc2ff
3 changed files with 12 additions and 15 deletions

View File

@ -116,13 +116,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Complete();
}
public void AbortAwaiting()
{
_awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted");
Complete();
}
private void Complete()
{
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()
{
return this;

View File

@ -1,8 +1,8 @@
// 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.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
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)
{
while (true)
while (input.IsCompleted)
{
if (!input.IsCompleted)
{
return input.ReadAsyncAwaited(buffer, offset, count);
}
var begin = input.ConsumingStart();
int actual;
var end = begin.CopyTo(buffer, offset, count, out actual);
input.ConsumingComplete(end, end);
@ -32,6 +26,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return 0;
}
}
return input.ReadAsyncAwaited(buffer, offset, count);
}
private static async Task<int> ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count)

View File

@ -12,5 +12,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
#else
public static Task CompletedTask = Task.FromResult<object>(null);
#endif
public static Task<int> ZeroTask = Task.FromResult(0);
}
}