summaryrefslogtreecommitdiff
path: root/core/views.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 16:12:18 -0300
committerGabriel Schneider <[email protected]>2026-11-20 16:48:13 -0300
commit48b9b370fb60d5543afd7ba5b96bbddf06028ae2 (patch)
tree6708e0d9a319b4acda0786dafe18798463c32b68 /core/views.zig
parent387297c3bd42c7016e36009ecf8c807259398ac7 (diff)
downloadpardes-48b9b370fb60d5543afd7ba5b96bbddf06028ae2.tar.gz
pardes-48b9b370fb60d5543afd7ba5b96bbddf06028ae2.zip
views: a view kept for its client's rejoin is that client's for away_kept_ns (30 s): the screen-state soak's 'the far client never showed the screen after the flood (it left)' (seed 0 at 207 ms, reproduced in f207-2: the far client 10.5 s behind joined again for its lag, then refused 40 times with 42 keys left, and given up) was openViewInner (Core.zig:1168) giving a join with no room the first away view (Views.close(@ctz(views_away))) while that view's client, which had said in its bye that it joins again, was still waiting for its dump to cross a slow link: a dialling client took its place and every later join of the far client was refused; FIRST the test (views.zig, the rejoin test turned round: with every view taken and two kept away, a join is refused until away_kept_ns has passed, then takes the first kept; on the base 'expected null, found 1'); then the fix: View.away_ns, the session's clock when its client went away (Views.away), and openViewInner lets a kept view go only once it is that old; the bound: the soak's far link (1 Mbit/s, 200 ms each way) has taken up to 18.3 s between two of its joins (g-1, 207 ms) and 15.6 s before; past 30 s the client is taken as gone; the wire's version 23 -> 24 (a view's state in the dump and the digest), test/daemon.py's WIRE with it; a user: a far client resyncing for its lag while a fifth client dialled lost its view and was refused (every view taken)
Diffstat (limited to 'core/views.zig')
-rw-r--r--core/views.zig20
1 files changed, 18 insertions, 2 deletions
diff --git a/core/views.zig b/core/views.zig
index 3c2248d7..2ddbb523 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -29,6 +29,13 @@ const MAX_PANES = pardes.MAX_PANES;
/// Views at once: a window or terminal each.
pub const max = 4;
+/// How long a view kept for its client's rejoin (`away`) is that client's
+/// alone: a join with no room is refused meanwhile, and takes it after
+/// (Pardes.openView). A client that said it joins again dials at once, and
+/// its join waits for its dump to cross: the soak's far link (1 Mbit/s,
+/// 200 ms each way) has taken up to 18.3 s from one of its joins to the
+/// next (a flood, joins for its lag). Past 30 s, it is taken as gone.
+pub const away_kept_ns: u64 = 30 * std.time.ns_per_s;
/// A pane's fields that are each view's own: where it is in the view's
/// layout, which of its texts has the keyboard, how far it is scrolled, and
@@ -470,6 +477,7 @@ pub fn away(p: *Pardes, k: u8) void {
if (!isOpen(p, k)) return;
if (k == p.live) if (looked(p, k) orelse open(p)) |other| to(p, other);
p.views_away |= bit(k);
+ p.views[k].?.away_ns = p.clock.now_ns;
}
/// The session's end: what each view holds.
@@ -765,7 +773,7 @@ test "the last client's view going leaves the session its layout, which a rejoin
try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
}
-test "a client's view kept for its rejoin: through an Upgrade's dump, each client back in its own; a join with no room lets one go" {
+test "a client's view kept for its rejoin: through an Upgrade's dump, each client back in its own; a join with no room lets one go only once it has been kept away_kept_ns" {
const gpa = testing.allocator;
const opts: pardes.Options = .{ .tty_only = true, .cols = 100, .rows = 30 };
const p = try Pardes.init(gpa, opts);
@@ -798,9 +806,17 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien
try testing.expect(layout.findPane(q, made[1 - i]) == null);
}
try testing.expect(!q.rejoinView(ks[0]));
- // A client that never comes back: its view goes when a join has no room.
+ // A client that said it joins again is coming back (a far one's join
+ // for its lag waits seconds for its dump): a join with no room is
+ // refused, its view not let go, until `away_kept_ns` has passed.
p.toView(.at(0));
try testing.expectEqual(@as(?View.Id, .at(3)), p.openView());
+ try testing.expectEqual(@as(?View.Id, null), p.openView());
+ p.advance(p.clock.now_ns + away_kept_ns - 1);
+ try testing.expectEqual(@as(?View.Id, null), p.openView());
+ try testing.expect(isAway(p, ks[0].index()) and isAway(p, ks[1].index()));
+ // One that never comes back: its view goes once the bound has passed.
+ p.advance(p.clock.now_ns + 1);
try testing.expectEqual(ks[0], p.openView());
try testing.expect(!isAway(p, ks[0].index()) and isAway(p, ks[1].index()));
}