summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig46
1 files changed, 41 insertions, 5 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 1a127ad4..de58da94 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -2059,10 +2059,10 @@ pub const Peers = struct {
/// No frontend of its own (the host says): with no client either, the
/// session is unattended.
detached: bool = false,
- /// Its last client left by closing its window, and no Detach was typed
- /// in any (`kept`): a pair's session ends there (runtime/session.zig).
+ /// Its last client left with a close (its window closed, its terminal
+ /// hung up) and the session is a pair's not kept (daemon.sessionState): it
+ /// ends there (runtime/session.zig).
closed: bool = false,
- kept: bool = false,
/// The worst a join cost the session's step, and the last one's dump.
join_ns: u64 = 0,
each_join: std.ArrayListUnmanaged(u64) = .empty,
@@ -2362,7 +2362,7 @@ pub const Peers = struct {
core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view.index()));
ps.closeViewOf(core, peer, peer.again);
if (ps.count() == 0) core.unattended = ps.detached;
- if (ps.count() == 0 and peer.close and !ps.kept) ps.closed = true;
+ if (ps.count() == 0 and peer.close and daemon.sessionState() == .pair) ps.closed = true;
ps.seq += 1;
ps.unit(0, ps.seq);
ps.letGo(peer);
@@ -2467,7 +2467,7 @@ pub const Peers = struct {
/// (`left`), its last word; the client goes, and its reader says so.
pub fn detach(ps: *Peers, k: u8) bool {
for (ps.list) |slot| if (slot) |peer| if (peer.view.index() == k) {
- ps.kept = true;
+ daemon.keepSession();
var out: [wire.max_name + 8]u8 = undefined;
peer.last(wire.encodeServer(&out, .{ .left = ps.name[0..@min(ps.name.len, wire.max_name)] }) catch unreachable);
return true;
@@ -7364,6 +7364,42 @@ test "a client joined while a script's writes to a body are held to go in as one
try n.agree();
}
+test "a client runs an Edit a script's write started once, as its session does, when the held write is asked again" {
+ var n = try NinepJoin.init("b\na\n", TestHost.host());
+ defer n.deinit();
+ try n.join();
+ const ctl = n.node(.ctl);
+ const req: pardes.ctlfs.Req = .{ .tag = 7, .op = .write, .node = ctl, .data = "Edit , | sort\n" };
+ // The step alone: its loop's pass would run the command (here, with no
+ // host to run it, fail it).
+ const first = try n.serve(req, false);
+ try std.testing.expectEqual(pardes.ctlfs.Status.ok, first.status);
+ // The write held as the session's listener holds it (runtime/9p_io.zig).
+ n.a.core.fs.edit_hold = .{ .asker = @ptrCast(n.a.core), .slot = 0, .seq = 1, .tag = req.tag, .node = ctl, .handle = 0, .written = first.written };
+ // Its command answers: the Edit is done.
+ n.a.apply(.{ .pipe_resp = .{ .id = n.a.core.pipe.edit_run.?.id, .success = true, .outputs = &.{"a\nb\n"} } });
+ n.a.seq += 1;
+ try n.send(try n.a.unit(0, n.a.seq));
+ try n.agree();
+ // A retry of the held write's park, as the listener serves it: its
+ // answer from the hold, no step, the Edit not run again by anyone.
+ const again = pardes.filesystem.EditHold.retried(&n.a.core.fs, req) orelse try n.serve(req, true);
+ try std.testing.expectEqual(pardes.ctlfs.Status.ok, again.status);
+ try std.testing.expect(n.a.core.pipe.edit_run == null);
+ try n.agree();
+}
+
+test "an Edit's stop token is each process's own (selection_pipe.next_token): a client's differs from its session's, and they agree" {
+ var n = try NinepJoin.init("b\na\n", TestHost.host());
+ defer n.deinit();
+ try n.join();
+ _ = try n.serve(.{ .tag = 1, .op = .write, .node = n.node(.ctl), .data = "Edit , | sort\n" }, false);
+ const session = n.a.core.pipe.edit_run.?.request.token;
+ const client = n.late.?.core().pipe.edit_run.?.request.token;
+ try std.testing.expect(session != client);
+ try n.agree();
+}
+
/// A session with a shell, for a run's 9P state across a join: a host
/// whose pty takes the line and whose tty nobody else holds.
const RunJoin = struct {