summaryrefslogtreecommitdiff
path: root/src/9p_io.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-27 20:20:27 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commit7dc3891ed574d6e96548f592b09b0f8abc87ae2a (patch)
tree70cddb9ce4a7e9039f8167e806b7e996f94eefb0 /src/9p_io.zig
parentacd9e032a147f4aa7ad49110dc2f4fb945e7a9bb (diff)
downloadpardes-7dc3891ed574d6e96548f592b09b0f8abc87ae2a.tar.gz
pardes-7dc3891ed574d6e96548f592b09b0f8abc87ae2a.zip
Keep what each open holds in one table of open records
Snapshots (and /log's cursor), runs, and the reader_handle constants for event and pty/data each reused the open handle and each validated handle and node on its own. Now p.fs.opens is one table of 64 records, each the node it was opened on and a tagged union of what it holds, like lib9p's per-fid aux and acme's Fid (editors/acme/dat.h:373-385): one lookup (openOf), one release, ENFILE when full. A held read lives in its open's record, so it goes with the release. Opens that hold nothing answer handle 0 and take no record. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/9p_io.zig')
-rw-r--r--src/9p_io.zig22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig
index 6182ca75..7c366aa8 100644
--- a/src/9p_io.zig
+++ b/src/9p_io.zig
@@ -229,7 +229,9 @@ pub const Listener = struct {
if (req.op == .release and quiet) l.collectOs();
// A read with nothing yet stays parked in the engine, and the core
// keeps it to answer when what it waits on has something.
- if (reply.status == .again and req.op == .read) pardes.ctlfs.hold(core, req, conn);
+ if (reply.status == .again and req.op == .read) if (pardes.ctlfs.openOf(core, req)) |o| {
+ o.held = .{ .asker = conn, .req = req };
+ };
if (!pardes.ctlfs.changesPane(req)) return conn.reply(&reply, core.fsPayload(reply));
// The editor draws the change and performs what it asked for; when
// it asked for something -- a save, a shell, a watch -- the answer
@@ -262,8 +264,8 @@ pub const Listener = struct {
const core = l.core;
if (!core.fs.news) return;
core.fs.news = false;
- for (&core.fs.held) |*slot| {
- const held = slot.* orelse continue;
+ for (&core.fs.opens) |*o| {
+ const held = o.held orelse continue;
const conn: *Runner.Conn = @ptrCast(@alignCast(held.asker));
conn.lock();
const parked: ?bool = for (conn.engine.slots) |sl| {
@@ -272,13 +274,13 @@ pub const Listener = struct {
// Gone (flushed, answered, hung up) it is forgotten; out being
// asked again, the asking answers it.
if (parked != true) {
- if (parked == null) slot.* = null;
+ if (parked == null) o.held = null;
conn.unlock();
continue;
}
const reply = core.serveFs(held.req);
if (reply.status != .again) {
- slot.* = null;
+ o.held = null;
conn.engine.reply(&reply, core.fsPayload(reply));
}
conn.unlock();
@@ -1280,7 +1282,7 @@ test "Unix TCP and QUIC share one listener through reads writes reconnects and r
l.reset(p);
try testing.expectEqual(@as(usize, 0), l.runner.count());
for (&l.conns, 0..) |conn, i| try testing.expect(!l.live(@intCast(i)) and !conn.draining);
- for (p.fs.snapshots) |snapshot| try testing.expect(snapshot.node == 0);
+ for (p.fs.opens) |o| try testing.expect(o.node == 0);
}
};
}
@@ -1409,8 +1411,8 @@ test "a held read is answered when the log has news, and a flushed one spends no
const deadline = Client.nowMs() + Client.budget_ms;
while (Client.nowMs() < deadline) {
pardes.turn.wake();
- const any = for (core.fs.held) |slot| {
- if (slot != null) break true;
+ const any = for (core.fs.opens) |o| {
+ if (o.held != null) break true;
} else false;
pardes.turn.rest();
if (any) return;
@@ -1450,8 +1452,8 @@ test "a held read is answered when the log has news, and a flushed one spends no
try testing.expect(std.mem.indexOf(u8, answered.result.read, "while held") != null);
s.drop(1);
pardes.turn.wake();
- const left = for (p.fs.held) |slot| {
- if (slot != null) break true;
+ const left = for (p.fs.opens) |o| {
+ if (o.held != null) break true;
} else false;
pardes.turn.rest();
try testing.expect(!left);