diff options
Diffstat (limited to 'core/views.zig')
| -rw-r--r-- | core/views.zig | 20 |
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())); } |
