From 1d4b9d663306179756959aec04313fb27a49b95c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 13:42:33 +0000 Subject: [PATCH] ListenerPrimary - reduce closure allocation Still captures string pipeName --- .../Http/ListenerPrimary.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 21c6c55183..c5b6321d4a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private List _dispatchPipes = new List(); private int _dispatchIndex; + private string _pipeName; // this message is passed to write2 because it must be non-zero-length, // but it has no other functional significance @@ -36,18 +37,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelThread thread, RequestDelegate application) { + _pipeName = pipeName; + await StartAsync(address, thread, application).ConfigureAwait(false); - await Thread.PostAsync(_ => - { - ListenPipe = new UvPipeHandle(Log); - ListenPipe.Init(Thread.Loop, false); - ListenPipe.Bind(pipeName); - ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null); - }, null).ConfigureAwait(false); + await Thread.PostAsync(_this => _this.PostCallback(), + this).ConfigureAwait(false); } - private void OnListenPipe(UvStreamHandle pipe, int status, Exception error, object state) + private void PostCallback() + { + ListenPipe = new UvPipeHandle(Log); + ListenPipe.Init(Thread.Loop, false); + ListenPipe.Bind(_pipeName); + ListenPipe.Listen(Constants.ListenBacklog, + (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); + } + + private void OnListenPipe(UvStreamHandle pipe, int status, Exception error) { if (status < 0) {