Use protocol.abstractions primitives instead of socket abstractions (#1432)

This commit is contained in:
David Fowler 2018-02-10 18:10:09 -08:00 committed by GitHub
parent 01f4bf01cc
commit 94155b0e89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 148 additions and 213 deletions

View File

@ -7,51 +7,52 @@
<BuildBundlerMinifierPackageVersion>2.4.337</BuildBundlerMinifierPackageVersion> <BuildBundlerMinifierPackageVersion>2.4.337</BuildBundlerMinifierPackageVersion>
<GoogleProtobufPackageVersion>3.1.0</GoogleProtobufPackageVersion> <GoogleProtobufPackageVersion>3.1.0</GoogleProtobufPackageVersion>
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15698</InternalAspNetCoreSdkPackageVersion> <InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15698</InternalAspNetCoreSdkPackageVersion>
<MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreAuthenticationCookiesPackageVersion> <MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>
<MicrosoftAspNetCoreAuthenticationCorePackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreAuthenticationCorePackageVersion> <MicrosoftAspNetCoreAuthenticationCorePackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreAuthenticationCorePackageVersion>
<MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion> <MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>
<MicrosoftAspNetCoreAuthorizationPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreAuthorizationPackageVersion> <MicrosoftAspNetCoreAuthorizationPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreAuthorizationPackageVersion>
<MicrosoftAspNetCoreAuthorizationPolicyPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreAuthorizationPolicyPackageVersion> <MicrosoftAspNetCoreAuthorizationPolicyPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreAuthorizationPolicyPackageVersion>
<MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion> <MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>
<MicrosoftAspNetCoreCorsPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreCorsPackageVersion> <MicrosoftAspNetCoreCorsPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreCorsPackageVersion>
<MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion> <MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion>
<MicrosoftAspNetCoreDiagnosticsPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreDiagnosticsPackageVersion> <MicrosoftAspNetCoreDiagnosticsPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreDiagnosticsPackageVersion>
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreHostingAbstractionsPackageVersion> <MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
<MicrosoftAspNetCoreHostingPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreHostingPackageVersion> <MicrosoftAspNetCoreHostingPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreHostingPackageVersion>
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreHttpAbstractionsPackageVersion> <MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
<MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreHttpFeaturesPackageVersion> <MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreHttpFeaturesPackageVersion>
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreHttpPackageVersion> <MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion> <MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreMvcPackageVersion> <MicrosoftAspNetCoreMvcPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreMvcPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreRoutingPackageVersion> <MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreServerIISIntegrationPackageVersion> <MicrosoftAspNetCoreRoutingPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.5.0-preview2-30066</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion> <MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreServerKestrelPackageVersion> <MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.5.0-preview2-30073</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
<MicrosoftAspNetCoreStaticFilesPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreStaticFilesPackageVersion> <MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreTestHostPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreTestHostPackageVersion> <MicrosoftAspNetCoreStaticFilesPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreStaticFilesPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreTestingPackageVersion> <MicrosoftAspNetCoreTestHostPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreTestHostPackageVersion>
<MicrosoftAspNetCoreWebSocketsPackageVersion>2.1.0-preview2-30066</MicrosoftAspNetCoreWebSocketsPackageVersion> <MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftAspNetCoreWebSocketsPackageVersion>2.1.0-preview2-30073</MicrosoftAspNetCoreWebSocketsPackageVersion>
<MicrosoftCSharpPackageVersion>4.5.0-preview2-26130-01</MicrosoftCSharpPackageVersion> <MicrosoftCSharpPackageVersion>4.5.0-preview2-26130-01</MicrosoftCSharpPackageVersion>
<MicrosoftEntityFrameworkCoreDesignPackageVersion>2.1.0-preview2-30066</MicrosoftEntityFrameworkCoreDesignPackageVersion> <MicrosoftEntityFrameworkCoreDesignPackageVersion>2.1.0-preview2-30073</MicrosoftEntityFrameworkCoreDesignPackageVersion>
<MicrosoftEntityFrameworkCoreSqlServerPackageVersion>2.1.0-preview2-30066</MicrosoftEntityFrameworkCoreSqlServerPackageVersion> <MicrosoftEntityFrameworkCoreSqlServerPackageVersion>2.1.0-preview2-30073</MicrosoftEntityFrameworkCoreSqlServerPackageVersion>
<MicrosoftEntityFrameworkCoreToolsPackageVersion>2.1.0-preview2-30066</MicrosoftEntityFrameworkCoreToolsPackageVersion> <MicrosoftEntityFrameworkCoreToolsPackageVersion>2.1.0-preview2-30073</MicrosoftEntityFrameworkCoreToolsPackageVersion>
<MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion> <MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion>
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion> <MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<MicrosoftExtensionsConfigurationCommandLinePackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsConfigurationCommandLinePackageVersion> <MicrosoftExtensionsConfigurationCommandLinePackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsConfigurationCommandLinePackageVersion>
<MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion> <MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>
<MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsConfigurationUserSecretsPackageVersion> <MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsConfigurationUserSecretsPackageVersion>
<MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion> <MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion>
<MicrosoftExtensionsDependencyInjectionPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsDependencyInjectionPackageVersion> <MicrosoftExtensionsDependencyInjectionPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsDependencyInjectionPackageVersion>
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsLoggingAbstractionsPackageVersion> <MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
<MicrosoftExtensionsLoggingConfigurationPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsLoggingConfigurationPackageVersion> <MicrosoftExtensionsLoggingConfigurationPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsLoggingConfigurationPackageVersion>
<MicrosoftExtensionsLoggingConsolePackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsLoggingConsolePackageVersion> <MicrosoftExtensionsLoggingConsolePackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsLoggingConsolePackageVersion>
<MicrosoftExtensionsLoggingDebugPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsLoggingDebugPackageVersion> <MicrosoftExtensionsLoggingDebugPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsLoggingDebugPackageVersion>
<MicrosoftExtensionsLoggingPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsLoggingPackageVersion> <MicrosoftExtensionsLoggingPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsLoggingPackageVersion>
<MicrosoftExtensionsLoggingTestingPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsLoggingTestingPackageVersion> <MicrosoftExtensionsLoggingTestingPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsLoggingTestingPackageVersion>
<MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion> <MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion>
<MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsOptionsPackageVersion> <MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsOptionsPackageVersion>
<MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsSecurityHelperSourcesPackageVersion> <MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsSecurityHelperSourcesPackageVersion>
<MicrosoftExtensionsValueStopwatchSourcesPackageVersion>2.1.0-preview2-30066</MicrosoftExtensionsValueStopwatchSourcesPackageVersion> <MicrosoftExtensionsValueStopwatchSourcesPackageVersion>2.1.0-preview2-30073</MicrosoftExtensionsValueStopwatchSourcesPackageVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion> <MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26130-04</MicrosoftNETCoreApp21PackageVersion> <MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26130-04</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion> <MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion>
@ -70,7 +71,7 @@
<SystemThreadingChannelsPackageVersion>4.5.0-preview2-26130-01</SystemThreadingChannelsPackageVersion> <SystemThreadingChannelsPackageVersion>4.5.0-preview2-26130-01</SystemThreadingChannelsPackageVersion>
<SystemThreadingTasksExtensionsPackageVersion>4.5.0-preview2-26130-01</SystemThreadingTasksExtensionsPackageVersion> <SystemThreadingTasksExtensionsPackageVersion>4.5.0-preview2-26130-01</SystemThreadingTasksExtensionsPackageVersion>
<XunitPackageVersion>2.3.1</XunitPackageVersion> <XunitPackageVersion>2.3.1</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.3.1</XunitRunnerVisualStudioPackageVersion> <XunitRunnerVisualStudioPackageVersion>2.4.0-beta.1.build3945</XunitRunnerVisualStudioPackageVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " /> <Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
</Project> </Project>

View File

@ -3,6 +3,7 @@
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
namespace FunctionalTests namespace FunctionalTests

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
using Microsoft.AspNetCore.Sockets.Features; using Microsoft.AspNetCore.Sockets.Features;
@ -23,9 +24,9 @@ namespace SocialWeather
public void OnConnectedAsync(ConnectionContext connection) public void OnConnectedAsync(ConnectionContext connection)
{ {
connection.Metadata["groups"] = new HashSet<string>(); connection.Features.Get<IConnectionMetadataFeature>().Metadata["groups"] = new HashSet<string>();
var format = connection.GetHttpContext().Request.Query["formatType"].ToString(); var format = connection.GetHttpContext().Request.Query["formatType"].ToString();
connection.Metadata["format"] = format; connection.Features.Get<IConnectionMetadataFeature>().Metadata["format"] = format;
if (string.Equals(format, "protobuf", StringComparison.OrdinalIgnoreCase)) if (string.Equals(format, "protobuf", StringComparison.OrdinalIgnoreCase))
{ {
var transferModeFeature = connection.Features.Get<ITransferModeFeature>(); var transferModeFeature = connection.Features.Get<ITransferModeFeature>();
@ -47,7 +48,7 @@ namespace SocialWeather
foreach (var connection in _connectionList) foreach (var connection in _connectionList)
{ {
var context = connection.GetHttpContext(); var context = connection.GetHttpContext();
var formatter = _formatterResolver.GetFormatter<T>((string)connection.Metadata["format"]); var formatter = _formatterResolver.GetFormatter<T>((string)connection.Features.Get<IConnectionMetadataFeature>().Metadata["format"]);
var ms = new MemoryStream(); var ms = new MemoryStream();
await formatter.WriteAsync(data, ms); await formatter.WriteAsync(data, ms);
@ -72,7 +73,7 @@ namespace SocialWeather
public void AddGroupAsync(ConnectionContext connection, string groupName) public void AddGroupAsync(ConnectionContext connection, string groupName)
{ {
var groups = (HashSet<string>)connection.Metadata["groups"]; var groups = (HashSet<string>)connection.Features.Get<IConnectionMetadataFeature>().Metadata["groups"];
lock (groups) lock (groups)
{ {
groups.Add(groupName); groups.Add(groupName);
@ -81,7 +82,7 @@ namespace SocialWeather
public void RemoveGroupAsync(ConnectionContext connection, string groupName) public void RemoveGroupAsync(ConnectionContext connection, string groupName)
{ {
var groups = (HashSet<string>)connection.Metadata["groups"]; var groups = (HashSet<string>)connection.Features.Get<IConnectionMetadataFeature>().Metadata["groups"];
if (groups != null) if (groups != null)
{ {
lock (groups) lock (groups)

View File

@ -3,7 +3,9 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
using Microsoft.AspNetCore.Sockets.Features;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace SocialWeather namespace SocialWeather
@ -32,7 +34,7 @@ namespace SocialWeather
public async Task ProcessRequests(ConnectionContext connection) public async Task ProcessRequests(ConnectionContext connection)
{ {
var formatter = _formatterResolver.GetFormatter<WeatherReport>( var formatter = _formatterResolver.GetFormatter<WeatherReport>(
(string)connection.Metadata["format"]); (string)connection.Features.Get<IConnectionMetadataFeature>().Metadata["format"]);
while (true) while (true)
{ {

View File

@ -5,7 +5,9 @@ using System.Collections.Generic;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
using Microsoft.AspNetCore.Sockets.Features;
namespace SocketsSample.EndPoints namespace SocketsSample.EndPoints
{ {
@ -17,7 +19,7 @@ namespace SocketsSample.EndPoints
{ {
Connections.Add(connection); Connections.Add(connection);
await Broadcast($"{connection.ConnectionId} connected ({connection.Metadata[ConnectionMetadataNames.Transport]})"); await Broadcast($"{connection.ConnectionId} connected ({connection.Features.Get<IConnectionMetadataFeature>().Metadata[ConnectionMetadataNames.Transport]})");
try try
{ {
@ -50,7 +52,7 @@ namespace SocketsSample.EndPoints
{ {
Connections.Remove(connection); Connections.Remove(connection);
await Broadcast($"{connection.ConnectionId} disconnected ({connection.Metadata[ConnectionMetadataNames.Transport]})"); await Broadcast($"{connection.ConnectionId} disconnected ({connection.Features.Get<IConnectionMetadataFeature>().Metadata[ConnectionMetadataNames.Transport]})");
} }
} }

View File

@ -3,8 +3,10 @@
using System.IO; using System.IO;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SocketsSample.Hubs;
namespace SocketsSample namespace SocketsSample
{ {
@ -23,7 +25,18 @@ namespace SocketsSample
{ {
factory.AddConsole(); 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<Chat>();
});
})
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>() .UseStartup<Startup>()

View File

@ -13,6 +13,7 @@ using System.Threading;
using System.Threading.Channels; using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.SignalR.Core; using Microsoft.AspNetCore.SignalR.Core;
using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal;
using Microsoft.AspNetCore.SignalR.Internal.Encoders; using Microsoft.AspNetCore.SignalR.Internal.Encoders;
@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.SignalR
public virtual IFeatureCollection Features => _connectionContext.Features; public virtual IFeatureCollection Features => _connectionContext.Features;
public virtual IDictionary<object, object> Metadata => _connectionContext.Metadata; public virtual IDictionary<object, object> Metadata => Features.Get<IConnectionMetadataFeature>().Metadata;
public virtual PipeReader Input => _connectionContext.Transport.Input; public virtual PipeReader Input => _connectionContext.Transport.Input;

View File

@ -11,10 +11,10 @@ using System.Threading;
using System.Threading.Channels; using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.SignalR.Core; using Microsoft.AspNetCore.SignalR.Core;
using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal;
using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.SignalR.Internal.Protocol;
using Microsoft.AspNetCore.Sockets;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.AspNetCore.Sockets;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -8,7 +9,7 @@ namespace Microsoft.AspNetCore.SignalR
{ {
public static class SignalRSocketBuilderExtensions public static class SignalRSocketBuilderExtensions
{ {
public static ISocketBuilder UseHub<THub>(this ISocketBuilder socketBuilder) where THub : Hub public static IConnectionBuilder UseHub<THub>(this IConnectionBuilder socketBuilder) where THub : Hub
{ {
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>(); var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>();
return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection));

View File

@ -6,29 +6,30 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
{ {
public class SocketBuilder : ISocketBuilder public class ConnectionBuilder : IConnectionBuilder
{ {
private readonly IList<Func<SocketDelegate, SocketDelegate>> _components = new List<Func<SocketDelegate, SocketDelegate>>(); private readonly IList<Func<ConnectionDelegate, ConnectionDelegate>> _components = new List<Func<ConnectionDelegate, ConnectionDelegate>>();
public IServiceProvider ApplicationServices { get; } public IServiceProvider ApplicationServices { get; }
public SocketBuilder(IServiceProvider applicationServices) public ConnectionBuilder(IServiceProvider applicationServices)
{ {
ApplicationServices = applicationServices; ApplicationServices = applicationServices;
} }
public ISocketBuilder Use(Func<SocketDelegate, SocketDelegate> middleware) public IConnectionBuilder Use(Func<ConnectionDelegate, ConnectionDelegate> middleware)
{ {
_components.Add(middleware); _components.Add(middleware);
return this; return this;
} }
public SocketDelegate Build() public ConnectionDelegate Build()
{ {
SocketDelegate app = features => ConnectionDelegate app = features =>
{ {
return Task.CompletedTask; return Task.CompletedTask;
}; };

View File

@ -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<object, object> Metadata { get; set; }
public abstract IDuplexPipe Transport { get; set; }
}
}

View File

@ -1,49 +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.IO.Pipelines;
namespace Microsoft.AspNetCore.Sockets
{
public class DuplexPipe : IDuplexPipe
{
public DuplexPipe(PipeReader reader, PipeWriter writer)
{
Input = reader;
Output = writer;
}
public PipeReader Input { get; }
public PipeWriter Output { get; }
public void Dispose()
{
}
public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions)
{
var input = new Pipe(inputOptions);
var output = new Pipe(outputOptions);
var transportToApplication = new DuplexPipe(output.Reader, input.Writer);
var applicationToTransport = new DuplexPipe(input.Reader, output.Writer);
return new DuplexPipePair(applicationToTransport, transportToApplication);
}
// This class exists to work around issues with value tuple on .NET Framework
public struct DuplexPipePair
{
public IDuplexPipe Transport { get; private set; }
public IDuplexPipe Application { get; private set; }
public DuplexPipePair(IDuplexPipe transport, IDuplexPipe application)
{
Transport = transport;
Application = application;
}
}
}
}

View File

@ -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<SocketDelegate, SocketDelegate> middleware);
SocketDelegate Build();
}
}

View File

@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="$(MicrosoftAspNetCoreHttpFeaturesPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="$(MicrosoftAspNetCoreHttpFeaturesPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Protocols.Abstractions" Version="$(MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion)" />
<PackageReference Include="System.Threading.Channels" Version="$(SystemThreadingChannelsPackageVersion)" /> <PackageReference Include="System.Threading.Channels" Version="$(SystemThreadingChannelsPackageVersion)" />
<PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" /> <PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryPackageVersion)" /> <PackageReference Include="System.Memory" Version="$(SystemMemoryPackageVersion)" />

View File

@ -3,12 +3,13 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
{ {
public static class SocketBuilderExtensions public static class SocketBuilderExtensions
{ {
public static ISocketBuilder Use(this ISocketBuilder socketBuilder, Func<ConnectionContext, Func<Task>, Task> middleware) public static IConnectionBuilder Use(this IConnectionBuilder socketBuilder, Func<ConnectionContext, Func<Task>, Task> middleware)
{ {
return socketBuilder.Use(next => return socketBuilder.Use(next =>
{ {
@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Sockets
}); });
} }
public static ISocketBuilder Run(this ISocketBuilder socketBuilder, Func<ConnectionContext, Task> middleware) public static IConnectionBuilder Run(this IConnectionBuilder socketBuilder, Func<ConnectionContext, Task> middleware)
{ {
return socketBuilder.Use(next => return socketBuilder.Use(next =>
{ {

View File

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

View File

@ -1,10 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Http;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets.Http.Features; using Microsoft.AspNetCore.Sockets.Http.Features;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets

View File

@ -10,6 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets.Features; using Microsoft.AspNetCore.Sockets.Features;
using Microsoft.AspNetCore.Sockets.Internal; using Microsoft.AspNetCore.Sockets.Internal;
using Microsoft.AspNetCore.Sockets.Internal.Transports; using Microsoft.AspNetCore.Sockets.Internal.Transports;
@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Sockets
_logger = _loggerFactory.CreateLogger<HttpConnectionDispatcher>(); _logger = _loggerFactory.CreateLogger<HttpConnectionDispatcher>();
} }
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 // 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 // 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)) else if (HttpMethods.IsGet(context.Request.Method))
{ {
// GET /{path} // GET /{path}
await ExecuteEndpointAsync(context, socketDelegate, options, logScope); await ExecuteEndpointAsync(context, ConnectionDelegate, options, logScope);
} }
else 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; 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. // 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); 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) else if (context.WebSockets.IsWebSocketRequest)
{ {
@ -141,7 +142,7 @@ namespace Microsoft.AspNetCore.Sockets
var ws = new WebSocketsTransport(options.WebSockets, connection.Application, connection, _loggerFactory); var ws = new WebSocketsTransport(options.WebSockets, connection.Application, connection, _loggerFactory);
await DoPersistentConnection(socketDelegate, ws, context, connection); await DoPersistentConnection(ConnectionDelegate, ws, context, connection);
} }
else else
{ {
@ -202,7 +203,7 @@ namespace Microsoft.AspNetCore.Sockets
connection.Metadata[ConnectionMetadataNames.Transport] = TransportType.LongPolling; connection.Metadata[ConnectionMetadataNames.Transport] = TransportType.LongPolling;
connection.ApplicationTask = ExecuteApplication(socketDelegate, connection); connection.ApplicationTask = ExecuteApplication(ConnectionDelegate, connection);
} }
else else
{ {
@ -291,7 +292,7 @@ namespace Microsoft.AspNetCore.Sockets
} }
} }
private async Task DoPersistentConnection(SocketDelegate socketDelegate, private async Task DoPersistentConnection(ConnectionDelegate ConnectionDelegate,
IHttpTransport transport, IHttpTransport transport,
HttpContext context, HttpContext context,
DefaultConnectionContext connection) DefaultConnectionContext connection)
@ -323,7 +324,7 @@ namespace Microsoft.AspNetCore.Sockets
connection.Status = DefaultConnectionContext.ConnectionStatus.Active; connection.Status = DefaultConnectionContext.ConnectionStatus.Active;
// Call into the end point passing the connection // Call into the end point passing the connection
connection.ApplicationTask = ExecuteApplication(socketDelegate, connection); connection.ApplicationTask = ExecuteApplication(ConnectionDelegate, connection);
// Start the transport // Start the transport
connection.TransportTask = transport.ProcessRequestAsync(context, context.RequestAborted); connection.TransportTask = transport.ProcessRequestAsync(context, context.RequestAborted);
@ -339,12 +340,12 @@ namespace Microsoft.AspNetCore.Sockets
await _manager.DisposeAndRemoveAsync(connection); await _manager.DisposeAndRemoveAsync(connection);
} }
private async Task ExecuteApplication(SocketDelegate socketDelegate, ConnectionContext connection) private async Task ExecuteApplication(ConnectionDelegate ConnectionDelegate, ConnectionContext connection)
{ {
// Verify some initialization invariants // 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. // 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(connection.Features.Get<IConnectionMetadataFeature>().Metadata[ConnectionMetadataNames.Transport] != null, "Transport has not been initialized yet");
Debug.Assert((TransportType?)connection.Metadata[ConnectionMetadataNames.Transport] != TransportType.LongPolling || Debug.Assert((TransportType?)connection.Features.Get<IConnectionMetadataFeature>().Metadata[ConnectionMetadataNames.Transport] != TransportType.LongPolling ||
connection.Features.Get<IConnectionInherentKeepAliveFeature>() != null, "Long-polling transport is in use but IConnectionInherentKeepAliveFeature as not configured"); connection.Features.Get<IConnectionInherentKeepAliveFeature>() != 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 // 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(); await AwaitableThreadPool.Yield();
// Running this in an async method turns sync exceptions into async ones // 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) private Task ProcessNegotiate(HttpContext context, HttpSocketOptions options, ConnectionLogScope logScope)

View File

@ -5,6 +5,7 @@ using System;
using System.Reflection; using System.Reflection;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
@ -20,15 +21,15 @@ namespace Microsoft.AspNetCore.Sockets
_dispatcher = dispatcher; _dispatcher = dispatcher;
} }
public void MapSocket(string path, Action<ISocketBuilder> socketConfig) => public void MapSocket(string path, Action<IConnectionBuilder> socketConfig) =>
MapSocket(new PathString(path), new HttpSocketOptions(), socketConfig); MapSocket(new PathString(path), new HttpSocketOptions(), socketConfig);
public void MapSocket(PathString path, Action<ISocketBuilder> socketConfig) => public void MapSocket(PathString path, Action<IConnectionBuilder> socketConfig) =>
MapSocket(path, new HttpSocketOptions(), socketConfig); MapSocket(path, new HttpSocketOptions(), socketConfig);
public void MapSocket(PathString path, HttpSocketOptions options, Action<ISocketBuilder> socketConfig) public void MapSocket(PathString path, HttpSocketOptions options, Action<IConnectionBuilder> socketConfig)
{ {
var socketBuilder = new SocketBuilder(_routes.ServiceProvider); var socketBuilder = new ConnectionBuilder(_routes.ServiceProvider);
socketConfig(socketBuilder); socketConfig(socketBuilder);
var socket = socketBuilder.Build(); var socket = socketBuilder.Build();
_routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket)); _routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket));

View File

@ -5,6 +5,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Protocols;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
{ {

View File

@ -2,12 +2,14 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Security.Claims; using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets.Features; using Microsoft.AspNetCore.Sockets.Features;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
@ -63,7 +65,7 @@ namespace Microsoft.AspNetCore.Sockets
public ClaimsPrincipal User { get; set; } public ClaimsPrincipal User { get; set; }
public override IDictionary<object, object> Metadata { get; set; } = new ConnectionMetadata(); public IDictionary<object, object> Metadata { get; set; } = new ConnectionMetadata();
public IDuplexPipe Application { get; } public IDuplexPipe Application { get; }

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
{ {

View File

@ -1,13 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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; using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
{ {
public static class SocketBuilderExtensions public static class SocketBuilderExtensions
{ {
public static ISocketBuilder UseEndPoint<TEndPoint>(this ISocketBuilder socketBuilder) where TEndPoint : EndPoint public static IConnectionBuilder UseEndPoint<TEndPoint>(this IConnectionBuilder socketBuilder) where TEndPoint : EndPoint
{ {
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<TEndPoint>(); var endpoint = socketBuilder.ApplicationServices.GetRequiredService<TEndPoint>();
// This is a terminal middleware, so there's no need to use the 'next' parameter // This is a terminal middleware, so there's no need to use the 'next' parameter

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public TestClient(bool synchronousCallbacks = false, IHubProtocol protocol = null, IInvocationBinder invocationBinder = null, bool addClaimId = false) public TestClient(bool synchronousCallbacks = false, IHubProtocol protocol = null, IInvocationBinder invocationBinder = null, bool addClaimId = false)
{ {
var options = new PipeOptions(readerScheduler: synchronousCallbacks ? PipeScheduler.Inline : null); var options = new PipeOptions(readerScheduler: synchronousCallbacks ? PipeScheduler.Inline : null);
var pair = Microsoft.AspNetCore.Sockets.DuplexPipe.CreateConnectionPair(options, options); var pair = DuplexPipe.CreateConnectionPair(options, options);
Connection = new DefaultConnectionContext(Guid.NewGuid().ToString(), pair.Transport, pair.Application); Connection = new DefaultConnectionContext(Guid.NewGuid().ToString(), pair.Transport, pair.Application);
var claimValue = Interlocked.Increment(ref _id).ToString(); var claimValue = Interlocked.Increment(ref _id).ToString();

View File

@ -3,6 +3,7 @@
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal;
using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.SignalR.Internal.Protocol;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;

View File

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Sockets.Features; using Microsoft.AspNetCore.Sockets.Features;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -116,7 +117,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Request.Query = qs; context.Request.Query = qs;
SetTransport(context, transportType); SetTransport(context, transportType);
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -151,7 +152,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var qs = new QueryCollection(values); var qs = new QueryCollection(values);
context.Request.Query = qs; context.Request.Query = qs;
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -188,7 +189,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var qs = new QueryCollection(values); var qs = new QueryCollection(values);
context.Request.Query = qs; context.Request.Query = qs;
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -233,7 +234,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var qs = new QueryCollection(values); var qs = new QueryCollection(values);
context.Request.Query = qs; context.Request.Query = qs;
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
@ -268,7 +269,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
SetTransport(context, transportType); SetTransport(context, transportType);
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Request.Path = "/foo"; context.Request.Path = "/foo";
context.Request.Method = "POST"; context.Request.Method = "POST";
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -370,7 +371,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>(); services.AddEndPoint<ImmediatelyCompleteEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>(); builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -396,7 +397,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<SynchronusExceptionEndPoint>(); services.AddEndPoint<SynchronusExceptionEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<SynchronusExceptionEndPoint>(); builder.UseEndPoint<SynchronusExceptionEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -422,7 +423,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>(); services.AddEndPoint<ImmediatelyCompleteEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>(); builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build(); var app = builder.Build();
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
@ -448,7 +449,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -474,7 +475,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>(); services.AddEndPoint<ImmediatelyCompleteEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>(); builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -506,7 +507,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -545,7 +546,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -583,7 +584,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -608,7 +609,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -643,7 +644,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<BlockingEndPoint>(); services.AddEndPoint<BlockingEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<BlockingEndPoint>(); builder.UseEndPoint<BlockingEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -676,7 +677,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<BlockingEndPoint>(); services.AddEndPoint<BlockingEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<BlockingEndPoint>(); builder.UseEndPoint<BlockingEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -707,7 +708,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -751,7 +752,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<ImmediatelyCompleteEndPoint>(); services.AddEndPoint<ImmediatelyCompleteEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>(); builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build(); var app = builder.Build();
@ -795,7 +796,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var qs = new QueryCollection(values); var qs = new QueryCollection(values);
context.Request.Query = qs; context.Request.Query = qs;
var builder = new SocketBuilder(sp); var builder = new ConnectionBuilder(sp);
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -840,7 +841,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var qs = new QueryCollection(values); var qs = new QueryCollection(values);
context.Request.Query = qs; context.Request.Query = qs;
var builder = new SocketBuilder(sp); var builder = new ConnectionBuilder(sp);
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -892,7 +893,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Request.Query = qs; context.Request.Query = qs;
context.Response.Body = new MemoryStream(); context.Response.Body = new MemoryStream();
var builder = new SocketBuilder(sp); var builder = new ConnectionBuilder(sp);
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -952,7 +953,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Request.Query = qs; context.Request.Query = qs;
context.Response.Body = new MemoryStream(); context.Response.Body = new MemoryStream();
var builder = new SocketBuilder(sp); var builder = new ConnectionBuilder(sp);
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -1030,7 +1031,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Request.Query = qs; context.Request.Query = qs;
context.Response.Body = new MemoryStream(); context.Response.Body = new MemoryStream();
var builder = new SocketBuilder(sp); var builder = new ConnectionBuilder(sp);
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -1086,7 +1087,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
context.Request.Query = qs; context.Request.Query = qs;
context.Response.Body = new MemoryStream(); context.Response.Body = new MemoryStream();
var builder = new SocketBuilder(sp); var builder = new ConnectionBuilder(sp);
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -1116,7 +1117,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddEndPoint<TestEndPoint>(); services.AddEndPoint<TestEndPoint>();
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<TestEndPoint>(); builder.UseEndPoint<TestEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();
@ -1196,7 +1197,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
var qs = new QueryCollection(values); var qs = new QueryCollection(values);
context.Request.Query = qs; context.Request.Query = qs;
var builder = new SocketBuilder(services.BuildServiceProvider()); var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseEndPoint<ImmediatelyCompleteEndPoint>(); builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
var app = builder.Build(); var app = builder.Build();
var options = new HttpSocketOptions(); var options = new HttpSocketOptions();

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;