From f4c6e0b1510d9151f85fa7d87d05c400f3357f2e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 18 Mar 2017 01:21:31 -0700 Subject: [PATCH] Feedback from SocketOutput port (#1502) - Fix naming convention in LibuvAwaitable - Remove case statement in SocketOutput --- .../Internal/Http/SocketOutput.cs | 11 +++-------- .../Internal/Infrastructure/LibuvAwaitable.cs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 1438f1c274..7c4412ef23 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -105,15 +105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void End(ProduceEndType endType) { - switch (endType) + if (endType == ProduceEndType.SocketShutdown) { - case ProduceEndType.SocketShutdown: - // Graceful shutdown - _pipe.Reader.CancelPendingRead(); - break; - case ProduceEndType.SocketDisconnect: - // Not graceful - break; + // Graceful shutdown + _pipe.Reader.CancelPendingRead(); } lock (_contextLock) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs index 1bfd222e6c..8fc241858f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public class LibuvAwaitable : ICriticalNotifyCompletion where TRequest : UvRequest { - private readonly static Action CALLBACK_RAN = () => { }; + private readonly static Action _callbackCompleted = () => { }; private Action _callback; @@ -20,20 +20,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private int _status; - public static Action Callback = (req, status, error, state) => + public static readonly Action Callback = (req, status, error, state) => { var awaitable = (LibuvAwaitable)state; awaitable._exception = error; awaitable._status = status; - var continuation = Interlocked.Exchange(ref awaitable._callback, CALLBACK_RAN); + var continuation = Interlocked.Exchange(ref awaitable._callback, _callbackCompleted); continuation?.Invoke(); }; public LibuvAwaitable GetAwaiter() => this; - public bool IsCompleted => _callback == CALLBACK_RAN; + public bool IsCompleted => _callback == _callbackCompleted; public UvWriteResult GetResult() { @@ -50,8 +50,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public void OnCompleted(Action continuation) { - if (_callback == CALLBACK_RAN || - Interlocked.CompareExchange(ref _callback, continuation, null) == CALLBACK_RAN) + if (_callback == _callbackCompleted || + Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) { Task.Run(continuation); } @@ -65,8 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public struct UvWriteResult { - public int Status; - public Exception Error; + public int Status { get; } + public Exception Error { get; } public UvWriteResult(int status, Exception error) {