Renames from API review (#2413)

* Renames from API review
- Rename Microsoft.AspNetCore.Protocols.Abstractions to Microsoft.AspNetCore.Connections.Abstractions.
- Renamed IConnectionHandler to IConnectionDispatcher (and related properties and types)
- Added ConnectionHandler and UseConnectionHandler extension method to Connections.Abstractions.
-  Use ActivatorUtilties to create the ConnectionHandler
This commit is contained in:
David Fowler 2018-03-22 21:38:14 -07:00 committed by GitHub
parent 54e538dcb5
commit abdcb47b8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 154 additions and 126 deletions

View File

@ -100,7 +100,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestr
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{A95C3BE1-B850-4265-97A0-777ADCCD437F}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{A95C3BE1-B850-4265-97A0-777ADCCD437F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "src\Protocols.Abstractions\Protocols.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connections.Abstractions", "src\Connections.Abstractions\Connections.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject

View File

@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
_connectionsPerEndPoint = connectionsPerEndPoint; _connectionsPerEndPoint = connectionsPerEndPoint;
} }
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher handler)
{ {
var connections = new InMemoryConnection[_connectionsPerEndPoint]; var connections = new InMemoryConnection[_connectionsPerEndPoint];
for (var i = 0; i < _connectionsPerEndPoint; i++) for (var i = 0; i < _connectionsPerEndPoint; i++)
@ -124,12 +124,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
public class InMemoryTransport : ITransport public class InMemoryTransport : ITransport
{ {
private readonly IConnectionHandler _handler; private readonly IConnectionDispatcher _dispatcher;
private readonly IReadOnlyList<InMemoryConnection> _connections; private readonly IReadOnlyList<InMemoryConnection> _connections;
public InMemoryTransport(IConnectionHandler handler, IReadOnlyList<InMemoryConnection> connections) public InMemoryTransport(IConnectionDispatcher dispatcher, IReadOnlyList<InMemoryConnection> connections)
{ {
_handler = handler; _dispatcher = dispatcher;
_connections = connections; _connections = connections;
} }
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
foreach (var connection in _connections) foreach (var connection in _connections)
{ {
_handler.OnConnection(connection); _dispatcher.OnConnection(connection);
} }
return Task.CompletedTask; return Task.CompletedTask;

View File

@ -16,6 +16,7 @@
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpPackageVersion> <MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreTestingPackageVersion> <MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreWebUtilitiesPackageVersion> <MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
<MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion>
<MicrosoftExtensionsBuffersSourcesPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsBuffersSourcesPackageVersion> <MicrosoftExtensionsBuffersSourcesPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsBuffersSourcesPackageVersion>
<MicrosoftExtensionsBuffersTestingSourcesPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsBuffersTestingSourcesPackageVersion> <MicrosoftExtensionsBuffersTestingSourcesPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsBuffersTestingSourcesPackageVersion>
<MicrosoftExtensionsConfigurationBinderPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsConfigurationBinderPackageVersion> <MicrosoftExtensionsConfigurationBinderPackageVersion>2.1.0-preview2-30355</MicrosoftExtensionsConfigurationBinderPackageVersion>

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public class ConnectionBuilder : IConnectionBuilder public class ConnectionBuilder : IConnectionBuilder
{ {

View File

@ -3,11 +3,20 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public static class ConnectionBuilderExtensions public static class ConnectionBuilderExtensions
{ {
public static IConnectionBuilder UseConnectionHandler<TConnectionHandler>(this IConnectionBuilder connectionBuilder) where TConnectionHandler : ConnectionHandler
{
var handler = ActivatorUtilities.GetServiceOrCreateInstance<TConnectionHandler>(connectionBuilder.ApplicationServices);
// This is a terminal middleware, so there's no need to use the 'next' parameter
return connectionBuilder.Run(connection => handler.OnConnectedAsync(connection));
}
public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func<ConnectionContext, Func<Task>, Task> middleware) public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func<ConnectionContext, Func<Task>, Task> middleware)
{ {
return connectionBuilder.Use(next => return connectionBuilder.Use(next =>

View File

@ -2,7 +2,7 @@
using System.IO.Pipelines; using System.IO.Pipelines;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public abstract class ConnectionContext public abstract class ConnectionContext
{ {

View File

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public delegate Task ConnectionDelegate(ConnectionContext connection); public delegate Task ConnectionDelegate(ConnectionContext connection);
} }

View File

@ -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.Threading.Tasks;
namespace Microsoft.AspNetCore.Connections
{
/// <summary>
/// Represents an end point that multiple connections connect to. For HTTP, endpoints are URLs, for non HTTP it can be a TCP listener (or similar)
/// </summary>
public abstract class ConnectionHandler
{
/// <summary>
/// Called when a new connection is accepted to the endpoint
/// </summary>
/// <param name="connection">The new <see cref="ConnectionContext"/></param>
/// <returns>A <see cref="Task"/> that represents the connection lifetime. When the task completes, the connection is complete.</returns>
public abstract Task OnConnectedAsync(ConnectionContext connection);
}
}

View File

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<AssemblyName>Microsoft.AspNetCore.Protocols.Abstractions</AssemblyName> <AssemblyName>Microsoft.AspNetCore.Connections.Abstractions</AssemblyName>
<RootNamespace>Microsoft.AspNetCore.Protocols.Abstractions</RootNamespace> <RootNamespace>Microsoft.AspNetCore.Connections.Abstractions</RootNamespace>
<Description>Core components of ASP.NET Core networking protocol stack.</Description> <Description>Core components of ASP.NET Core networking protocol stack.</Description>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
@ -13,11 +13,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="$(MicrosoftAspNetCoreHttpFeaturesPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="$(MicrosoftAspNetCoreHttpFeaturesPackageVersion)" />
<PackageReference Include="System.Numerics.Vectors" Version="$(SystemNumericsVectorsPackageVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersPackageVersion)" />
<PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" /> <PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.ActivatorUtilities.Sources" Version="$(MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,9 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Pipelines; using System.IO.Pipelines;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Connections.Features;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public class DefaultConnectionContext : ConnectionContext public class DefaultConnectionContext : ConnectionContext
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public class AddressInUseException : InvalidOperationException public class AddressInUseException : InvalidOperationException
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public class ConnectionAbortedException : OperationCanceledException public class ConnectionAbortedException : OperationCanceledException
{ {

View File

@ -4,7 +4,7 @@
using System; using System;
using System.IO; using System.IO;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public class ConnectionResetException : IOException public class ConnectionResetException : IOException
{ {

View File

@ -5,7 +5,7 @@ using System.Buffers;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading; using System.Threading;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IApplicationTransportFeature public interface IApplicationTransportFeature
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IConnectionHeartbeatFeature public interface IConnectionHeartbeatFeature
{ {

View File

@ -1,7 +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.
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IConnectionIdFeature public interface IConnectionIdFeature
{ {

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
/// <summary> /// <summary>
/// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically /// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IConnectionItemsFeature public interface IConnectionItemsFeature
{ {

View File

@ -5,7 +5,7 @@ using System.Buffers;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading; using System.Threading;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IConnectionTransportFeature public interface IConnectionTransportFeature
{ {

View File

@ -1,6 +1,6 @@
using System.Security.Claims; using System.Security.Claims;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IConnectionUserFeature public interface IConnectionUserFeature
{ {

View File

@ -5,7 +5,7 @@ using System.Buffers;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading; using System.Threading;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface IMemoryPoolFeature public interface IMemoryPoolFeature
{ {

View File

@ -1,7 +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.
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface ITransferFormatFeature public interface ITransferFormatFeature
{ {

View File

@ -5,7 +5,7 @@ using System.Buffers;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading; using System.Threading;
namespace Microsoft.AspNetCore.Protocols.Features namespace Microsoft.AspNetCore.Connections.Features
{ {
public interface ITransportSchedulerFeature public interface ITransportSchedulerFeature
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
public interface IConnectionBuilder public interface IConnectionBuilder
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Protocols namespace Microsoft.AspNetCore.Connections
{ {
[Flags] [Flags]
public enum TransferFormat public enum TransferFormat

View File

@ -10,7 +10,7 @@ using System.Threading.Tasks;
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.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -2,7 +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; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;

View File

@ -7,20 +7,20 @@ using System.IO.Pipelines;
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.Connections;
using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
{ {
public class ConnectionHandler : IConnectionHandler public class ConnectionDispatcher : IConnectionDispatcher
{ {
private readonly ServiceContext _serviceContext; private readonly ServiceContext _serviceContext;
private readonly ConnectionDelegate _connectionDelegate; private readonly ConnectionDelegate _connectionDelegate;
public ConnectionHandler(ServiceContext serviceContext, ConnectionDelegate connectionDelegate) public ConnectionDispatcher(ServiceContext serviceContext, ConnectionDelegate connectionDelegate)
{ {
_serviceContext = serviceContext; _serviceContext = serviceContext;
_connectionDelegate = connectionDelegate; _connectionDelegate = connectionDelegate;
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.LogCritical(0, ex, $"{nameof(ConnectionHandler)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); Log.LogCritical(0, ex, $"{nameof(ConnectionDispatcher)}.{nameof(Execute)}() {connectionContext.ConnectionId}");
} }
Log.ConnectionStop(connectionContext.ConnectionId); Log.ConnectionStop(connectionContext.ConnectionId);

View File

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Connections.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http

View File

@ -8,7 +8,7 @@ using System.IO;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Connections.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http

View File

@ -16,7 +16,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
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.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;

View File

@ -7,7 +7,7 @@ using System.Runtime.ExceptionServices;
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.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http

View File

@ -4,7 +4,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Protocols.Abstractions namespace Microsoft.AspNetCore.Connections.Abstractions
{ {
internal class UrlDecoder internal class UrlDecoder
{ {

View File

@ -10,7 +10,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal

View File

@ -4,8 +4,8 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal

View File

@ -4,7 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
{ {

View File

@ -24,6 +24,7 @@
<PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" /> <PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" /> <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="$(SystemSecurityCryptographyCngPackageVersion)" /> <PackageReference Include="System.Security.Cryptography.Cng" Version="$(SystemSecurityCryptographyCngPackageVersion)" />
<PackageReference Include="System.Numerics.Vectors" Version="$(SystemNumericsVectorsPackageVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -148,8 +148,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
connectionDelegate = new ConnectionLimitMiddleware(connectionDelegate, Options.Limits.MaxConcurrentConnections.Value, Trace).OnConnectionAsync; connectionDelegate = new ConnectionLimitMiddleware(connectionDelegate, Options.Limits.MaxConcurrentConnections.Value, Trace).OnConnectionAsync;
} }
var connectionHandler = new ConnectionHandler(ServiceContext, connectionDelegate); var connectionDispatcher = new ConnectionDispatcher(ServiceContext, connectionDelegate);
var transport = _transportFactory.Create(endpoint, connectionHandler); var transport = _transportFactory.Create(endpoint, connectionDispatcher);
_transports.Add(transport); _transports.Add(transport);
await transport.BindAsync().ConfigureAwait(false); await transport.BindAsync().ConfigureAwait(false);

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
{ {
public interface IConnectionHandler public interface IConnectionDispatcher
{ {
void OnConnection(TransportConnection connection); void OnConnection(TransportConnection connection);
} }

View File

@ -5,6 +5,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
{ {
public interface ITransportFactory public interface ITransportFactory
{ {
ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler); ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher);
} }
} }

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Net; using System.Net;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Connections.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
{ {

View File

@ -13,7 +13,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Protocols.Abstractions\Protocols.Abstractions.csproj" /> <ProjectReference Include="..\Connections.Abstractions\Connections.Abstractions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" /> <PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" />

View File

@ -7,7 +7,7 @@ using System.IO;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -48,14 +48,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
public LibuvOutputConsumer OutputConsumer { get; set; } public LibuvOutputConsumer OutputConsumer { get; set; }
private ILibuvTrace Log => ListenerContext.TransportContext.Log; private ILibuvTrace Log => ListenerContext.TransportContext.Log;
private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; private IConnectionDispatcher ConnectionDispatcher => ListenerContext.TransportContext.ConnectionDispatcher;
private LibuvThread Thread => ListenerContext.Thread; private LibuvThread Thread => ListenerContext.Thread;
public async Task Start() public async Task Start()
{ {
try try
{ {
ConnectionHandler.OnConnection(this); ConnectionDispatcher.OnConnection(this);
OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log); OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log);

View File

@ -14,6 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
public ILibuvTrace Log { get; set; } public ILibuvTrace Log { get; set; }
public IConnectionHandler ConnectionHandler { get; set; } public IConnectionDispatcher ConnectionDispatcher { get; set; }
} }
} }

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking;

View File

@ -62,14 +62,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
}; };
} }
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
{ {
var transportContext = new LibuvTransportContext var transportContext = new LibuvTransportContext
{ {
Options = _baseTransportContext.Options, Options = _baseTransportContext.Options,
AppLifetime = _baseTransportContext.AppLifetime, AppLifetime = _baseTransportContext.AppLifetime,
Log = _baseTransportContext.Log, Log = _baseTransportContext.Log,
ConnectionHandler = handler ConnectionDispatcher = dispatcher
}; };
return new LibuvTransport(transportContext, endPointInformation); return new LibuvTransport(transportContext, endPointInformation);

View File

@ -10,7 +10,7 @@ using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -60,12 +60,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
public override PipeScheduler InputWriterScheduler => _scheduler; public override PipeScheduler InputWriterScheduler => _scheduler;
public override PipeScheduler OutputReaderScheduler => _scheduler; public override PipeScheduler OutputReaderScheduler => _scheduler;
public async Task StartAsync(IConnectionHandler connectionHandler) public async Task StartAsync(IConnectionDispatcher connectionDispatcher)
{ {
Exception sendError = null; Exception sendError = null;
try try
{ {
connectionHandler.OnConnection(this); connectionDispatcher.OnConnection(this);
// Spawn send and receive logic // Spawn send and receive logic
Task receiveTask = DoReceive(); Task receiveTask = DoReceive();

View File

@ -11,7 +11,7 @@ using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
private readonly MemoryPool<byte> _memoryPool = KestrelMemoryPool.Create(); private readonly MemoryPool<byte> _memoryPool = KestrelMemoryPool.Create();
private readonly IEndPointInformation _endPointInformation; private readonly IEndPointInformation _endPointInformation;
private readonly IConnectionHandler _handler; private readonly IConnectionDispatcher _dispatcher;
private readonly IApplicationLifetime _appLifetime; private readonly IApplicationLifetime _appLifetime;
private readonly int _numSchedulers; private readonly int _numSchedulers;
private readonly PipeScheduler[] _schedulers; private readonly PipeScheduler[] _schedulers;
@ -36,19 +36,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
internal SocketTransport( internal SocketTransport(
IEndPointInformation endPointInformation, IEndPointInformation endPointInformation,
IConnectionHandler handler, IConnectionDispatcher dispatcher,
IApplicationLifetime applicationLifetime, IApplicationLifetime applicationLifetime,
int ioQueueCount, int ioQueueCount,
ISocketsTrace trace) ISocketsTrace trace)
{ {
Debug.Assert(endPointInformation != null); Debug.Assert(endPointInformation != null);
Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint); Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint);
Debug.Assert(handler != null); Debug.Assert(dispatcher != null);
Debug.Assert(applicationLifetime != null); Debug.Assert(applicationLifetime != null);
Debug.Assert(trace != null); Debug.Assert(trace != null);
_endPointInformation = endPointInformation; _endPointInformation = endPointInformation;
_handler = handler; _dispatcher = dispatcher;
_appLifetime = applicationLifetime; _appLifetime = applicationLifetime;
_trace = trace; _trace = trace;
@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
acceptSocket.NoDelay = _endPointInformation.NoDelay; acceptSocket.NoDelay = _endPointInformation.NoDelay;
var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace); var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace);
_ = connection.StartAsync(_handler); _ = connection.StartAsync(_dispatcher);
} }
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset)
{ {

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
_trace = new SocketsTrace(logger); _trace = new SocketsTrace(logger);
} }
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
{ {
if (endPointInformation == null) if (endPointInformation == null)
{ {
@ -52,12 +52,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation)); throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation));
} }
if (handler == null) if (dispatcher == null)
{ {
throw new ArgumentNullException(nameof(handler)); throw new ArgumentNullException(nameof(dispatcher));
} }
return new SocketTransport(endPointInformation, handler, _appLifetime, _options.IOQueueCount, _trace); return new SocketTransport(endPointInformation, dispatcher, _appLifetime, _options.IOQueueCount, _trace);
} }
} }
} }

View File

@ -5,7 +5,7 @@ using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;

View File

@ -5,7 +5,7 @@ using System.Linq;
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.Features; using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
@ -14,18 +14,18 @@ using Xunit;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
{ {
public class ConnectionHandlerTests public class ConnectionDispatcherTests
{ {
[Fact] [Fact]
public void OnConnectionCreatesLogScopeWithConnectionId() public void OnConnectionCreatesLogScopeWithConnectionId()
{ {
var serviceContext = new TestServiceContext(); var serviceContext = new TestServiceContext();
var tcs = new TaskCompletionSource<object>(); var tcs = new TaskCompletionSource<object>();
var handler = new ConnectionHandler(serviceContext, _ => tcs.Task); var dispatcher = new ConnectionDispatcher(serviceContext, _ => tcs.Task);
var connection = new TestConnection(); var connection = new TestConnection();
handler.OnConnection(connection); dispatcher.OnConnection(connection);
// The scope should be created // The scope should be created
var scopeObjects = ((TestKestrelTrace)serviceContext.Log) var scopeObjects = ((TestKestrelTrace)serviceContext.Log)

View File

@ -12,7 +12,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;

View File

@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
Assert.Contains(server.Options.ListenOptions[0].ConnectionAdapters, adapter => adapter.IsHttps); Assert.Contains(server.Options.ListenOptions[0].ConnectionAdapters, adapter => adapter.IsHttps);
} }
} }
[Fact] [Fact]
public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded() public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded()
{ {
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
Assert.Equal(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound, ex.Message); Assert.Equal(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound, ex.Message);
} }
} }
[Fact] [Fact]
public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButNoHttpUrls() public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButNoHttpUrls()
{ {
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
StartDummyApplication(server); StartDummyApplication(server);
} }
} }
[Fact] [Fact]
public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButManualListenOptions() public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButManualListenOptions()
{ {
@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockTransportFactory = new Mock<ITransportFactory>(); var mockTransportFactory = new Mock<ITransportFactory>();
mockTransportFactory mockTransportFactory
.Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionHandler>())) .Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionDispatcher>()))
.Returns(mockTransport.Object); .Returns(mockTransport.Object);
var mockLoggerFactory = new Mock<ILoggerFactory>(); var mockLoggerFactory = new Mock<ILoggerFactory>();
@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockTransportFactory = new Mock<ITransportFactory>(); var mockTransportFactory = new Mock<ITransportFactory>();
mockTransportFactory mockTransportFactory
.Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionHandler>())) .Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionDispatcher>()))
.Returns(mockTransport.Object); .Returns(mockTransport.Object);
var mockLoggerFactory = new Mock<ILoggerFactory>(); var mockLoggerFactory = new Mock<ILoggerFactory>();
@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
private class MockTransportFactory : ITransportFactory private class MockTransportFactory : ITransportFactory
{ {
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher handler)
{ {
return Mock.Of<ITransport>(); return Mock.Of<ITransport>();
} }

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
serviceContext.Scheduler = PipeScheduler.ThreadPool; serviceContext.Scheduler = PipeScheduler.ThreadPool;
var mockScheduler = Mock.Of<PipeScheduler>(); var mockScheduler = Mock.Of<PipeScheduler>();
var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, KestrelMemoryPool.Create(), readerScheduler: mockScheduler); var outputPipeOptions = ConnectionDispatcher.GetOutputPipeOptions(serviceContext, KestrelMemoryPool.Create(), readerScheduler: mockScheduler);
Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.ResumeWriterThreshold);
Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold);
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
serviceContext.Scheduler = PipeScheduler.ThreadPool; serviceContext.Scheduler = PipeScheduler.ThreadPool;
var mockScheduler = Mock.Of<PipeScheduler>(); var mockScheduler = Mock.Of<PipeScheduler>();
var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, KestrelMemoryPool.Create(), writerScheduler: mockScheduler); var inputPipeOptions = ConnectionDispatcher.GetInputPipeOptions(serviceContext, KestrelMemoryPool.Create(), writerScheduler: mockScheduler);
Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.ResumeWriterThreshold);
Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold);

View File

@ -18,7 +18,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
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.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;

View File

@ -19,9 +19,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
[Fact] [Fact]
public async Task DoesNotEndConnectionOnZeroRead() public async Task DoesNotEndConnectionOnZeroRead()
{ {
var mockConnectionHandler = new MockConnectionHandler(); var mockConnectionDispatcher = new MockConnectionDispatcher();
var mockLibuv = new MockLibuv(); var mockLibuv = new MockLibuv();
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
var transport = new LibuvTransport(mockLibuv, transportContext, null); var transport = new LibuvTransport(mockLibuv, transportContext, null);
var thread = new LibuvThread(transport); var thread = new LibuvThread(transport);
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored);
}, (object)null); }, (object)null);
var readAwaitable = mockConnectionHandler.Input.Reader.ReadAsync(); var readAwaitable = mockConnectionDispatcher.Input.Reader.ReadAsync();
Assert.False(readAwaitable.IsCompleted); Assert.False(readAwaitable.IsCompleted);
} }
finally finally
@ -54,12 +54,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
[Fact] [Fact]
public async Task ConnectionDoesNotResumeAfterSocketCloseIfBackpressureIsApplied() public async Task ConnectionDoesNotResumeAfterSocketCloseIfBackpressureIsApplied()
{ {
var mockConnectionHandler = new MockConnectionHandler(); var mockConnectionDispatcher = new MockConnectionDispatcher();
var mockLibuv = new MockLibuv(); var mockLibuv = new MockLibuv();
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
var transport = new LibuvTransport(mockLibuv, transportContext, null); var transport = new LibuvTransport(mockLibuv, transportContext, null);
var thread = new LibuvThread(transport); var thread = new LibuvThread(transport);
mockConnectionHandler.InputOptions = pool => mockConnectionDispatcher.InputOptions = pool =>
new PipeOptions( new PipeOptions(
pool: pool, pool: pool,
pauseWriterThreshold: 3, pauseWriterThreshold: 3,
@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
// We don't set the output writer scheduler here since we want to run the callback inline // We don't set the output writer scheduler here since we want to run the callback inline
mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); mockConnectionDispatcher.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
Task connectionTask = null; Task connectionTask = null;
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
Assert.Null(mockLibuv.ReadCallback); Assert.Null(mockLibuv.ReadCallback);
// Now complete the output writer so that the connection closes // Now complete the output writer so that the connection closes
mockConnectionHandler.Output.Writer.Complete(); mockConnectionDispatcher.Output.Writer.Complete();
await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout);
@ -115,9 +115,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
[Fact] [Fact]
public async Task ConnectionDoesNotResumeAfterReadCallbackScheduledAndSocketCloseIfBackpressureIsApplied() public async Task ConnectionDoesNotResumeAfterReadCallbackScheduledAndSocketCloseIfBackpressureIsApplied()
{ {
var mockConnectionHandler = new MockConnectionHandler(); var mockConnectionDispatcher = new MockConnectionDispatcher();
var mockLibuv = new MockLibuv(); var mockLibuv = new MockLibuv();
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
var transport = new LibuvTransport(mockLibuv, transportContext, null); var transport = new LibuvTransport(mockLibuv, transportContext, null);
var thread = new LibuvThread(transport); var thread = new LibuvThread(transport);
var mockScheduler = new Mock<PipeScheduler>(); var mockScheduler = new Mock<PipeScheduler>();
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
{ {
backPressure = () => a(o); backPressure = () => a(o);
}); });
mockConnectionHandler.InputOptions = pool => mockConnectionDispatcher.InputOptions = pool =>
new PipeOptions( new PipeOptions(
pool: pool, pool: pool,
pauseWriterThreshold: 3, pauseWriterThreshold: 3,
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
readerScheduler: PipeScheduler.Inline, readerScheduler: PipeScheduler.Inline,
useSynchronizationContext: false); useSynchronizationContext: false);
mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); mockConnectionDispatcher.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
Task connectionTask = null; Task connectionTask = null;
try try
@ -163,13 +163,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
Assert.Null(mockLibuv.ReadCallback); Assert.Null(mockLibuv.ReadCallback);
// Now release backpressure by reading the input // Now release backpressure by reading the input
var result = await mockConnectionHandler.Input.Reader.ReadAsync(); var result = await mockConnectionDispatcher.Input.Reader.ReadAsync();
// Calling advance will call into our custom scheduler that captures the back pressure // Calling advance will call into our custom scheduler that captures the back pressure
// callback // callback
mockConnectionHandler.Input.Reader.AdvanceTo(result.Buffer.End); mockConnectionDispatcher.Input.Reader.AdvanceTo(result.Buffer.End);
// Cancel the current pending flush // Cancel the current pending flush
mockConnectionHandler.Input.Writer.CancelPendingFlush(); mockConnectionDispatcher.Input.Writer.CancelPendingFlush();
// Now release the back pressure // Now release the back pressure
await thread.PostAsync(a => a(), backPressure); await thread.PostAsync(a => a(), backPressure);
@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
Assert.Null(mockLibuv.ReadCallback); Assert.Null(mockLibuv.ReadCallback);
// Now complete the output writer and wait for the connection to close // Now complete the output writer and wait for the connection to close
mockConnectionHandler.Output.Writer.Complete(); mockConnectionDispatcher.Output.Writer.Complete();
await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout);
@ -196,9 +196,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
[Fact] [Fact]
public async Task DoesNotThrowIfOnReadCallbackCalledWithEOFButAllocCallbackNotCalled() public async Task DoesNotThrowIfOnReadCallbackCalledWithEOFButAllocCallbackNotCalled()
{ {
var mockConnectionHandler = new MockConnectionHandler(); var mockConnectionDispatcher = new MockConnectionDispatcher();
var mockLibuv = new MockLibuv(); var mockLibuv = new MockLibuv();
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
var transport = new LibuvTransport(mockLibuv, transportContext, null); var transport = new LibuvTransport(mockLibuv, transportContext, null);
var thread = new LibuvThread(transport); var thread = new LibuvThread(transport);
@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
mockLibuv.ReadCallback(socket.InternalGetHandle(), TestConstants.EOF, ref ignored); mockLibuv.ReadCallback(socket.InternalGetHandle(), TestConstants.EOF, ref ignored);
}, (object)null); }, (object)null);
var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); var readAwaitable = await mockConnectionDispatcher.Input.Reader.ReadAsync();
Assert.True(readAwaitable.IsCompleted); Assert.True(readAwaitable.IsCompleted);
} }
finally finally

View File

@ -18,9 +18,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
[Fact] [Fact]
public async Task LibuvThreadDoesNotThrowIfPostingWorkAfterDispose() public async Task LibuvThreadDoesNotThrowIfPostingWorkAfterDispose()
{ {
var mockConnectionHandler = new MockConnectionHandler(); var mockConnectionDispatcher = new MockConnectionDispatcher();
var mockLibuv = new MockLibuv(); var mockLibuv = new MockLibuv();
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
var transport = new LibuvTransport(mockLibuv, transportContext, null); var transport = new LibuvTransport(mockLibuv, transportContext, null);
var thread = new LibuvThread(transport); var thread = new LibuvThread(transport);
var ranOne = false; var ranOne = false;

View File

@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var transportContext = new TestLibuvTransportContext() var transportContext = new TestLibuvTransportContext()
{ {
ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()) ConnectionDispatcher = new ConnectionDispatcher(serviceContext, listenOptions.Build())
}; };
var transport = new LibuvTransport(transportContext, listenOptions); var transport = new LibuvTransport(transportContext, listenOptions);
@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var transportContext = new TestLibuvTransportContext() var transportContext = new TestLibuvTransportContext()
{ {
ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()), ConnectionDispatcher = new ConnectionDispatcher(serviceContext, listenOptions.Build()),
Options = new LibuvTransportOptions { ThreadCount = threadCount } Options = new LibuvTransportOptions { ThreadCount = threadCount }
}; };

View File

@ -8,7 +8,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
@ -34,13 +34,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var transportContextPrimary = new TestLibuvTransportContext(); var transportContextPrimary = new TestLibuvTransportContext();
var builderPrimary = new ConnectionBuilder(); var builderPrimary = new ConnectionBuilder();
builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1);
transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); transportContextPrimary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextPrimary, builderPrimary.Build());
var serviceContextSecondary = new TestServiceContext(); var serviceContextSecondary = new TestServiceContext();
var builderSecondary = new ConnectionBuilder(); var builderSecondary = new ConnectionBuilder();
builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1);
var transportContextSecondary = new TestLibuvTransportContext(); var transportContextSecondary = new TestLibuvTransportContext();
transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); transportContextSecondary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextSecondary, builderSecondary.Build());
var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions);
@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var builderPrimary = new ConnectionBuilder(); var builderPrimary = new ConnectionBuilder();
builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1);
var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) };
transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); transportContextPrimary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextPrimary, builderPrimary.Build());
var serviceContextSecondary = new TestServiceContext var serviceContextSecondary = new TestServiceContext
{ {
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var builderSecondary = new ConnectionBuilder(); var builderSecondary = new ConnectionBuilder();
builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1);
var transportContextSecondary = new TestLibuvTransportContext(); var transportContextSecondary = new TestLibuvTransportContext();
transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); transportContextSecondary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextSecondary, builderSecondary.Build());
var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions);
@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var builderPrimary = new ConnectionBuilder(); var builderPrimary = new ConnectionBuilder();
builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1);
var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) };
transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); transportContextPrimary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextPrimary, builderPrimary.Build());
var serviceContextSecondary = new TestServiceContext var serviceContextSecondary = new TestServiceContext
{ {
@ -226,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var builderSecondary = new ConnectionBuilder(); var builderSecondary = new ConnectionBuilder();
builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1);
var transportContextSecondary = new TestLibuvTransportContext(); var transportContextSecondary = new TestLibuvTransportContext();
transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); transportContextSecondary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextSecondary, builderSecondary.Build());
var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions);

View File

@ -5,13 +5,13 @@ using System;
using System.Buffers; using System.Buffers;
using System.IO.Pipelines; using System.IO.Pipelines;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers
{ {
public class MockConnectionHandler : IConnectionHandler public class MockConnectionDispatcher : IConnectionDispatcher
{ {
public Func<MemoryPool<byte>, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public Func<MemoryPool<byte>, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
public Func<MemoryPool<byte>, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public Func<MemoryPool<byte>, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers
var logger = new TestApplicationErrorLogger(); var logger = new TestApplicationErrorLogger();
AppLifetime = new LifetimeNotImplemented(); AppLifetime = new LifetimeNotImplemented();
ConnectionHandler = new MockConnectionHandler(); ConnectionDispatcher = new MockConnectionDispatcher();
Log = new LibuvTrace(logger); Log = new LibuvTrace(logger);
Options = new LibuvTransportOptions { ThreadCount = 1 }; Options = new LibuvTransportOptions { ThreadCount = 1 };
} }