diff --git a/build/dependencies.props b/build/dependencies.props index 142daeb465..eea44544e8 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,52 +7,51 @@ 2.4.337 3.1.0 2.1.0-preview2-15698 - 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 + 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 4.5.0-preview2-26130-01 - 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.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.0.0 2.1.0-preview2-26130-04 15.3.0 @@ -71,7 +70,7 @@ 4.5.0-preview2-26130-01 4.5.0-preview2-26130-01 2.3.1 - 2.4.0-beta.1.build3945 + 2.3.1 \ No newline at end of file diff --git a/client-ts/FunctionalTests/EchoEndPoint.cs b/client-ts/FunctionalTests/EchoEndPoint.cs index 27460590eb..0680acc8ca 100644 --- a/client-ts/FunctionalTests/EchoEndPoint.cs +++ b/client-ts/FunctionalTests/EchoEndPoint.cs @@ -3,7 +3,6 @@ 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 577254ae15..01093214a6 100644 --- a/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs +++ b/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs @@ -6,7 +6,6 @@ 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; @@ -24,9 +23,9 @@ namespace SocialWeather public void OnConnectedAsync(ConnectionContext connection) { - connection.Features.Get().Metadata["groups"] = new HashSet(); + connection.Metadata["groups"] = new HashSet(); var format = connection.GetHttpContext().Request.Query["formatType"].ToString(); - connection.Features.Get().Metadata["format"] = format; + connection.Metadata["format"] = format; if (string.Equals(format, "protobuf", StringComparison.OrdinalIgnoreCase)) { var transferModeFeature = connection.Features.Get(); @@ -48,7 +47,7 @@ namespace SocialWeather foreach (var connection in _connectionList) { var context = connection.GetHttpContext(); - var formatter = _formatterResolver.GetFormatter((string)connection.Features.Get().Metadata["format"]); + var formatter = _formatterResolver.GetFormatter((string)connection.Metadata["format"]); var ms = new MemoryStream(); await formatter.WriteAsync(data, ms); @@ -73,7 +72,7 @@ namespace SocialWeather public void AddGroupAsync(ConnectionContext connection, string groupName) { - var groups = (HashSet)connection.Features.Get().Metadata["groups"]; + var groups = (HashSet)connection.Metadata["groups"]; lock (groups) { groups.Add(groupName); @@ -82,7 +81,7 @@ namespace SocialWeather public void RemoveGroupAsync(ConnectionContext connection, string groupName) { - var groups = (HashSet)connection.Features.Get().Metadata["groups"]; + var groups = (HashSet)connection.Metadata["groups"]; if (groups != null) { lock (groups) diff --git a/samples/SocialWeather/SocialWeatherEndPoint.cs b/samples/SocialWeather/SocialWeatherEndPoint.cs index 38eaf60752..84dd03d919 100644 --- a/samples/SocialWeather/SocialWeatherEndPoint.cs +++ b/samples/SocialWeather/SocialWeatherEndPoint.cs @@ -3,9 +3,7 @@ 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 @@ -34,7 +32,7 @@ namespace SocialWeather public async Task ProcessRequests(ConnectionContext connection) { var formatter = _formatterResolver.GetFormatter( - (string)connection.Features.Get().Metadata["format"]); + (string)connection.Metadata["format"]); while (true) { diff --git a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs index 933e50fd73..0fd837f8bf 100644 --- a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs +++ b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs @@ -5,9 +5,7 @@ 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 { @@ -19,7 +17,7 @@ namespace SocketsSample.EndPoints { Connections.Add(connection); - await Broadcast($"{connection.ConnectionId} connected ({connection.Features.Get().Metadata[ConnectionMetadataNames.Transport]})"); + await Broadcast($"{connection.ConnectionId} connected ({connection.Metadata[ConnectionMetadataNames.Transport]})"); try { @@ -52,7 +50,7 @@ namespace SocketsSample.EndPoints { Connections.Remove(connection); - await Broadcast($"{connection.ConnectionId} disconnected ({connection.Features.Get().Metadata[ConnectionMetadataNames.Transport]})"); + await Broadcast($"{connection.ConnectionId} disconnected ({connection.Metadata[ConnectionMetadataNames.Transport]})"); } } diff --git a/samples/SocketsSample/Program.cs b/samples/SocketsSample/Program.cs index 3aea9e8472..aa6c67a8fe 100644 --- a/samples/SocketsSample/Program.cs +++ b/samples/SocketsSample/Program.cs @@ -3,10 +3,8 @@ using System.IO; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using SocketsSample.Hubs; namespace SocketsSample { @@ -25,18 +23,7 @@ namespace SocketsSample { factory.AddConsole(); }) - .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(); - }); - }) + .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs index 6cfb3bcc58..2913578a42 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs @@ -13,7 +13,6 @@ 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; @@ -65,7 +64,7 @@ namespace Microsoft.AspNetCore.SignalR public virtual IFeatureCollection Features => _connectionContext.Features; - public virtual IDictionary Metadata => Features.Get().Metadata; + public virtual IDictionary Metadata => _connectionContext.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 535c52e3f5..8c87c0abed 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 a1e0e5f5e6..eee93cc206 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs @@ -1,7 +1,6 @@ // 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; @@ -9,7 +8,7 @@ namespace Microsoft.AspNetCore.SignalR { public static class SignalRSocketBuilderExtensions { - public static IConnectionBuilder UseHub(this IConnectionBuilder socketBuilder) where THub : Hub + public static ISocketBuilder UseHub(this ISocketBuilder socketBuilder) where THub : Hub { var endpoint = socketBuilder.ApplicationServices.GetRequiredService>(); return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionContext.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionContext.cs new file mode 100644 index 0000000000..53779be11d --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionContext.cs @@ -0,0 +1,20 @@ +// 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 new file mode 100644 index 0000000000..f7d2f98513 --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/ISocketBuilder.cs @@ -0,0 +1,18 @@ +// 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 86f2e20454..4ad4e73092 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj @@ -8,7 +8,6 @@ - diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilder.cs similarity index 61% rename from src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilder.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilder.cs index b11ffc03cb..8dfc21b848 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilder.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilder.cs @@ -6,30 +6,29 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { - public class ConnectionBuilder : IConnectionBuilder + public class SocketBuilder : ISocketBuilder { - private readonly IList> _components = new List>(); + private readonly IList> _components = new List>(); public IServiceProvider ApplicationServices { get; } - public ConnectionBuilder(IServiceProvider applicationServices) + public SocketBuilder(IServiceProvider applicationServices) { ApplicationServices = applicationServices; } - public IConnectionBuilder Use(Func middleware) + public ISocketBuilder Use(Func middleware) { _components.Add(middleware); return this; } - public ConnectionDelegate Build() + public SocketDelegate Build() { - ConnectionDelegate app = features => + SocketDelegate app = features => { return Task.CompletedTask; }; diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs index 69dc9712d4..e8fe0db519 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs @@ -3,13 +3,12 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { public static class SocketBuilderExtensions { - public static IConnectionBuilder Use(this IConnectionBuilder socketBuilder, Func, Task> middleware) + public static ISocketBuilder Use(this ISocketBuilder socketBuilder, Func, Task> middleware) { return socketBuilder.Use(next => { @@ -21,7 +20,7 @@ namespace Microsoft.AspNetCore.Sockets }); } - public static IConnectionBuilder Run(this IConnectionBuilder socketBuilder, Func middleware) + public static ISocketBuilder Run(this ISocketBuilder 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 new file mode 100644 index 0000000000..45af07cd77 --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketDelegate.cs @@ -0,0 +1,12 @@ +// 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 8e538d47bf..74ce92ccd1 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs @@ -1,8 +1,10 @@ // 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 72766cc788..9ea7aaf9b5 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs @@ -10,7 +10,6 @@ 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; @@ -33,7 +32,7 @@ namespace Microsoft.AspNetCore.Sockets _logger = _loggerFactory.CreateLogger(); } - public async Task ExecuteAsync(HttpContext context, HttpSocketOptions options, ConnectionDelegate ConnectionDelegate) + public async Task ExecuteAsync(HttpContext context, HttpSocketOptions options, SocketDelegate socketDelegate) { // 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 @@ -54,7 +53,7 @@ namespace Microsoft.AspNetCore.Sockets else if (HttpMethods.IsGet(context.Request.Method)) { // GET /{path} - await ExecuteEndpointAsync(context, ConnectionDelegate, options, logScope); + await ExecuteEndpointAsync(context, socketDelegate, options, logScope); } else { @@ -88,7 +87,7 @@ namespace Microsoft.AspNetCore.Sockets } } - private async Task ExecuteEndpointAsync(HttpContext context, ConnectionDelegate ConnectionDelegate, HttpSocketOptions options, ConnectionLogScope logScope) + private async Task ExecuteEndpointAsync(HttpContext context, SocketDelegate socketDelegate, HttpSocketOptions options, ConnectionLogScope logScope) { var supportedTransports = options.Transports; @@ -120,7 +119,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(ConnectionDelegate, sse, context, connection); + await DoPersistentConnection(socketDelegate, sse, context, connection); } else if (context.WebSockets.IsWebSocketRequest) { @@ -142,7 +141,7 @@ namespace Microsoft.AspNetCore.Sockets var ws = new WebSocketsTransport(options.WebSockets, connection.Application, connection, _loggerFactory); - await DoPersistentConnection(ConnectionDelegate, ws, context, connection); + await DoPersistentConnection(socketDelegate, ws, context, connection); } else { @@ -203,7 +202,7 @@ namespace Microsoft.AspNetCore.Sockets connection.Metadata[ConnectionMetadataNames.Transport] = TransportType.LongPolling; - connection.ApplicationTask = ExecuteApplication(ConnectionDelegate, connection); + connection.ApplicationTask = ExecuteApplication(socketDelegate, connection); } else { @@ -292,7 +291,7 @@ namespace Microsoft.AspNetCore.Sockets } } - private async Task DoPersistentConnection(ConnectionDelegate ConnectionDelegate, + private async Task DoPersistentConnection(SocketDelegate socketDelegate, IHttpTransport transport, HttpContext context, DefaultConnectionContext connection) @@ -324,7 +323,7 @@ namespace Microsoft.AspNetCore.Sockets connection.Status = DefaultConnectionContext.ConnectionStatus.Active; // Call into the end point passing the connection - connection.ApplicationTask = ExecuteApplication(ConnectionDelegate, connection); + connection.ApplicationTask = ExecuteApplication(socketDelegate, connection); // Start the transport connection.TransportTask = transport.ProcessRequestAsync(context, context.RequestAborted); @@ -340,12 +339,12 @@ namespace Microsoft.AspNetCore.Sockets await _manager.DisposeAndRemoveAsync(connection); } - private async Task ExecuteApplication(ConnectionDelegate ConnectionDelegate, ConnectionContext connection) + private async Task ExecuteApplication(SocketDelegate socketDelegate, 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.Features.Get().Metadata[ConnectionMetadataNames.Transport] != null, "Transport has not been initialized yet"); - Debug.Assert((TransportType?)connection.Features.Get().Metadata[ConnectionMetadataNames.Transport] != TransportType.LongPolling || + Debug.Assert(connection.Metadata[ConnectionMetadataNames.Transport] != null, "Transport has not been initialized yet"); + Debug.Assert((TransportType?)connection.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 @@ -353,7 +352,7 @@ namespace Microsoft.AspNetCore.Sockets await AwaitableThreadPool.Yield(); // Running this in an async method turns sync exceptions into async ones - await ConnectionDelegate(connection); + await socketDelegate(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 96df652cc5..99b92af5d5 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs @@ -5,7 +5,6 @@ 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 @@ -21,15 +20,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 ConnectionBuilder(_routes.ServiceProvider); + var socketBuilder = new SocketBuilder(_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 ea3e201c95..0b9b799406 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs +++ b/src/Microsoft.AspNetCore.Sockets/ConnectionList.cs @@ -5,7 +5,6 @@ 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 e3f6281e66..eb7b727673 100644 --- a/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Sockets/DefaultConnectionContext.cs @@ -2,14 +2,12 @@ // 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; @@ -65,7 +63,7 @@ namespace Microsoft.AspNetCore.Sockets public ClaimsPrincipal User { get; set; } - public IDictionary Metadata { get; set; } = new ConnectionMetadata(); + public override IDictionary Metadata { get; set; } = new ConnectionMetadata(); public IDuplexPipe Application { get; } @@ -75,8 +73,6 @@ 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 89de4b79fa..d23fbeddf4 100644 --- a/src/Microsoft.AspNetCore.Sockets/EndPoint.cs +++ b/src/Microsoft.AspNetCore.Sockets/EndPoint.cs @@ -2,7 +2,6 @@ // 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 1e4d5cd688..f0d6d3387b 100644 --- a/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs @@ -1,14 +1,13 @@ // 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 IConnectionBuilder UseEndPoint(this IConnectionBuilder socketBuilder) where TEndPoint : EndPoint + public static ISocketBuilder UseEndPoint(this ISocketBuilder 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 b31f85c7dd..839e98088b 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs @@ -3,7 +3,6 @@ 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 61910660a3..ea571661a8 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs @@ -3,7 +3,6 @@ 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 11998ab298..aac60adee8 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -15,7 +15,6 @@ 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; @@ -117,7 +116,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; SetTransport(context, transportType); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -152,7 +151,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -189,7 +188,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -234,7 +233,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -269,7 +268,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -298,7 +297,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Path = "/foo"; context.Request.Method = "POST"; - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -371,7 +370,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -397,7 +396,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -423,7 +422,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); @@ -449,7 +448,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -475,7 +474,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -507,7 +506,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -546,7 +545,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -584,7 +583,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -609,7 +608,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -644,7 +643,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -677,7 +676,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -708,7 +707,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -752,7 +751,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); @@ -796,7 +795,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new ConnectionBuilder(sp); + var builder = new SocketBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -841,7 +840,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new ConnectionBuilder(sp); + var builder = new SocketBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -893,7 +892,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new ConnectionBuilder(sp); + var builder = new SocketBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -953,7 +952,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new ConnectionBuilder(sp); + var builder = new SocketBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1031,7 +1030,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new ConnectionBuilder(sp); + var builder = new SocketBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1087,7 +1086,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; context.Response.Body = new MemoryStream(); - var builder = new ConnectionBuilder(sp); + var builder = new SocketBuilder(sp); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1117,7 +1116,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var services = new ServiceCollection(); services.AddEndPoint(); - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(services.BuildServiceProvider()); builder.UseEndPoint(); var app = builder.Build(); var options = new HttpSocketOptions(); @@ -1197,7 +1196,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var qs = new QueryCollection(values); context.Request.Query = qs; - var builder = new ConnectionBuilder(services.BuildServiceProvider()); + var builder = new SocketBuilder(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 0854c338ff..1ab370512a 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs @@ -10,7 +10,6 @@ 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;