Skip to content

Commit

Permalink
Pass connection's cancellation token to package handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wj8400684 committed Apr 24, 2024
1 parent ff8b254 commit 7fc930f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/SuperSocket.Kestrel/KestrelPipeConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.");
Expand Down Expand Up @@ -64,12 +72,4 @@ public override async ValueTask SendAsync<TPackage>(IPackageEncoder<TPackage> pa
await base.SendAsync(packageEncoder, package, cancellationToken);
UpdateLastActiveTime();
}

private void OnConnectionClosed()
{
if (!CloseReason.HasValue)
CloseReason = Connection.CloseReason.RemoteClosing;

Cancel();
}
}

0 comments on commit 7fc930f

Please sign in to comment.