diff --git a/SVSim.BattleNode/Sessions/BattleSession.cs b/SVSim.BattleNode/Sessions/BattleSession.cs index fbab589..8ab6b03 100644 --- a/SVSim.BattleNode/Sessions/BattleSession.cs +++ b/SVSim.BattleNode/Sessions/BattleSession.cs @@ -18,6 +18,19 @@ public sealed class BattleSession private readonly WebSocket _ws; private readonly ILogger _log; + /// + /// Cancellation token for the session lifetime, captured from 's + /// parameter. Read by all send helpers so host shutdown promptly terminates pending + /// writes (was CancellationToken.None on every send pre-this-slice). + /// + /// + /// Defaults to when hasn't + /// run — e.g. unit tests that drive directly without + /// going through the WS pump. None of those tests exercise send code, so the default + /// is safe. + /// + private CancellationToken _sessionCt; + public string BattleId { get; } public long ViewerId { get; } public BattleSessionPhase Phase { get; internal set; } = BattleSessionPhase.AwaitingInitNetwork; @@ -37,6 +50,7 @@ public sealed class BattleSession /// public async Task RunAsync(CancellationToken cancellation) { + _sessionCt = cancellation; await SendEioOpenAsync(cancellation); var buffer = new byte[8192];