Use a property instead of a method (#19690)
- Rename GetTrasnsport to TransportConnection
This commit is contained in:
parent
5af0c471dd
commit
ddedfc64c9
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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; }
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue