Feedback from SocketOutput port (#1502)

- Fix naming convention in LibuvAwaitable
- Remove case statement in SocketOutput
This commit is contained in:
David Fowler 2017-03-18 01:21:31 -07:00 committed by GitHub
parent 07cbf7faa9
commit f4c6e0b151
2 changed files with 11 additions and 16 deletions

View File

@ -105,15 +105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
public void End(ProduceEndType endType) public void End(ProduceEndType endType)
{ {
switch (endType) if (endType == ProduceEndType.SocketShutdown)
{ {
case ProduceEndType.SocketShutdown: // Graceful shutdown
// Graceful shutdown _pipe.Reader.CancelPendingRead();
_pipe.Reader.CancelPendingRead();
break;
case ProduceEndType.SocketDisconnect:
// Not graceful
break;
} }
lock (_contextLock) lock (_contextLock)

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{ {
public class LibuvAwaitable<TRequest> : ICriticalNotifyCompletion where TRequest : UvRequest public class LibuvAwaitable<TRequest> : ICriticalNotifyCompletion where TRequest : UvRequest
{ {
private readonly static Action CALLBACK_RAN = () => { }; private readonly static Action _callbackCompleted = () => { };
private Action _callback; private Action _callback;
@ -20,20 +20,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
private int _status; private int _status;
public static Action<TRequest, int, Exception, object> Callback = (req, status, error, state) => public static readonly Action<TRequest, int, Exception, object> Callback = (req, status, error, state) =>
{ {
var awaitable = (LibuvAwaitable<TRequest>)state; var awaitable = (LibuvAwaitable<TRequest>)state;
awaitable._exception = error; awaitable._exception = error;
awaitable._status = status; awaitable._status = status;
var continuation = Interlocked.Exchange(ref awaitable._callback, CALLBACK_RAN); var continuation = Interlocked.Exchange(ref awaitable._callback, _callbackCompleted);
continuation?.Invoke(); continuation?.Invoke();
}; };
public LibuvAwaitable<TRequest> GetAwaiter() => this; public LibuvAwaitable<TRequest> GetAwaiter() => this;
public bool IsCompleted => _callback == CALLBACK_RAN; public bool IsCompleted => _callback == _callbackCompleted;
public UvWriteResult GetResult() public UvWriteResult GetResult()
{ {
@ -50,8 +50,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
public void OnCompleted(Action continuation) public void OnCompleted(Action continuation)
{ {
if (_callback == CALLBACK_RAN || if (_callback == _callbackCompleted ||
Interlocked.CompareExchange(ref _callback, continuation, null) == CALLBACK_RAN) Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted)
{ {
Task.Run(continuation); Task.Run(continuation);
} }
@ -65,8 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
public struct UvWriteResult public struct UvWriteResult
{ {
public int Status; public int Status { get; }
public Exception Error; public Exception Error { get; }
public UvWriteResult(int status, Exception error) public UvWriteResult(int status, Exception error)
{ {