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