diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index ec8394be20..60536fe5d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -23,6 +23,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + (handle as UvStreamHandle)?.Connection?.Tick((long)arg); + }; // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network @@ -245,14 +250,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } public void Walk(Action callback) + { + Walk((ptr, arg) => callback(ptr), IntPtr.Zero); + } + + private void Walk(Libuv.uv_walk_cb callback, IntPtr arg) { _engine.Libuv.walk( _loop, - (ptr, arg) => - { - callback(ptr); - }, - IntPtr.Zero); + callback, + arg + ); } private void PostCloseHandle(Action callback, IntPtr handle) @@ -336,13 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void OnHeartbeat(UvTimerHandle timer) { - var now = Loop.Now(); - - Walk(ptr => - { - var handle = UvMemory.FromIntPtr(ptr); - (handle as UvStreamHandle)?.Connection?.Tick(now); - }); + Walk(_heartbeatWalkCallback, (IntPtr)Loop.Now()); } private bool DoPostWork()