summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--abi/wire.zig4
-rw-r--r--core/Core.zig19
-rw-r--r--core/views.zig20
-rw-r--r--test/daemon.py2
4 files changed, 35 insertions, 10 deletions
diff --git a/abi/wire.zig b/abi/wire.zig
index 8713ba98..ff1d1bf2 100644
--- a/abi/wire.zig
+++ b/abi/wire.zig
@@ -10,6 +10,8 @@ const pardes = @import("core");
const config = @import("pardes_options");
const build_info = @import("build_info");
+/// 24: a view kept for its client's rejoin says when it went away
+/// (View.away_ns), and is that client's for Views.away_kept_ns;
/// 23: a pane of a kind's frame names its rasters by key, their pixels
/// crossing before it as strips of 4 MiB at most over the rows it shows
/// (screen kind 5), and a replica lacking one asks for its pane again
@@ -36,7 +38,7 @@ const build_info = @import("build_info");
/// part B); 14: the hello names a session and
/// carries the semantics hash, and a ping is answered (phase 5's
/// groundwork); 13: the frames went (phase 3).
-pub const version: u16 = 23;
+pub const version: u16 = 24;
/// The terminal's build and the window's step alike (`semantics`).
const family = switch (config.platform) {
diff --git a/core/Core.zig b/core/Core.zig
index 6de4f21e..de911469 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -127,6 +127,9 @@ pub const View = struct {
/// pane (util.c:467). Where the acme placement puts new panes
/// (layout.placeNew). A Look click moves the keyboard but not this.
active_column: u32 = 0,
+ /// When its client went away to join again for it (Views.away), on
+ /// the session's clock.
+ away_ns: u64 = 0,
/// The live view's frontend (Event.frontend): a window, what it draws and
/// the words it takes (builtins.zig `here`); it starts as
/// `Options.windowed` says.
@@ -1162,13 +1165,17 @@ pub inline fn view(p: anytype) if (@typeInfo(@TypeOf(p)).pointer.attrs.@"const")
pub const openView = pardes.tape.taped(openViewInner);
fn openViewInner(p: *Pardes) ?View.Id {
// Every view taken: one kept for a client that has not come back
- // for it (Views.away) goes first. ponytail: no timer lets one go;
- // until its place is wanted it costs a parked slot, and a terminal
- // it sized last keeps that size until another view types into it.
- if (@popCount(p.views_open) == Views.max and p.views_away != 0) {
- Views.close(p, @ctz(p.views_away));
+ // for it in Views.away_kept_ns (Views.away) goes first; one kept
+ // since is its client's, and the join is refused. ponytail: no timer
+ // lets one go; until its place is wanted it costs a parked slot, and
+ // a terminal it sized last keeps that size until another view types
+ // into it.
+ if (@popCount(p.views_open) == Views.max) for (0..Views.max) |k| {
+ if (!Views.isAway(p, @intCast(k)) or p.clock.now_ns -| p.views[k].?.away_ns < Views.away_kept_ns) continue;
+ Views.close(p, @intCast(k));
p.sync();
- }
+ break;
+ };
// What was queued since the last pump (a leaving client's view
// closed, a 9P request's step) done first, as every client of the
// tape does it here: a join dumps the session next, and a core
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()));
}
diff --git a/test/daemon.py b/test/daemon.py
index a8ae4331..de586895 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -240,7 +240,7 @@ class Replica:
"""A replica's connection (abi/wire.zig): length-prefixed
messages, a tag byte and a little-endian u32 length. It is a near
client: its first word after the hello says so."""
- WIRE = 23
+ WIRE = 24
def __init__(self, path, timeout=10):
self.path, self.timeout = path, timeout