Start transport before endpoint

This commit is contained in:
David Fowler 2016-11-02 21:28:05 -07:00
parent b6f15338eb
commit a175609bb1
3 changed files with 13 additions and 25 deletions

View File

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

View File

@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Authorization;
namespace ChatSample.Hubs
{
// TODO: Make this work
[Authorize]
public class Chat : Hub
{
public override Task OnConnectedAsync()

View File

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