From cac6ade7c95d744f37313f8567787de7de162781 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 23 Jan 2017 13:51:57 +0000 Subject: [PATCH] Implement Stream Flush+FlushAsync fully Streams should pass through the flush and not assume the underlying Stream's Flush behaviour --- .../Adapter/Internal/LoggingStream.cs | 5 +++++ .../Adapter/Internal/RawStream.cs | 6 +++--- .../Adapter/Internal/StreamSocketOutput.cs | 5 ++--- .../ConnectionAdapterTests.cs | 7 ++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs index 184839163c..5421093a63 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs @@ -71,6 +71,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal _inner.Flush(); } + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _inner.FlushAsync(cancellationToken); + } + public override int Read(byte[] buffer, int offset, int count) { int read = _inner.Read(buffer, offset, count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs index 2c7fb8accf..0824eeb594 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs @@ -117,15 +117,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal public override void Flush() { - // No-op since writes are immediate. + _output.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - // No-op since writes are immediate. - return TaskCache.CompletedTask; + return _output.FlushAsync(cancellationToken); } + private ValueTask ReadAsync(ArraySegment buffer) { return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index e2cce039aa..a5fd6c24a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { @@ -114,14 +113,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal end.Block.Pool.Return(end.Block); } - // Flush no-ops. We rely on connection filter streams to auto-flush. public void Flush() { + _outputStream.Flush(); } public Task FlushAsync(CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return _outputStream.FlushAsync(cancellationToken); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs index 81fb5629c2..c842e0e83e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs @@ -186,7 +186,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public override void Flush() { - // No-op + _innerStream.Flush(); + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _innerStream.FlushAsync(cancellationToken); } public override int Read(byte[] buffer, int offset, int count)