Merge branch 'benaadams/listener-allocation' into dev

This commit is contained in:
Stephen Halter 2015-11-04 10:12:33 -08:00
commit 04b2885f10
1 changed files with 16 additions and 12 deletions

View File

@ -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();