Skip to content

Commit f4c6e0b

Browse files
authored
Feedback from SocketOutput port (#1502)
- Fix naming convention in LibuvAwaitable - Remove case statement in SocketOutput
1 parent 07cbf7f commit f4c6e0b

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,10 @@ public async Task WriteAsync(
105105

106106
public void End(ProduceEndType endType)
107107
{
108-
switch (endType)
108+
if (endType == ProduceEndType.SocketShutdown)
109109
{
110-
case ProduceEndType.SocketShutdown:
111-
// Graceful shutdown
112-
_pipe.Reader.CancelPendingRead();
113-
break;
114-
case ProduceEndType.SocketDisconnect:
115-
// Not graceful
116-
break;
110+
// Graceful shutdown
111+
_pipe.Reader.CancelPendingRead();
117112
}
118113

119114
lock (_contextLock)

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
1212
{
1313
public class LibuvAwaitable<TRequest> : ICriticalNotifyCompletion where TRequest : UvRequest
1414
{
15-
private readonly static Action CALLBACK_RAN = () => { };
15+
private readonly static Action _callbackCompleted = () => { };
1616

1717
private Action _callback;
1818

1919
private Exception _exception;
2020

2121
private int _status;
2222

23-
public static Action<TRequest, int, Exception, object> Callback = (req, status, error, state) =>
23+
public static readonly Action<TRequest, int, Exception, object> Callback = (req, status, error, state) =>
2424
{
2525
var awaitable = (LibuvAwaitable<TRequest>)state;
2626

2727
awaitable._exception = error;
2828
awaitable._status = status;
2929

30-
var continuation = Interlocked.Exchange(ref awaitable._callback, CALLBACK_RAN);
30+
var continuation = Interlocked.Exchange(ref awaitable._callback, _callbackCompleted);
3131

3232
continuation?.Invoke();
3333
};
3434

3535
public LibuvAwaitable<TRequest> GetAwaiter() => this;
36-
public bool IsCompleted => _callback == CALLBACK_RAN;
36+
public bool IsCompleted => _callback == _callbackCompleted;
3737

3838
public UvWriteResult GetResult()
3939
{
@@ -50,8 +50,8 @@ public UvWriteResult GetResult()
5050

5151
public void OnCompleted(Action continuation)
5252
{
53-
if (_callback == CALLBACK_RAN ||
54-
Interlocked.CompareExchange(ref _callback, continuation, null) == CALLBACK_RAN)
53+
if (_callback == _callbackCompleted ||
54+
Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted)
5555
{
5656
Task.Run(continuation);
5757
}
@@ -65,8 +65,8 @@ public void UnsafeOnCompleted(Action continuation)
6565

6666
public struct UvWriteResult
6767
{
68-
public int Status;
69-
public Exception Error;
68+
public int Status { get; }
69+
public Exception Error { get; }
7070

7171
public UvWriteResult(int status, Exception error)
7272
{

0 commit comments

Comments
 (0)