Clean up some of protocol abstractions (#2311)
* Clean up some of protocol abstractions - Renamed PipeConnection to DuplexPipe - Removed MemoryPool from ConnectionContext - Work around value tuple issue on net471
This commit is contained in:
parent
7098c8d07d
commit
2156030460
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
var memoryPool = new MemoryPool();
|
var memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
|
|
||||||
var serviceContext = new ServiceContext
|
var serviceContext = new ServiceContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
private static readonly Func<object, Task> _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask;
|
private static readonly Func<object, Task> _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask;
|
||||||
|
|
||||||
private readonly TestHttp1Connection _http1Connection;
|
private readonly TestHttp1Connection _http1Connection;
|
||||||
private (IDuplexPipe Transport, IDuplexPipe Application) _pair;
|
private DuplexPipe.DuplexPipePair _pair;
|
||||||
|
|
||||||
private readonly byte[] _writeData;
|
private readonly byte[] _writeData;
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
{
|
{
|
||||||
using (var memoryPool = new MemoryPool())
|
using (var memoryPool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
_pair = pair;
|
_pair = pair;
|
||||||
|
|
||||||
var serviceContext = new ServiceContext
|
var serviceContext = new ServiceContext
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
public HttpProtocolFeatureCollection()
|
public HttpProtocolFeatureCollection()
|
||||||
{
|
{
|
||||||
var memoryPool = new MemoryPool();
|
var memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
|
|
||||||
var serviceContext = new ServiceContext
|
var serviceContext = new ServiceContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
var memoryPool = new MemoryPool();
|
var memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
|
|
||||||
var serviceContext = new ServiceContext
|
var serviceContext = new ServiceContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
var memoryPool = new MemoryPool();
|
var memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
|
|
||||||
var serviceContext = new ServiceContext
|
var serviceContext = new ServiceContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
var memoryPool = new MemoryPool();
|
var memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
|
|
||||||
var serviceContext = new ServiceContext
|
var serviceContext = new ServiceContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
||||||
|
|
||||||
// REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings
|
// REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings
|
||||||
// for the scheduler and limits are specified here
|
// for the scheduler and limits are specified here
|
||||||
var inputOptions = GetInputPipeOptions(_serviceContext, connectionContext.MemoryPool, transportFeature.InputWriterScheduler);
|
var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.InputWriterScheduler);
|
||||||
var outputOptions = GetOutputPipeOptions(_serviceContext, connectionContext.MemoryPool, transportFeature.OutputReaderScheduler);
|
var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.OutputReaderScheduler);
|
||||||
|
|
||||||
var pair = PipeFactory.CreateConnectionPair(inputOptions, outputOptions);
|
var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions);
|
||||||
|
|
||||||
// Set the transport and connection id
|
// Set the transport and connection id
|
||||||
connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId();
|
connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId();
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
||||||
Protocols = _protocols,
|
Protocols = _protocols,
|
||||||
ServiceContext = _serviceContext,
|
ServiceContext = _serviceContext,
|
||||||
ConnectionFeatures = connectionContext.Features,
|
ConnectionFeatures = connectionContext.Features,
|
||||||
MemoryPool = connectionContext.MemoryPool,
|
MemoryPool = transportFeature.MemoryPool,
|
||||||
ConnectionAdapters = _connectionAdapters,
|
ConnectionAdapters = _connectionAdapters,
|
||||||
Transport = connectionContext.Transport,
|
Transport = connectionContext.Transport,
|
||||||
Application = transportFeature.Application
|
Application = transportFeature.Application
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
using System.IO.Pipelines;
|
||||||
using System.Buffers;
|
|
||||||
using System.IO.Pipelines;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Protocols
|
namespace Microsoft.AspNetCore.Protocols
|
||||||
|
|
@ -14,7 +10,5 @@ namespace Microsoft.AspNetCore.Protocols
|
||||||
public abstract IFeatureCollection Features { get; }
|
public abstract IFeatureCollection Features { get; }
|
||||||
|
|
||||||
public abstract IDuplexPipe Transport { get; set; }
|
public abstract IDuplexPipe Transport { get; set; }
|
||||||
|
|
||||||
public abstract MemoryPool MemoryPool { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,6 @@ namespace Microsoft.AspNetCore.Protocols
|
||||||
|
|
||||||
public override IFeatureCollection Features => _features.Collection;
|
public override IFeatureCollection Features => _features.Collection;
|
||||||
|
|
||||||
public override MemoryPool MemoryPool => ConnectionTransportFeature.MemoryPool;
|
|
||||||
|
|
||||||
public override IDuplexPipe Transport
|
public override IDuplexPipe Transport
|
||||||
{
|
{
|
||||||
get => ConnectionTransportFeature.Transport;
|
get => ConnectionTransportFeature.Transport;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace System.IO.Pipelines
|
||||||
|
{
|
||||||
|
public class DuplexPipe : IDuplexPipe
|
||||||
|
{
|
||||||
|
public DuplexPipe(PipeReader reader, PipeWriter writer)
|
||||||
|
{
|
||||||
|
Input = reader;
|
||||||
|
Output = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PipeReader Input { get; }
|
||||||
|
|
||||||
|
public PipeWriter Output { get; }
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DuplexPipePair CreateConnectionPair(MemoryPool memoryPool)
|
||||||
|
{
|
||||||
|
return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions)
|
||||||
|
{
|
||||||
|
var input = new Pipe(inputOptions);
|
||||||
|
var output = new Pipe(outputOptions);
|
||||||
|
|
||||||
|
var transportToApplication = new DuplexPipe(output.Reader, input.Writer);
|
||||||
|
var applicationToTransport = new DuplexPipe(input.Reader, output.Writer);
|
||||||
|
|
||||||
|
return new DuplexPipePair(applicationToTransport, transportToApplication);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This class exists to work around issues with value tuple on .NET Framework
|
||||||
|
public readonly struct DuplexPipePair
|
||||||
|
{
|
||||||
|
public IDuplexPipe Transport { get; }
|
||||||
|
public IDuplexPipe Application { get; }
|
||||||
|
|
||||||
|
public DuplexPipePair(IDuplexPipe transport, IDuplexPipe application)
|
||||||
|
{
|
||||||
|
Transport = transport;
|
||||||
|
Application = application;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace System.IO.Pipelines
|
|
||||||
{
|
|
||||||
public class PipeConnection : IDuplexPipe
|
|
||||||
{
|
|
||||||
public PipeConnection(PipeReader reader, PipeWriter writer)
|
|
||||||
{
|
|
||||||
Input = reader;
|
|
||||||
Output = writer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PipeReader Input { get; }
|
|
||||||
|
|
||||||
public PipeWriter Output { get; }
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
using System.Buffers;
|
|
||||||
|
|
||||||
namespace System.IO.Pipelines
|
|
||||||
{
|
|
||||||
public static class PipeFactory
|
|
||||||
{
|
|
||||||
public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(MemoryPool memoryPool)
|
|
||||||
{
|
|
||||||
return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions)
|
|
||||||
{
|
|
||||||
var input = new Pipe(inputOptions);
|
|
||||||
var output = new Pipe(outputOptions);
|
|
||||||
|
|
||||||
var transportToApplication = new PipeConnection(output.Reader, input.Writer);
|
|
||||||
var applicationToTransport = new PipeConnection(input.Reader, output.Writer);
|
|
||||||
|
|
||||||
return (applicationToTransport, transportToApplication);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
public Http1ConnectionTests()
|
public Http1ConnectionTests()
|
||||||
{
|
{
|
||||||
_pipelineFactory = new MemoryPool();
|
_pipelineFactory = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(_pipelineFactory);
|
var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory);
|
||||||
|
|
||||||
_transport = pair.Transport;
|
_transport = pair.Transport;
|
||||||
_application = pair.Application;
|
_application = pair.Application;
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize));
|
private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize));
|
||||||
|
|
||||||
private readonly MemoryPool _memoryPool = new MemoryPool();
|
private readonly MemoryPool _memoryPool = new MemoryPool();
|
||||||
private readonly (IDuplexPipe Transport, IDuplexPipe Application) _pair;
|
private readonly DuplexPipe.DuplexPipePair _pair;
|
||||||
private readonly TestApplicationErrorLogger _logger;
|
private readonly TestApplicationErrorLogger _logger;
|
||||||
private readonly Http2ConnectionContext _connectionContext;
|
private readonly Http2ConnectionContext _connectionContext;
|
||||||
private readonly Http2Connection _connection;
|
private readonly Http2Connection _connection;
|
||||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
|
|
||||||
public Http2ConnectionTests()
|
public Http2ConnectionTests()
|
||||||
{
|
{
|
||||||
_pair = PipeFactory.CreateConnectionPair(_memoryPool);
|
_pair = DuplexPipe.CreateConnectionPair(_memoryPool);
|
||||||
|
|
||||||
_noopApplication = context => Task.CompletedTask;
|
_noopApplication = context => Task.CompletedTask;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
public HttpConnectionTests()
|
public HttpConnectionTests()
|
||||||
{
|
{
|
||||||
_memoryPool = new MemoryPool();
|
_memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(_memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(_memoryPool);
|
||||||
|
|
||||||
_httpConnectionContext = new HttpConnectionContext
|
_httpConnectionContext = new HttpConnectionContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
{
|
{
|
||||||
using (var memoryPool = new MemoryPool())
|
using (var memoryPool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var pair = PipeFactory.CreateConnectionPair(memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(memoryPool);
|
||||||
var http1ConnectionContext = new Http1ConnectionContext
|
var http1ConnectionContext = new Http1ConnectionContext
|
||||||
{
|
{
|
||||||
ServiceContext = new TestServiceContext(),
|
ServiceContext = new TestServiceContext(),
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
public TestInput()
|
public TestInput()
|
||||||
{
|
{
|
||||||
_memoryPool = new MemoryPool();
|
_memoryPool = new MemoryPool();
|
||||||
var pair = PipeFactory.CreateConnectionPair(_memoryPool);
|
var pair = DuplexPipe.CreateConnectionPair(_memoryPool);
|
||||||
Transport = pair.Transport;
|
Transport = pair.Transport;
|
||||||
Application = pair.Application;
|
Application = pair.Application;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -695,7 +695,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
||||||
|
|
||||||
private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null)
|
private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null)
|
||||||
{
|
{
|
||||||
var pair = PipeFactory.CreateConnectionPair(pipeOptions, pipeOptions);
|
var pair = DuplexPipe.CreateConnectionPair(pipeOptions, pipeOptions);
|
||||||
|
|
||||||
var logger = new TestApplicationErrorLogger();
|
var logger = new TestApplicationErrorLogger();
|
||||||
var serviceContext = new TestServiceContext
|
var serviceContext = new TestServiceContext
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers
|
||||||
{
|
{
|
||||||
var connectionContext = new DefaultConnectionContext(features);
|
var connectionContext = new DefaultConnectionContext(features);
|
||||||
|
|
||||||
Input = new Pipe(InputOptions(connectionContext.MemoryPool));
|
|
||||||
Output = new Pipe(OutputOptions(connectionContext.MemoryPool));
|
|
||||||
|
|
||||||
var feature = connectionContext.Features.Get<IConnectionTransportFeature>();
|
var feature = connectionContext.Features.Get<IConnectionTransportFeature>();
|
||||||
|
|
||||||
connectionContext.Transport = new PipeConnection(Input.Reader, Output.Writer);
|
Input = new Pipe(InputOptions(feature.MemoryPool));
|
||||||
feature.Application = new PipeConnection(Output.Reader, Input.Writer);
|
Output = new Pipe(OutputOptions(feature.MemoryPool));
|
||||||
|
|
||||||
|
connectionContext.Transport = new DuplexPipe(Input.Reader, Output.Writer);
|
||||||
|
feature.Application = new DuplexPipe(Output.Reader, Input.Writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pipe Input { get; private set; }
|
public Pipe Input { get; private set; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue