Merged release/2.1
This commit is contained in:
commit
0753f4b4f4
|
|
@ -100,7 +100,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestr
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{A95C3BE1-B850-4265-97A0-777ADCCD437F}"
|
||||
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
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
_connectionsPerEndPoint = connectionsPerEndPoint;
|
||||
}
|
||||
|
||||
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler)
|
||||
public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher handler)
|
||||
{
|
||||
var connections = new InMemoryConnection[_connectionsPerEndPoint];
|
||||
for (var i = 0; i < _connectionsPerEndPoint; i++)
|
||||
|
|
@ -124,12 +124,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
|
||||
public class InMemoryTransport : ITransport
|
||||
{
|
||||
private readonly IConnectionHandler _handler;
|
||||
private readonly IConnectionDispatcher _dispatcher;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
{
|
||||
foreach (var connection in _connections)
|
||||
{
|
||||
_handler.OnConnection(connection);
|
||||
_dispatcher.OnConnection(connection);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public class ConnectionBuilder : IConnectionBuilder
|
||||
{
|
||||
|
|
@ -3,11 +3,20 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
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)
|
||||
{
|
||||
return connectionBuilder.Use(next =>
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
using System.IO.Pipelines;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public abstract class ConnectionContext
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public delegate Task ConnectionDelegate(ConnectionContext connection);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Microsoft.AspNetCore.Protocols.Abstractions</AssemblyName>
|
||||
<RootNamespace>Microsoft.AspNetCore.Protocols.Abstractions</RootNamespace>
|
||||
<AssemblyName>Microsoft.AspNetCore.Connections.Abstractions</AssemblyName>
|
||||
<RootNamespace>Microsoft.AspNetCore.Connections.Abstractions</RootNamespace>
|
||||
<Description>Core components of ASP.NET Core networking protocol stack.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
|
@ -13,11 +13,8 @@
|
|||
|
||||
<ItemGroup>
|
||||
<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.Memory" Version="$(SystemMemoryPackageVersion)" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.ActivatorUtilities.Sources" Version="$(MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO.Pipelines;
|
||||
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
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public class AddressInUseException : InvalidOperationException
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public class ConnectionAbortedException : OperationCanceledException
|
||||
{
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public class ConnectionResetException : IOException
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@ using System.Buffers;
|
|||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IApplicationTransportFeature
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IConnectionHeartbeatFeature
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IConnectionIdFeature
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IConnectionItemsFeature
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@ using System.Buffers;
|
|||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IConnectionTransportFeature
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Security.Claims;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IConnectionUserFeature
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@ using System.Buffers;
|
|||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface IMemoryPoolFeature
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface ITransferFormatFeature
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@ using System.Buffers;
|
|||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public interface ITransportSchedulerFeature
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
public interface IConnectionBuilder
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols
|
||||
namespace Microsoft.AspNetCore.Connections
|
||||
{
|
||||
[Flags]
|
||||
public enum TransferFormat
|
||||
|
|
@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,20 +7,20 @@ using System.IO.Pipelines;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
||||
{
|
||||
public class ConnectionHandler : IConnectionHandler
|
||||
public class ConnectionDispatcher : IConnectionDispatcher
|
||||
{
|
||||
private readonly ServiceContext _serviceContext;
|
||||
private readonly ConnectionDelegate _connectionDelegate;
|
||||
|
||||
public ConnectionHandler(ServiceContext serviceContext, ConnectionDelegate connectionDelegate)
|
||||
public ConnectionDispatcher(ServiceContext serviceContext, ConnectionDelegate connectionDelegate)
|
||||
{
|
||||
_serviceContext = serviceContext;
|
||||
_connectionDelegate = connectionDelegate;
|
||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
}
|
||||
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);
|
||||
|
|
@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols.Abstractions;
|
||||
using Microsoft.AspNetCore.Connections.Abstractions;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.IO;
|
|||
using System.IO.Pipelines;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Protocols.Abstractions;
|
||||
using Microsoft.AspNetCore.Connections.Abstractions;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Runtime.ExceptionServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Abstractions
|
||||
namespace Microsoft.AspNetCore.Connections.Abstractions
|
||||
{
|
||||
internal class UrlDecoder
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
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.Http2.HPack;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" />
|
||||
<PackageReference Include="System.Security.Cryptography.Cng" Version="$(SystemSecurityCryptographyCngPackageVersion)" />
|
||||
<PackageReference Include="System.Numerics.Vectors" Version="$(SystemNumericsVectorsPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -148,8 +148,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
|
|||
connectionDelegate = new ConnectionLimitMiddleware(connectionDelegate, Options.Limits.MaxConcurrentConnections.Value, Trace).OnConnectionAsync;
|
||||
}
|
||||
|
||||
var connectionHandler = new ConnectionHandler(ServiceContext, connectionDelegate);
|
||||
var transport = _transportFactory.Create(endpoint, connectionHandler);
|
||||
var connectionDispatcher = new ConnectionDispatcher(ServiceContext, connectionDelegate);
|
||||
var transport = _transportFactory.Create(endpoint, connectionDispatcher);
|
||||
_transports.Add(transport);
|
||||
|
||||
await transport.BindAsync().ConfigureAwait(false);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
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.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http.Features;
|
|||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
|
||||
{
|
||||
public interface IConnectionHandler
|
||||
public interface IConnectionDispatcher
|
||||
{
|
||||
void OnConnection(TransportConnection connection);
|
||||
}
|
||||
|
|
@ -5,6 +5,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
|
|||
{
|
||||
public interface ITransportFactory
|
||||
{
|
||||
ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler);
|
||||
ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.IO.Pipelines;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Protocols.Abstractions\Protocols.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\Connections.Abstractions\Connections.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" />
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.IO;
|
|||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
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.Libuv.Internal.Networking;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -48,14 +48,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
public LibuvOutputConsumer OutputConsumer { get; set; }
|
||||
|
||||
private ILibuvTrace Log => ListenerContext.TransportContext.Log;
|
||||
private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler;
|
||||
private IConnectionDispatcher ConnectionDispatcher => ListenerContext.TransportContext.ConnectionDispatcher;
|
||||
private LibuvThread Thread => ListenerContext.Thread;
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionHandler.OnConnection(this);
|
||||
ConnectionDispatcher.OnConnection(this);
|
||||
|
||||
OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
|
||||
public ILibuvTrace Log { get; set; }
|
||||
|
||||
public IConnectionHandler ConnectionHandler { get; set; }
|
||||
public IConnectionDispatcher ConnectionDispatcher { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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.Libuv.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
Options = _baseTransportContext.Options,
|
||||
AppLifetime = _baseTransportContext.AppLifetime,
|
||||
Log = _baseTransportContext.Log,
|
||||
ConnectionHandler = handler
|
||||
ConnectionDispatcher = dispatcher
|
||||
};
|
||||
|
||||
return new LibuvTransport(transportContext, endPointInformation);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using System.Net;
|
|||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -60,12 +60,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
|
|||
public override PipeScheduler InputWriterScheduler => _scheduler;
|
||||
public override PipeScheduler OutputReaderScheduler => _scheduler;
|
||||
|
||||
public async Task StartAsync(IConnectionHandler connectionHandler)
|
||||
public async Task StartAsync(IConnectionDispatcher connectionDispatcher)
|
||||
{
|
||||
Exception sendError = null;
|
||||
try
|
||||
{
|
||||
connectionHandler.OnConnection(this);
|
||||
connectionDispatcher.OnConnection(this);
|
||||
|
||||
// Spawn send and receive logic
|
||||
Task receiveTask = DoReceive();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using System.Runtime.ExceptionServices;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
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.Sockets.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
|
|||
|
||||
private readonly MemoryPool<byte> _memoryPool = KestrelMemoryPool.Create();
|
||||
private readonly IEndPointInformation _endPointInformation;
|
||||
private readonly IConnectionHandler _handler;
|
||||
private readonly IConnectionDispatcher _dispatcher;
|
||||
private readonly IApplicationLifetime _appLifetime;
|
||||
private readonly int _numSchedulers;
|
||||
private readonly PipeScheduler[] _schedulers;
|
||||
|
|
@ -36,19 +36,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
|
|||
|
||||
internal SocketTransport(
|
||||
IEndPointInformation endPointInformation,
|
||||
IConnectionHandler handler,
|
||||
IConnectionDispatcher dispatcher,
|
||||
IApplicationLifetime applicationLifetime,
|
||||
int ioQueueCount,
|
||||
ISocketsTrace trace)
|
||||
{
|
||||
Debug.Assert(endPointInformation != null);
|
||||
Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint);
|
||||
Debug.Assert(handler != null);
|
||||
Debug.Assert(dispatcher != null);
|
||||
Debug.Assert(applicationLifetime != null);
|
||||
Debug.Assert(trace != null);
|
||||
|
||||
_endPointInformation = endPointInformation;
|
||||
_handler = handler;
|
||||
_dispatcher = dispatcher;
|
||||
_appLifetime = applicationLifetime;
|
||||
_trace = trace;
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
|
|||
acceptSocket.NoDelay = _endPointInformation.NoDelay;
|
||||
|
||||
var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace);
|
||||
_ = connection.StartAsync(_handler);
|
||||
_ = connection.StartAsync(_dispatcher);
|
||||
}
|
||||
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
|
|||
_trace = new SocketsTrace(logger);
|
||||
}
|
||||
|
||||
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler)
|
||||
public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
|
||||
{
|
||||
if (endPointInformation == null)
|
||||
{
|
||||
|
|
@ -52,12 +52,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
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.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
|
|
@ -14,18 +14,18 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||
{
|
||||
public class ConnectionHandlerTests
|
||||
public class ConnectionDispatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void OnConnectionCreatesLogScopeWithConnectionId()
|
||||
{
|
||||
var serviceContext = new TestServiceContext();
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
var handler = new ConnectionHandler(serviceContext, _ => tcs.Task);
|
||||
var dispatcher = new ConnectionDispatcher(serviceContext, _ => tcs.Task);
|
||||
|
||||
var connection = new TestConnection();
|
||||
|
||||
handler.OnConnection(connection);
|
||||
dispatcher.OnConnection(connection);
|
||||
|
||||
// The scope should be created
|
||||
var scopeObjects = ((TestKestrelTrace)serviceContext.Log)
|
||||
|
|
@ -12,7 +12,7 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
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.Internal.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
Assert.Contains(server.Options.ListenOptions[0].ConnectionAdapters, adapter => adapter.IsHttps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded()
|
||||
{
|
||||
|
|
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
Assert.Equal(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButNoHttpUrls()
|
||||
{
|
||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
StartDummyApplication(server);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButManualListenOptions()
|
||||
{
|
||||
|
|
@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
|
||||
var mockTransportFactory = new Mock<ITransportFactory>();
|
||||
mockTransportFactory
|
||||
.Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionHandler>()))
|
||||
.Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionDispatcher>()))
|
||||
.Returns(mockTransport.Object);
|
||||
|
||||
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
||||
|
|
@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
|
||||
var mockTransportFactory = new Mock<ITransportFactory>();
|
||||
mockTransportFactory
|
||||
.Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionHandler>()))
|
||||
.Setup(transportFactory => transportFactory.Create(It.IsAny<IEndPointInformation>(), It.IsAny<IConnectionDispatcher>()))
|
||||
.Returns(mockTransport.Object);
|
||||
|
||||
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
||||
|
|
@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
|
||||
private class MockTransportFactory : ITransportFactory
|
||||
{
|
||||
public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler)
|
||||
public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher handler)
|
||||
{
|
||||
return Mock.Of<ITransport>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
serviceContext.Scheduler = PipeScheduler.ThreadPool;
|
||||
|
||||
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(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold);
|
||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
serviceContext.Scheduler = PipeScheduler.ThreadPool;
|
||||
|
||||
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(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ using Microsoft.AspNetCore.Builder;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
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.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
[Fact]
|
||||
public async Task DoesNotEndConnectionOnZeroRead()
|
||||
{
|
||||
var mockConnectionHandler = new MockConnectionHandler();
|
||||
var mockConnectionDispatcher = new MockConnectionDispatcher();
|
||||
var mockLibuv = new MockLibuv();
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler };
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
|
||||
var transport = new LibuvTransport(mockLibuv, transportContext, null);
|
||||
var thread = new LibuvThread(transport);
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored);
|
||||
}, (object)null);
|
||||
|
||||
var readAwaitable = mockConnectionHandler.Input.Reader.ReadAsync();
|
||||
var readAwaitable = mockConnectionDispatcher.Input.Reader.ReadAsync();
|
||||
Assert.False(readAwaitable.IsCompleted);
|
||||
}
|
||||
finally
|
||||
|
|
@ -54,12 +54,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
[Fact]
|
||||
public async Task ConnectionDoesNotResumeAfterSocketCloseIfBackpressureIsApplied()
|
||||
{
|
||||
var mockConnectionHandler = new MockConnectionHandler();
|
||||
var mockConnectionDispatcher = new MockConnectionDispatcher();
|
||||
var mockLibuv = new MockLibuv();
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler };
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
|
||||
var transport = new LibuvTransport(mockLibuv, transportContext, null);
|
||||
var thread = new LibuvThread(transport);
|
||||
mockConnectionHandler.InputOptions = pool =>
|
||||
mockConnectionDispatcher.InputOptions = pool =>
|
||||
new PipeOptions(
|
||||
pool: pool,
|
||||
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
|
||||
|
||||
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;
|
||||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Assert.Null(mockLibuv.ReadCallback);
|
||||
|
||||
// Now complete the output writer so that the connection closes
|
||||
mockConnectionHandler.Output.Writer.Complete();
|
||||
mockConnectionDispatcher.Output.Writer.Complete();
|
||||
|
||||
await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout);
|
||||
|
||||
|
|
@ -115,9 +115,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
[Fact]
|
||||
public async Task ConnectionDoesNotResumeAfterReadCallbackScheduledAndSocketCloseIfBackpressureIsApplied()
|
||||
{
|
||||
var mockConnectionHandler = new MockConnectionHandler();
|
||||
var mockConnectionDispatcher = new MockConnectionDispatcher();
|
||||
var mockLibuv = new MockLibuv();
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler };
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
|
||||
var transport = new LibuvTransport(mockLibuv, transportContext, null);
|
||||
var thread = new LibuvThread(transport);
|
||||
var mockScheduler = new Mock<PipeScheduler>();
|
||||
|
|
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
{
|
||||
backPressure = () => a(o);
|
||||
});
|
||||
mockConnectionHandler.InputOptions = pool =>
|
||||
mockConnectionDispatcher.InputOptions = pool =>
|
||||
new PipeOptions(
|
||||
pool: pool,
|
||||
pauseWriterThreshold: 3,
|
||||
|
|
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
readerScheduler: PipeScheduler.Inline,
|
||||
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;
|
||||
try
|
||||
|
|
@ -163,13 +163,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Assert.Null(mockLibuv.ReadCallback);
|
||||
|
||||
// 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
|
||||
// callback
|
||||
mockConnectionHandler.Input.Reader.AdvanceTo(result.Buffer.End);
|
||||
mockConnectionDispatcher.Input.Reader.AdvanceTo(result.Buffer.End);
|
||||
|
||||
// Cancel the current pending flush
|
||||
mockConnectionHandler.Input.Writer.CancelPendingFlush();
|
||||
mockConnectionDispatcher.Input.Writer.CancelPendingFlush();
|
||||
|
||||
// Now release the back pressure
|
||||
await thread.PostAsync(a => a(), backPressure);
|
||||
|
|
@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Assert.Null(mockLibuv.ReadCallback);
|
||||
|
||||
// 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);
|
||||
|
||||
|
|
@ -196,9 +196,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
[Fact]
|
||||
public async Task DoesNotThrowIfOnReadCallbackCalledWithEOFButAllocCallbackNotCalled()
|
||||
{
|
||||
var mockConnectionHandler = new MockConnectionHandler();
|
||||
var mockConnectionDispatcher = new MockConnectionDispatcher();
|
||||
var mockLibuv = new MockLibuv();
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler };
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
|
||||
var transport = new LibuvTransport(mockLibuv, transportContext, null);
|
||||
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);
|
||||
}, (object)null);
|
||||
|
||||
var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync();
|
||||
var readAwaitable = await mockConnectionDispatcher.Input.Reader.ReadAsync();
|
||||
Assert.True(readAwaitable.IsCompleted);
|
||||
}
|
||||
finally
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
[Fact]
|
||||
public async Task LibuvThreadDoesNotThrowIfPostingWorkAfterDispose()
|
||||
{
|
||||
var mockConnectionHandler = new MockConnectionHandler();
|
||||
var mockConnectionDispatcher = new MockConnectionDispatcher();
|
||||
var mockLibuv = new MockLibuv();
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler };
|
||||
var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher };
|
||||
var transport = new LibuvTransport(mockLibuv, transportContext, null);
|
||||
var thread = new LibuvThread(transport);
|
||||
var ranOne = false;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
|
||||
var transportContext = new TestLibuvTransportContext()
|
||||
{
|
||||
ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build())
|
||||
ConnectionDispatcher = new ConnectionDispatcher(serviceContext, listenOptions.Build())
|
||||
};
|
||||
|
||||
var transport = new LibuvTransport(transportContext, listenOptions);
|
||||
|
|
@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
|
||||
var transportContext = new TestLibuvTransportContext()
|
||||
{
|
||||
ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()),
|
||||
ConnectionDispatcher = new ConnectionDispatcher(serviceContext, listenOptions.Build()),
|
||||
Options = new LibuvTransportOptions { ThreadCount = threadCount }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.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 builderPrimary = new ConnectionBuilder();
|
||||
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 builderSecondary = new ConnectionBuilder();
|
||||
builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1);
|
||||
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);
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
var builderPrimary = new ConnectionBuilder();
|
||||
builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1);
|
||||
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
|
||||
{
|
||||
|
|
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
var builderSecondary = new ConnectionBuilder();
|
||||
builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1);
|
||||
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);
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
var builderPrimary = new ConnectionBuilder();
|
||||
builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1);
|
||||
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
|
||||
{
|
||||
|
|
@ -226,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
var builderSecondary = new ConnectionBuilder();
|
||||
builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ using System;
|
|||
using System.Buffers;
|
||||
using System.IO.Pipelines;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
|
||||
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> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
|
||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers
|
|||
var logger = new TestApplicationErrorLogger();
|
||||
|
||||
AppLifetime = new LifetimeNotImplemented();
|
||||
ConnectionHandler = new MockConnectionHandler();
|
||||
ConnectionDispatcher = new MockConnectionDispatcher();
|
||||
Log = new LibuvTrace(logger);
|
||||
Options = new LibuvTransportOptions { ThreadCount = 1 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue