From a175609bb141198cc7e039eb1ee7522d9345dd77 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 2 Nov 2016 21:28:05 -0700 Subject: [PATCH] Start transport before endpoint --- .../ChatSample/Controllers/HomeController.cs | 16 +-------------- samples/ChatSample/Hubs/Chat.cs | 2 ++ .../HttpConnectionDispatcher.cs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/samples/ChatSample/Controllers/HomeController.cs b/samples/ChatSample/Controllers/HomeController.cs index 29cf1ab63a..77436b46ee 100644 --- a/samples/ChatSample/Controllers/HomeController.cs +++ b/samples/ChatSample/Controllers/HomeController.cs @@ -3,28 +3,14 @@ using Microsoft.AspNetCore.Authorization; namespace ChatSample.Controllers { - [Authorize] public class HomeController : Controller { + [Authorize] public IActionResult Index() { return View(); } - public IActionResult About() - { - ViewData["Message"] = "Your application description page."; - - return View(); - } - - public IActionResult Contact() - { - ViewData["Message"] = "Your contact page."; - - return View(); - } - public IActionResult Error() { return View(); diff --git a/samples/ChatSample/Hubs/Chat.cs b/samples/ChatSample/Hubs/Chat.cs index 1f308b9572..f54cc2cc28 100644 --- a/samples/ChatSample/Hubs/Chat.cs +++ b/samples/ChatSample/Hubs/Chat.cs @@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Authorization; namespace ChatSample.Hubs { + // TODO: Make this work + [Authorize] public class Chat : Hub { public override Task OnConnectedAsync() diff --git a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs index 41bc105cd7..3866a2fa42 100644 --- a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs @@ -86,6 +86,13 @@ namespace Microsoft.AspNetCore.Sockets // Mark the connection as active state.Active = true; + RegisterLongPollingDisconnect(context, state.Connection); + + var longPolling = new LongPolling(state.Connection); + + // Start the transport + var transportTask = longPolling.ProcessRequest(context); + Task endpointTask = null; // Raise OnConnected for new connections only since polls happen all the time @@ -112,13 +119,6 @@ namespace Microsoft.AspNetCore.Sockets endpointTask = (Task)state.Connection.Metadata["endpoint"]; } - RegisterLongPollingDisconnect(context, state.Connection); - - var longPolling = new LongPolling(state.Connection); - - // Start the transport - var transportTask = longPolling.ProcessRequest(context); - var resultTask = await Task.WhenAny(endpointTask, transportTask); if (resultTask == endpointTask) @@ -144,12 +144,12 @@ namespace Microsoft.AspNetCore.Sockets // Register this transport for disconnect RegisterDisconnect(context, connection); - // Call into the end point passing the connection - var endpointTask = endpoint.OnConnected(connection); - // Start the transport var transportTask = transport.ProcessRequest(context); + // Call into the end point passing the connection + var endpointTask = endpoint.OnConnected(connection); + // Wait for any of them to end await Task.WhenAny(endpointTask, transportTask);