From 7fc930f1b853cd636daf6bf28ada73442f922d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E4=BF=8A?= <8400684@qq.com> Date: Wed, 24 Apr 2024 11:44:18 +0800 Subject: [PATCH] Pass connection's cancellation token to package handling --- .../KestrelPipeConnection.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SuperSocket.Kestrel/KestrelPipeConnection.cs b/src/SuperSocket.Kestrel/KestrelPipeConnection.cs index aff20e106..b67372c5d 100644 --- a/src/SuperSocket.Kestrel/KestrelPipeConnection.cs +++ b/src/SuperSocket.Kestrel/KestrelPipeConnection.cs @@ -16,11 +16,19 @@ public KestrelPipeConnection(ConnectionContext context, ConnectionOptions option : base(context.Transport.Input, context.Transport.Output, options) { _context = context; - context.ConnectionClosed.Register(() => OnConnectionClosed()); + context.ConnectionClosed.Register(() => Cancel()); LocalEndPoint = context.LocalEndPoint; RemoteEndPoint = context.RemoteEndPoint; } + protected override void OnClosed() + { + if (!CloseReason.HasValue) + CloseReason = Connection.CloseReason.RemoteClosing; + + base.OnClosed(); + } + public override ValueTask DetachAsync() { throw new NotSupportedException($"Detach is not supported by {nameof(KestrelPipeConnection)}."); @@ -64,12 +72,4 @@ public override async ValueTask SendAsync(IPackageEncoder pa await base.SendAsync(packageEncoder, package, cancellationToken); UpdateLastActiveTime(); } - - private void OnConnectionClosed() - { - if (!CloseReason.HasValue) - CloseReason = Connection.CloseReason.RemoteClosing; - - Cancel(); - } }