diff --git a/build/dependencies.props b/build/dependencies.props index eea44544e8..142daeb465 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,51 +7,52 @@ 2.4.337 3.1.0 2.1.0-preview2-15698 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 0.5.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 0.5.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 4.5.0-preview2-26130-01 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 + 2.1.0-preview2-30070 2.0.0 2.1.0-preview2-26130-04 15.3.0 @@ -70,7 +71,7 @@ 4.5.0-preview2-26130-01 4.5.0-preview2-26130-01 2.3.1 - 2.3.1 + 2.4.0-beta.1.build3945 \ No newline at end of file diff --git a/client-ts/FunctionalTests/EchoEndPoint.cs b/client-ts/FunctionalTests/EchoEndPoint.cs index 0680acc8ca..27460590eb 100644 --- a/client-ts/FunctionalTests/EchoEndPoint.cs +++ b/client-ts/FunctionalTests/EchoEndPoint.cs @@ -3,6 +3,7 @@ using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets; namespace FunctionalTests diff --git a/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs b/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs index 01093214a6..577254ae15 100644 --- a/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs +++ b/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Features; @@ -23,9 +24,9 @@ namespace SocialWeather public void OnConnectedAsync(ConnectionContext connection) { - connection.Metadata["groups"] = new HashSet(); + connection.Features.Get().Metadata["groups"] = new HashSet(); var format = connection.GetHttpContext().Request.Query["formatType"].ToString(); - connection.Metadata["format"] = format; + connection.Features.Get().Metadata["format"] = format; if (string.Equals(format, "protobuf", StringComparison.OrdinalIgnoreCase)) { var transferModeFeature = connection.Features.Get(); @@ -47,7 +48,7 @@ namespace SocialWeather foreach (var connection in _connectionList) { var context = connection.GetHttpContext(); - var formatter = _formatterResolver.GetFormatter((string)connection.Metadata["format"]); + var formatter = _formatterResolver.GetFormatter((string)connection.Features.Get().Metadata["format"]); var ms = new MemoryStream(); await formatter.WriteAsync(data, ms); @@ -72,7 +73,7 @@ namespace SocialWeather public void AddGroupAsync(ConnectionContext connection, string groupName) { - var groups = (HashSet)connection.Metadata["groups"]; + var groups = (HashSet)connection.Features.Get().Metadata["groups"]; lock (groups) { groups.Add(groupName); @@ -81,7 +82,7 @@ namespace SocialWeather public void RemoveGroupAsync(ConnectionContext connection, string groupName) { - var groups = (HashSet)connection.Metadata["groups"]; + var groups = (HashSet)connection.Features.Get().Metadata["groups"]; if (groups != null) { lock (groups) diff --git a/samples/SocialWeather/SocialWeatherEndPoint.cs b/samples/SocialWeather/SocialWeatherEndPoint.cs index 84dd03d919..38eaf60752 100644 --- a/samples/SocialWeather/SocialWeatherEndPoint.cs +++ b/samples/SocialWeather/SocialWeatherEndPoint.cs @@ -3,7 +3,9 @@ using System.IO; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets; +using Microsoft.AspNetCore.Sockets.Features; using Microsoft.Extensions.Logging; namespace SocialWeather @@ -32,7 +34,7 @@ namespace SocialWeather public async Task ProcessRequests(ConnectionContext connection) { var formatter = _formatterResolver.GetFormatter( - (string)connection.Metadata["format"]); + (string)connection.Features.Get().Metadata["format"]); while (true) { diff --git a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs index 0fd837f8bf..933e50fd73 100644 --- a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs +++ b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs @@ -5,7 +5,9 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets; +using Microsoft.AspNetCore.Sockets.Features; namespace SocketsSample.EndPoints { @@ -17,7 +19,7 @@ namespace SocketsSample.EndPoints { Connections.Add(connection); - await Broadcast($"{connection.ConnectionId} connected ({connection.Metadata[ConnectionMetadataNames.Transport]})"); + await Broadcast($"{connection.ConnectionId} connected ({connection.Features.Get().Metadata[ConnectionMetadataNames.Transport]})"); try { @@ -50,7 +52,7 @@ namespace SocketsSample.EndPoints { Connections.Remove(connection); - await Broadcast($"{connection.ConnectionId} disconnected ({connection.Metadata[ConnectionMetadataNames.Transport]})"); + await Broadcast($"{connection.ConnectionId} disconnected ({connection.Features.Get().Metadata[ConnectionMetadataNames.Transport]})"); } } diff --git a/samples/SocketsSample/Program.cs b/samples/SocketsSample/Program.cs index aa6c67a8fe..3aea9e8472 100644 --- a/samples/SocketsSample/Program.cs +++ b/samples/SocketsSample/Program.cs @@ -3,8 +3,10 @@ using System.IO; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using SocketsSample.Hubs; namespace SocketsSample { @@ -23,7 +25,18 @@ namespace SocketsSample { factory.AddConsole(); }) - .UseKestrel() + .UseKestrel(options => + { + // Default port + options.ListenLocalhost(5000); + + // Hub bound to TCP end point + options.ListenLocalhost(9001, builder => + { + // Run the hub on this port (this won't work properly until streaming parsing is implemented) + builder.UseHub(); + }); + }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs index 2913578a42..6cfb3bcc58 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs @@ -13,6 +13,7 @@ using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.SignalR.Core; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Encoders; @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.SignalR public virtual IFeatureCollection Features => _connectionContext.Features; - public virtual IDictionary Metadata => _connectionContext.Metadata; + public virtual IDictionary Metadata => Features.Get().Metadata; public virtual PipeReader Input => _connectionContext.Transport.Input; diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs index 8c87c0abed..535c52e3f5 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs @@ -11,10 +11,10 @@ using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.SignalR.Core; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; -using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs index eee93cc206..a1e0e5f5e6 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; @@ -8,7 +9,7 @@ namespace Microsoft.AspNetCore.SignalR { public static class SignalRSocketBuilderExtensions { - public static ISocketBuilder UseHub(this ISocketBuilder socketBuilder) where THub : Hub + public static IConnectionBuilder UseHub(this IConnectionBuilder socketBuilder) where THub : Hub { var endpoint = socketBuilder.ApplicationServices.GetRequiredService>(); return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilder.cs similarity index 61% rename from src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilder.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilder.cs index 8dfc21b848..b11ffc03cb 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilder.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilder.cs @@ -6,29 +6,30 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { - public class SocketBuilder : ISocketBuilder + public class ConnectionBuilder : IConnectionBuilder { - private readonly IList> _components = new List>(); + private readonly IList> _components = new List>(); public IServiceProvider ApplicationServices { get; } - public SocketBuilder(IServiceProvider applicationServices) + public ConnectionBuilder(IServiceProvider applicationServices) { ApplicationServices = applicationServices; } - public ISocketBuilder Use(Func middleware) + public IConnectionBuilder Use(Func middleware) { _components.Add(middleware); return this; } - public SocketDelegate Build() + public ConnectionDelegate Build() { - SocketDelegate app = features => + ConnectionDelegate app = features => { return Task.CompletedTask; }; diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionContext.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionContext.cs deleted file mode 100644 index 53779be11d..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionContext.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Http.Features; - -namespace Microsoft.AspNetCore.Sockets -{ - public abstract class ConnectionContext - { - public abstract string ConnectionId { get; set; } - - public abstract IFeatureCollection Features { get; } - - public abstract IDictionary Metadata { get; set; } - - public abstract IDuplexPipe Transport { get; set; } - } -} diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/ISocketBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ISocketBuilder.cs deleted file mode 100644 index f7d2f98513..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/ISocketBuilder.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.AspNetCore.Sockets -{ - public interface ISocketBuilder - { - IServiceProvider ApplicationServices { get; } - - ISocketBuilder Use(Func middleware); - - SocketDelegate Build(); - } -} diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj b/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj index 4ad4e73092..86f2e20454 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs index e8fe0db519..69dc9712d4 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs @@ -3,12 +3,13 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { public static class SocketBuilderExtensions { - public static ISocketBuilder Use(this ISocketBuilder socketBuilder, Func, Task> middleware) + public static IConnectionBuilder Use(this IConnectionBuilder socketBuilder, Func, Task> middleware) { return socketBuilder.Use(next => { @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Sockets }); } - public static ISocketBuilder Run(this ISocketBuilder socketBuilder, Func middleware) + public static IConnectionBuilder Run(this IConnectionBuilder socketBuilder, Func middleware) { return socketBuilder.Use(next => { diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketDelegate.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketDelegate.cs deleted file mode 100644 index 45af07cd77..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketDelegate.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Sockets -{ - public delegate Task SocketDelegate(ConnectionContext connection); -} diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs index 74ce92ccd1..8e538d47bf 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs @@ -1,10 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Text; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets.Http.Features; namespace Microsoft.AspNetCore.Sockets diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs index 9ea7aaf9b5..72766cc788 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets.Features; using Microsoft.AspNetCore.Sockets.Internal; using Microsoft.AspNetCore.Sockets.Internal.Transports; @@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Sockets _logger = _loggerFactory.CreateLogger(); } - public async Task ExecuteAsync(HttpContext context, HttpSocketOptions options, SocketDelegate socketDelegate) + public async Task ExecuteAsync(HttpContext context, HttpSocketOptions options, ConnectionDelegate ConnectionDelegate) { // Create the log scope and attempt to pass the Connection ID to it so as many logs as possible contain // the Connection ID metadata. If this is the negotiate request then the Connection ID for the scope will @@ -53,7 +54,7 @@ namespace Microsoft.AspNetCore.Sockets else if (HttpMethods.IsGet(context.Request.Method)) { // GET /{path} - await ExecuteEndpointAsync(context, socketDelegate, options, logScope); + await ExecuteEndpointAsync(context, ConnectionDelegate, options, logScope); } else { @@ -87,7 +88,7 @@ namespace Microsoft.AspNetCore.Sockets } } - private async Task ExecuteEndpointAsync(HttpContext context, SocketDelegate socketDelegate, HttpSocketOptions options, ConnectionLogScope logScope) + private async Task ExecuteEndpointAsync(HttpContext context, ConnectionDelegate ConnectionDelegate, HttpSocketOptions options, ConnectionLogScope logScope) { var supportedTransports = options.Transports; @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Sockets // We only need to provide the Input channel since writing to the application is handled through /send. var sse = new ServerSentEventsTransport(connection.Application.Input, connection.ConnectionId, _loggerFactory); - await DoPersistentConnection(socketDelegate, sse, context, connection); + await DoPersistentConnection(ConnectionDelegate, sse, context, connection); } else if (context.WebSockets.IsWebSocketRequest) { @@ -141,7 +142,7 @@ namespace Microsoft.AspNetCore.Sockets var ws = new WebSocketsTransport(options.WebSockets, connection.Application, connection, _loggerFactory); - await DoPersistentConnection(socketDelegate, ws, context, connection); + await DoPersistentConnection(ConnectionDelegate, ws, context, connection); } else { @@ -202,7 +203,7 @@ namespace Microsoft.AspNetCore.Sockets connection.Metadata[ConnectionMetadataNames.Transport] = TransportType.LongPolling; - connection.ApplicationTask = ExecuteApplication(socketDelegate, connection); + connection.ApplicationTask = ExecuteApplication(ConnectionDelegate, connection); } else { @@ -291,7 +292,7 @@ namespace Microsoft.AspNetCore.Sockets } } - private async Task DoPersistentConnection(SocketDelegate socketDelegate, + private async Task DoPersistentConnection(ConnectionDelegate ConnectionDelegate, IHttpTransport transport, HttpContext context, DefaultConnectionContext connection) @@ -323,7 +324,7 @@ namespace Microsoft.AspNetCore.Sockets connection.Status = DefaultConnectionContext.ConnectionStatus.Active; // Call into the end point passing the connection - connection.ApplicationTask = ExecuteApplication(socketDelegate, connection); + connection.ApplicationTask = ExecuteApplication(ConnectionDelegate, connection); // Start the transport connection.TransportTask = transport.ProcessRequestAsync(context, context.RequestAborted); @@ -339,12 +340,12 @@ namespace Microsoft.AspNetCore.Sockets await _manager.DisposeAndRemoveAsync(connection); } - private async Task ExecuteApplication(SocketDelegate socketDelegate, ConnectionContext connection) + private async Task ExecuteApplication(ConnectionDelegate ConnectionDelegate, ConnectionContext connection) { // Verify some initialization invariants // We want to be positive that the IConnectionInherentKeepAliveFeature is initialized before invoking the application, if the long polling transport is in use. - Debug.Assert(connection.Metadata[ConnectionMetadataNames.Transport] != null, "Transport has not been initialized yet"); - Debug.Assert((TransportType?)connection.Metadata[ConnectionMetadataNames.Transport] != TransportType.LongPolling || + Debug.Assert(connection.Features.Get().Metadata[ConnectionMetadataNames.Transport] != null, "Transport has not been initialized yet"); + Debug.Assert((TransportType?)connection.Features.Get().Metadata[ConnectionMetadataNames.Transport] != TransportType.LongPolling || connection.Features.Get() != null, "Long-polling transport is in use but IConnectionInherentKeepAliveFeature as not configured"); // Jump onto the thread pool thread so blocking user code doesn't block the setup of the @@ -352,7 +353,7 @@ namespace Microsoft.AspNetCore.Sockets await AwaitableThreadPool.Yield(); // Running this in an async method turns sync exceptions into async ones - await socketDelegate(connection); + await ConnectionDelegate(connection); } private Task ProcessNegotiate(HttpContext context, HttpSocketOptions options, ConnectionLogScope logScope) diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs index 99b92af5d5..96df652cc5 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs @@ -5,6 +5,7 @@ using System; using System.Reflection; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Sockets @@ -20,15 +21,15 @@ namespace Microsoft.AspNetCore.Sockets _dispatcher = dispatcher; } - public void MapSocket(string path, Action socketConfig) => + public void MapSocket(string path, Action socketConfig) => MapSocket(new PathString(path), new HttpSocketOptions(), socketConfig); - public void MapSocket(PathString path, Action socketConfig) => + public void MapSocket(PathString path, Action socketConfig) => MapSocket(path, new HttpSocketOptions(), socketConfig); - public void MapSocket(PathString path, HttpSocketOptions options, Action socketConfig) + public void MapSocket(PathString path, HttpSocketOptions options, Action socketConfig) { - var socketBuilder = new SocketBuilder(_routes.ServiceProvider); + var socketBuilder = new ConnectionBuilder(_routes.ServiceProvider); socketConfig(socketBuilder); var socket = socketBuilder.Build(); _routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket)); diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs b/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs index 0b9b799406..ea3e201c95 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs +++ b/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; +using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { diff --git a/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs b/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs index eb7b727673..e3f6281e66 100644 --- a/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs @@ -2,12 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets.Features; using Microsoft.Extensions.Internal; @@ -63,7 +65,7 @@ namespace Microsoft.AspNetCore.Sockets public ClaimsPrincipal User { get; set; } - public override IDictionary Metadata { get; set; } = new ConnectionMetadata(); + public IDictionary Metadata { get; set; } = new ConnectionMetadata(); public IDuplexPipe Application { get; } @@ -73,6 +75,8 @@ namespace Microsoft.AspNetCore.Sockets public TransferMode TransferMode { get; set; } + public override MemoryPool MemoryPool { get; } + public void OnHeartbeat(Action action, object state) { lock (_heartbeatHandlers) diff --git a/src/Microsoft.AspNetCore.Sockets/EndPoint.cs b/src/Microsoft.AspNetCore.Sockets/EndPoint.cs index d23fbeddf4..89de4b79fa 100644 --- a/src/Microsoft.AspNetCore.Sockets/EndPoint.cs +++ b/src/Microsoft.AspNetCore.Sockets/EndPoint.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { diff --git a/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs index f0d6d3387b..1e4d5cd688 100644 --- a/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs @@ -1,13 +1,14 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Protocols; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Sockets { public static class SocketBuilderExtensions { - public static ISocketBuilder UseEndPoint(this ISocketBuilder socketBuilder) where TEndPoint : EndPoint + public static IConnectionBuilder UseEndPoint(this IConnectionBuilder socketBuilder) where TEndPoint : EndPoint { var endpoint = socketBuilder.ApplicationServices.GetRequiredService(); // This is a terminal middleware, so there's no need to use the 'next' parameter diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs index 839e98088b..b31f85c7dd 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs @@ -3,6 +3,7 @@ using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets; namespace Microsoft.AspNetCore.SignalR.Tests diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs index ea571661a8..61910660a3 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.Sockets; diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs index aac60adee8..11998ab298 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Internal; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Sockets.Features; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -116,7 +117,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; SetTransport(context, transportType); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -151,7 +152,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -188,7 +189,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -233,7 +234,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -268,7 +269,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Path = "/foo"; context.Request.Method = "POST"; - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -370,7 +371,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -396,7 +397,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -422,7 +423,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -448,7 +449,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -474,7 +475,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -506,7 +507,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -545,7 +546,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -583,7 +584,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -608,7 +609,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -643,7 +644,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -676,7 +677,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -707,7 +708,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -751,7 +752,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -795,7 +796,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new SocketBuilder(sp); + var builder = new ConnectionBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -840,7 +841,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new SocketBuilder(sp); + var builder = new ConnectionBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -892,7 +893,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new SocketBuilder(sp); + var builder = new ConnectionBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -952,7 +953,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new SocketBuilder(sp); + var builder = new ConnectionBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1030,7 +1031,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new SocketBuilder(sp); + var builder = new ConnectionBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1086,7 +1087,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new SocketBuilder(sp); + var builder = new ConnectionBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1116,7 +1117,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1196,7 +1197,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new SocketBuilder(services.BuildServiceProvider()); + var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs index 1ab370512a..0854c338ff 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging;