Merge pull request #342 from benaadams/completed-task
Completed Task opt
This commit is contained in:
commit
e1a95c97e1
|
|
@ -2,16 +2,15 @@
|
||||||
// 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.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||||
{
|
{
|
||||||
public class NoOpConnectionFilter : IConnectionFilter
|
public class NoOpConnectionFilter : IConnectionFilter
|
||||||
{
|
{
|
||||||
private static Task _empty = Task.FromResult<object>(null);
|
|
||||||
|
|
||||||
public Task OnConnection(ConnectionFilterContext context)
|
public Task OnConnection(ConnectionFilterContext context)
|
||||||
{
|
{
|
||||||
return _empty;
|
return TaskUtilities.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Server.Kestrel.Http;
|
using Microsoft.AspNet.Server.Kestrel.Http;
|
||||||
|
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||||
{
|
{
|
||||||
|
|
@ -17,8 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SocketInputStream : Stream
|
public class SocketInputStream : Stream
|
||||||
{
|
{
|
||||||
private static Task _emptyTask = Task.FromResult<object>(null);
|
|
||||||
|
|
||||||
private readonly SocketInput _socketInput;
|
private readonly SocketInput _socketInput;
|
||||||
|
|
||||||
public SocketInputStream(SocketInput socketInput)
|
public SocketInputStream(SocketInput socketInput)
|
||||||
|
|
@ -85,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
|
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
|
||||||
{
|
{
|
||||||
Write(buffer, offset, count);
|
Write(buffer, offset, count);
|
||||||
return _emptyTask;
|
return TaskUtilities.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,12 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Server.Kestrel.Http;
|
using Microsoft.AspNet.Server.Kestrel.Http;
|
||||||
|
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||||
{
|
{
|
||||||
public class StreamSocketOutput : ISocketOutput
|
public class StreamSocketOutput : ISocketOutput
|
||||||
{
|
{
|
||||||
private static readonly Task _emptyTask = Task.FromResult<object>(null);
|
|
||||||
|
|
||||||
private readonly Stream _outputStream;
|
private readonly Stream _outputStream;
|
||||||
|
|
||||||
public StreamSocketOutput(Stream outputStream)
|
public StreamSocketOutput(Stream outputStream)
|
||||||
|
|
@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||||
{
|
{
|
||||||
// TODO: Use _outputStream.WriteAsync
|
// TODO: Use _outputStream.WriteAsync
|
||||||
_outputStream.Write(buffer.Array, buffer.Offset, buffer.Count);
|
_outputStream.Write(buffer.Array, buffer.Offset, buffer.Count);
|
||||||
return _emptyTask;
|
return TaskUtilities.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
||||||
{
|
{
|
||||||
public static class TaskUtilities
|
public static class TaskUtilities
|
||||||
{
|
{
|
||||||
public static Task CompletedTask = NewCompletedTask();
|
#if DOTNET5_4 || DNXCORE50
|
||||||
|
public static Task CompletedTask = Task.CompletedTask;
|
||||||
private static Task NewCompletedTask()
|
#else
|
||||||
{
|
public static Task CompletedTask = Task.FromResult<object>(null);
|
||||||
var tcs = new TaskCompletionSource<int>();
|
#endif
|
||||||
tcs.SetResult(0);
|
|
||||||
return tcs.Task;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue