Use a property instead of a method (#19690)

- Rename GetTrasnsport to TransportConnection
This commit is contained in:
David Fowler 2020-03-08 12:44:30 -07:00 committed by GitHub
parent 5af0c471dd
commit ddedfc64c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 15 deletions

View File

@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
Walk(connection => Walk(connection =>
{ {
connection.GetTransport().Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown)); connection.TransportConnection.Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown));
abortTasks.Add(connection.ExecutionTask); abortTasks.Add(connection.ExecutionTask);
}); });

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
public ConnectionReference(KestrelConnection connection) public ConnectionReference(KestrelConnection connection)
{ {
_weakReference = new WeakReference<KestrelConnection>(connection); _weakReference = new WeakReference<KestrelConnection>(connection);
ConnectionId = connection.GetTransport().ConnectionId; ConnectionId = connection.TransportConnection.ConnectionId;
} }
public string ConnectionId { get; } public string ConnectionId { get; }

View File

@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
} }
} }
public abstract BaseConnectionContext GetTransport(); public abstract BaseConnectionContext TransportConnection { get; }
public void OnHeartbeat(Action<object> action, object state) public void OnHeartbeat(Action<object> action, object state)
{ {

View File

@ -10,8 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
internal class KestrelConnection<T> : KestrelConnection, IThreadPoolWorkItem where T : BaseConnectionContext internal class KestrelConnection<T> : KestrelConnection, IThreadPoolWorkItem where T : BaseConnectionContext
{ {
private readonly Func<T, Task> _connectionDelegate; private readonly Func<T, Task> _connectionDelegate;
private readonly T _transportConnection;
public T TransportConnection { get; set; }
public KestrelConnection(long id, public KestrelConnection(long id,
ServiceContext serviceContext, ServiceContext serviceContext,
@ -21,12 +20,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
: base(id, serviceContext, logger) : base(id, serviceContext, logger)
{ {
_connectionDelegate = connectionDelegate; _connectionDelegate = connectionDelegate;
TransportConnection = connectionContext; _transportConnection = connectionContext;
connectionContext.Features.Set<IConnectionHeartbeatFeature>(this); connectionContext.Features.Set<IConnectionHeartbeatFeature>(this);
connectionContext.Features.Set<IConnectionCompleteFeature>(this); connectionContext.Features.Set<IConnectionCompleteFeature>(this);
connectionContext.Features.Set<IConnectionLifetimeNotificationFeature>(this); connectionContext.Features.Set<IConnectionLifetimeNotificationFeature>(this);
} }
public override BaseConnectionContext TransportConnection => _transportConnection;
void IThreadPoolWorkItem.Execute() void IThreadPoolWorkItem.Execute()
{ {
_ = ExecuteAsync(); _ = ExecuteAsync();
@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
internal async Task ExecuteAsync() internal async Task ExecuteAsync()
{ {
var connectionContext = TransportConnection; var connectionContext = _transportConnection;
try try
{ {
@ -63,15 +64,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
// Dispose the transport connection, this needs to happen before removing it from the // Dispose the transport connection, this needs to happen before removing it from the
// connection manager so that we only signal completion of this connection after the transport // connection manager so that we only signal completion of this connection after the transport
// is properly torn down. // is properly torn down.
await TransportConnection.DisposeAsync(); await connectionContext.DisposeAsync();
_serviceContext.ConnectionManager.RemoveConnection(_id); _serviceContext.ConnectionManager.RemoveConnection(_id);
} }
} }
public override BaseConnectionContext GetTransport()
{
return TransportConnection;
}
} }
} }

View File

@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
connection.ConnectionClosed = new CancellationToken(canceled: true); connection.ConnectionClosed = new CancellationToken(canceled: true);
var kestrelConnection = new KestrelConnection<ConnectionContext>(0, serviceContext, _ => Task.CompletedTask, connection, serviceContext.Log); var kestrelConnection = new KestrelConnection<ConnectionContext>(0, serviceContext, _ => Task.CompletedTask, connection, serviceContext.Log);
serviceContext.ConnectionManager.AddConnection(0, kestrelConnection); serviceContext.ConnectionManager.AddConnection(0, kestrelConnection);
var completeFeature = kestrelConnection.GetTransport().Features.Get<IConnectionCompleteFeature>(); var completeFeature = kestrelConnection.TransportConnection.Features.Get<IConnectionCompleteFeature>();
Assert.NotNull(completeFeature); Assert.NotNull(completeFeature);
object stateObject = new object(); object stateObject = new object();
@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
connection.ConnectionClosed = new CancellationToken(canceled: true); connection.ConnectionClosed = new CancellationToken(canceled: true);
var kestrelConnection = new KestrelConnection<ConnectionContext>(0, serviceContext, _ => Task.CompletedTask, connection, serviceContext.Log); var kestrelConnection = new KestrelConnection<ConnectionContext>(0, serviceContext, _ => Task.CompletedTask, connection, serviceContext.Log);
serviceContext.ConnectionManager.AddConnection(0, kestrelConnection); serviceContext.ConnectionManager.AddConnection(0, kestrelConnection);
var completeFeature = kestrelConnection.GetTransport().Features.Get<IConnectionCompleteFeature>(); var completeFeature = kestrelConnection.TransportConnection.Features.Get<IConnectionCompleteFeature>();
Assert.NotNull(completeFeature); Assert.NotNull(completeFeature);
object stateObject = new object(); object stateObject = new object();