diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 12:36:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 13:09:56 -0300 |
| commit | 9c50dd0b64ecaa8cbcfd4f76868dc83e5b9636e3 (patch) | |
| tree | 1fd44d101a680ed4ff601c8760d2f6bd4139edc0 /dev/Ptys.zig | |
| parent | 1374e668fe568ad4f7f70c06156c1ecdbb8840b9 (diff) | |
| parent | c8ac386d8f2404417b6d09af1635e1104bcc66ae (diff) | |
| download | pardes-9c50dd0b64ecaa8cbcfd4f76868dc83e5b9636e3.tar.gz pardes-9c50dd0b64ecaa8cbcfd4f76868dc83e5b9636e3.zip | |
integration: the addons' workers and the daemon's notes once, on the five faults a busy machine showed: pardes-services-3 (jobs, draws, pipes and a search through the session's one queue, their workers the queue's; the daemon's notes the loop's own: eight frontend calls; an Adopt's shells kept room in a full queue; a command's exit told after its reads are applied; the tty harness's end of a case) and pardes-merge36 (pardes-faults-5); two conflicts, both where the daemon's reader starts: the faults made daemon.watch() argument-free with daemon.notesTo, the services gave the loop its own note: daemon.notesTo(&l, note) and daemon.watch(); the terminal frontend's quit arm starts no reader (kept does), and Shell.session, whose one reader that line was, is deleted; tui core-test 861/1016 (155 skipped), shell-test 1058/1061, term-test 17/17, both soaks diverged 0, unequal 0, unlisted 0, the window builds; the coordinator's gate in the ledger (reorg/merge37)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/Ptys.zig')
| -rw-r--r-- | dev/Ptys.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/dev/Ptys.zig b/dev/Ptys.zig index 16a31939..583e3c38 100644 --- a/dev/Ptys.zig +++ b/dev/Ptys.zig @@ -180,6 +180,7 @@ pub fn close(p: *Ptys, id: pardes.Pane.Id) void { /// A reader's read, off the queue (freed here). pub fn output(p: *Ptys, core: *pardes.Pardes, o: @FieldType(Inbox.Msg, "output")) void { defer p.queue.gpa.free(o.bytes); + defer p.queue.applied(o.pane); if (p.gens[o.pane.index()] == o.gen) core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } }); } @@ -213,6 +214,11 @@ pub fn takeExits(p: *Ptys, core: *pardes.Pardes) void { host_io.takeExits(core, &p.slots, p, closeWatched); } +/// Whether pane `id` has reads not yet applied (host_io.takeExits). +pub fn unapplied(p: *const Ptys, id: usize) bool { + return p.queue.unapplied[id].load(.acquire) > 0; +} + fn closeWatched(p: *Ptys, id: usize) void { p.close(.at(id)); } @@ -401,3 +407,31 @@ test "a post of an older generation is passed over" { try std.testing.expect(std.mem.indexOf(u8, text, "old session") == null); try std.testing.expect(std.mem.indexOf(u8, text, "current session") != null); } + +test "a command's exit is told after its output a reader read, however long that waits in the queue" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .tty_only = true }); + defer core.deinit(); + var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; + defer queue.deinit(); + var p = testing(&queue); + defer p.deinit(); + // A command done (reaped), its pty held open by what it left running + // (the pipe's write end): no end of file, and no output in the kernel + // once the reader has read it. + var fds: [2]c_int = undefined; + if (libc.pipe(&fds) != 0) return error.PipeFailed; + defer _ = libc.close(fds[1]); + p.slots[0] = .{ .fd = fds[0], .pid = 0, .cmd = .{ .watched = true, .fd = fds[0], .exited = true, .status = 0 } }; + p.slots[0].?.reader = try queue.startReader(.{ .handle = fds[0], .flags = .{ .nonblocking = false } }, .at(0), p.gens[0]); + try std.testing.expect(host_io.writeFd(fds[1], "LAST")); + const until = std.Io.Clock.awake.now(std.testing.io).toMilliseconds() + 2_000; + while (queue.len == 0 and std.Io.Clock.awake.now(std.testing.io).toMilliseconds() < until) try std.testing.io.sleep(.fromMilliseconds(1), .awake); + try std.testing.expectEqual(@as(usize, 1), queue.len); + p.takeExits(core); + try std.testing.expect(!p.slots[0].?.cmd.told); + var batch = queue.take(); + for (batch.slice()) |msg| p.output(core, msg.output); + p.takeExits(core); + try std.testing.expect(p.slots[0].?.cmd.told); +} |
