Listener - remove closure allocation
This commit is contained in:
parent
facf3ad0da
commit
cc84097016
|
|
@ -30,19 +30,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
Thread = thread;
|
||||
Application = application;
|
||||
|
||||
var tcs = new TaskCompletionSource<int>();
|
||||
Thread.Post(_ =>
|
||||
var tcs = new TaskCompletionSource<int>(this);
|
||||
|
||||
Thread.Post(tcs2 =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ListenSocket = CreateListenSocket();
|
||||
tcs.SetResult(0);
|
||||
var listener = ((Listener)tcs2.Task.AsyncState);
|
||||
listener.ListenSocket = listener.CreateListenSocket();
|
||||
tcs2.SetResult(0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
tcs2.SetException(ex);
|
||||
}
|
||||
}, null);
|
||||
}, tcs);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
|
|
@ -85,21 +88,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
// the exception that stopped the event loop will never be surfaced.
|
||||
if (Thread.FatalError == null && ListenSocket != null)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<int>();
|
||||
var tcs = new TaskCompletionSource<int>(this);
|
||||
Thread.Post(
|
||||
_ =>
|
||||
tcs2 =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ListenSocket.Dispose();
|
||||
tcs.SetResult(0);
|
||||
var socket = (Listener)tcs2.Task.AsyncState;
|
||||
socket.ListenSocket.Dispose();
|
||||
tcs2.SetResult(0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
tcs2.SetException(ex);
|
||||
}
|
||||
},
|
||||
null);
|
||||
tcs);
|
||||
|
||||
// REVIEW: Should we add a timeout here to be safe?
|
||||
tcs.Task.Wait();
|
||||
|
|
|
|||
Loading…
Reference in New Issue