summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md7
-rw-r--r--src/Plumb.zig121
-rw-r--r--src/config.zig1
-rw-r--r--src/fs-help.txt2
-rw-r--r--src/fs.zig5
-rw-r--r--src/ninep/ctl.zig2
-rw-r--r--src/ninep/events.zig4
-rw-r--r--src/ninep/tree.zig64
8 files changed, 183 insertions, 23 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 3e6c3d7f..823b0e13 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,13 @@
## Unreleased
+- A port the plumbing rules name is a file a program reads,
+ `plumb/<port>`, as Plan 9's plumber serves one: every open reads its
+ own copy of what is sent there from then on (`cat plumb/edit` sees each
+ file a look opens), a read held until a message comes. A message to a
+ port no one reads runs its rule set's `start`, or with `plumb client`
+ waits for the port's first reader.
+
- A look asks the plumber first, as acme's does: once the pane's own
readings are done and a name already open in a pane is focused, what
is looked at is sent (`type text`, `src pardes`, `wdir` the pane's
diff --git a/src/Plumb.zig b/src/Plumb.zig
index f54ac1e2..e2edef77 100644
--- a/src/Plumb.zig
+++ b/src/Plumb.zig
@@ -12,6 +12,8 @@ const fs = @import("fs.zig");
const look = @import("look.zig");
const layout = @import("layout.zig");
const Kind = @import("Kind.zig");
+const tape = @import("tape.zig");
+const events = @import("ninep/events.zig");
const Regex = @import("regexp.zig").Regex;
const Pardes = pardes.Pardes;
@@ -23,6 +25,10 @@ text: std.ArrayList(u8) = .empty,
/// are `include basic`'s, so a session starts with the defaults, and so
/// does a dump made before the plumber.
written: bool = false,
+/// Every port a rule has named this session, in the order they were
+/// named, never dropped (plumber(4)'s directory): plumb/<port>'s files,
+/// a port's index its node.
+ports: std.ArrayList([]u8) = .empty,
/// The default rules, which `include basic` names, as Plan 9's names
/// /lib/plumb/basic.
@@ -45,6 +51,8 @@ pub const e_empty = "empty argument list";
pub fn deinit(pl: *Plumb, gpa: std.mem.Allocator) void {
pl.text.deinit(gpa);
+ for (pl.ports.items) |name| gpa.free(name);
+ pl.ports.deinit(gpa);
}
// ---- the message ----
@@ -518,8 +526,10 @@ pub fn filePath(p: *Pardes, buf: *[4096]u8) ?[]const u8 {
/// At boot, the plumbing file's rules in force, if it is there (the
/// plumber reading $home/lib/plumbing); a refusal is said, as an init
-/// line that fails is, and the defaults stay.
+/// line that fails is, and the defaults stay. Either way the ports the
+/// rules in force name have their files.
pub fn boot(p: *Pardes) void {
+ if (rulesOf(p, p.scratch.allocator())) |rules| notePorts(p, rules.ports.items) catch {} else |_| {}
var buf: [4096]u8 = undefined;
const path = filePath(p, &buf) orelse return;
const text = fs.read(p, path) catch return;
@@ -537,6 +547,71 @@ pub fn saved(p: *Pardes, pane: usize, path: []const u8, text: []const u8) void {
if (apply(p, false, "plumbing", text)) |why| p.reportFailure(pane, why);
}
+/// `names` added to the session's ports, those it has not yet, in order;
+/// none when they would be more than max_ports.
+fn notePorts(p: *Pardes, names: []const []const u8) error{ TooMany, OutOfMemory }!void {
+ var new: usize = 0;
+ for (names) |n| new += @intFromBool(portIndex(p, n) == null);
+ if (p.plumber.ports.items.len + new > max_ports) return error.TooMany;
+ try p.plumber.ports.ensureUnusedCapacity(p.gpa, new);
+ for (names) |n| if (portIndex(p, n) == null) p.plumber.ports.appendAssumeCapacity(try p.gpa.dupe(u8, n));
+}
+
+/// The port named `name`'s index, its file's node.
+pub fn portIndex(p: *const Pardes, name: []const u8) ?u8 {
+ for (p.plumber.ports.items, 0..) |n, i| if (std.mem.eql(u8, n, name)) return @intCast(i);
+ return null;
+}
+
+pub fn portName(p: *const Pardes, index: u8) ?[]const u8 {
+ return if (index < p.plumber.ports.items.len) p.plumber.ports.items[index] else null;
+}
+
+/// Whether a program reads port `index` (an open of its file): the
+/// authority's 9P state, asked through the tape.
+fn portRead(p: *Pardes, index: u8) bool {
+ for (&p.fs.opens) |*o| if (o.node != 0 and o.what == .port and o.what.port.index == index) return true;
+ return false;
+}
+
+/// `m` packed onto `q` (a reader's, the held ones'), after `lead` (a
+/// held message's port); false when it is over what a queue holds.
+fn enqueue(p: *Pardes, q: *events.Queue, lead: []const u8, m: *const Msg) bool {
+ var out: std.Io.Writer.Allocating = .init(p.scratch.allocator());
+ out.writer.writeAll(lead) catch return false;
+ m.pack(&out.writer) catch return false;
+ if (out.written().len + 4 > q.cap) return false;
+ q.push(p.gpa, out.written());
+ return true;
+}
+
+/// A copy of `m` to every reader of port `index` (plumber(4)'s queuesend:
+/// every fid open when it was sent), each read held for one answered.
+fn fanOut(p: *Pardes, index: u8, m: *const Msg) void {
+ for (&p.fs.opens) |*o| if (o.node != 0 and o.what == .port and o.what.port.index == index) {
+ if (!enqueue(p, &o.what.port.queue, "", m)) {
+ var said: Kind.Buf(160) = .{};
+ events.notePath(p, "err -", said.print("plumb/{s}: a message of {d} bytes is over a reader's {d} KiB, not sent to it", .{ portName(p, index).?, m.data.len, events.queue_cap / 1024 }));
+ }
+ };
+ p.fs.news = true;
+}
+
+/// A port's file opened (tree.zig): what `client` rules held for it, the
+/// opener's (plumber(4)'s queueheld).
+pub fn opened(p: *Pardes, index: u8, q: *events.Queue) void {
+ const held = &p.fs.plumb_held;
+ var kept: events.Queue = .{};
+ while (held.peek()) |record| {
+ if (record[0] == index) {
+ q.push(p.gpa, record[1..]);
+ } else kept.push(p.gpa, record);
+ held.pop();
+ }
+ held.deinit(p.gpa);
+ held.* = kept;
+}
+
/// No rules at all: a `>` to plumb/rules, before what it writes.
pub fn clear(p: *Pardes) void {
p.plumber.text.clearRetainingCapacity();
@@ -560,6 +635,10 @@ pub fn apply(p: *Pardes, keep: bool, name: []const u8, more: []const u8) ?[]cons
var out: std.Io.Writer.Allocating = .init(arena);
ps.rules.print(&out.writer) catch break :said "out of memory";
if (out.written().len > max_text) break :said std.fmt.comptimePrint("rules too long; max {d} KiB", .{max_text / 1024});
+ notePorts(p, ps.rules.ports.items) catch |err| break :said switch (err) {
+ error.TooMany => std.fmt.comptimePrint("too many ports; max {d}", .{max_ports}),
+ error.OutOfMemory => "out of memory",
+ };
p.plumber.text.clearRetainingCapacity();
p.plumber.text.appendSlice(p.gpa, out.written()) catch break :said "out of memory";
p.plumber.written = true;
@@ -780,15 +859,28 @@ pub fn send(p: *Pardes, from: ?usize, msg: Msg, seen: ?Seen) Sent {
const id = from orelse p.view().active;
// dispose.
if (m.dst.len == 0) return startup(&s, id, set orelse return .{ .refused = e_no_port }, &e);
- if (std.meta.stringToEnum(Port, m.dst)) |port| return deliver(&s, id, port, &m);
+ const port = portIndex(p, m.dst);
+ // A port pardes reads itself: its readers' copies (a program reading
+ // plumb/edit sees every open, plumber(4)'s fan-out), the authority's
+ // alone to hand out, so asked of nobody; then pardes's own.
+ if (std.meta.stringToEnum(Port, m.dst)) |own| {
+ if (port) |i| fanOut(p, i, &m);
+ return deliver(&s, id, own, &m);
+ }
if (p.kinds.byName(m.dst)) |k| {
+ if (port) |i| fanOut(p, i, &m);
openInKind(&s, id, k, &m);
return .done;
}
- // A port nobody reads: what the rule set starts, if it is one a rule
- // names; one no rule names is no port, and the message goes nowhere,
- // as fsys.c's dispose finds no Dirtab for it.
- if (!s.rules.named(m.dst)) return .done;
+ // One no rule ever named is none, and the message goes nowhere, as
+ // fsys.c's dispose finds no Dirtab for it. Another goes to its readers,
+ // whom only the authority knows (its 9P opens); with none, what the
+ // rule set starts.
+ const i = port orelse return .done;
+ if (tape.authority(portRead, .{ p, i })) {
+ fanOut(p, i, &m);
+ return .done;
+ }
return startup(&s, id, set orelse return .{ .refused = e_no_start }, &e);
}
@@ -814,10 +906,17 @@ fn startup(s: *Send, id: usize, set: Set, e: *const Exec) Sent {
rest = rest[took..];
}
if (argv.items.len == 0) return .{ .refused = e_empty };
- return if (run(s.p, id, e.m.wdir, argv.items)) |why| .{ .refused = why } else .done;
+ if (run(s.p, id, e.m.wdir, argv.items)) |why| return .{ .refused = why };
+ // `client`: the message waits for the port's first reader, the program
+ // it started perhaps (plumber(4)'s hold); held messages past what the
+ // queue keeps push out the oldest.
+ if (act.verb == .client) if (portIndex(s.p, e.m.dst)) |i| {
+ if (!enqueue(s.p, &s.p.fs.plumb_held, &.{i}, e.m)) return .{ .refused = "plumb: message too big to hold for a client" };
+ };
+ return .done;
}
-/// What a `plumb start` (and, until ports are read, a `plumb client`) runs:
+/// What a `plumb start` or a `plumb client` runs:
/// the one place that decides it (question 4 of docs/next-plumber.md).
/// A builtin or a kind's word runs in place, from the message's pane, as
/// a line of it would; one that cannot do what the message asks declines
@@ -1175,15 +1274,15 @@ test "plumb: dispose: no rule and no dst, a start, the web port, a port no rule
// A URL to the web port: the host's opener.
while (p.nextEffect()) |_| {}
try testing.expect(send(p, null, .{ .type = "text", .data = "https://ziglang.org" }, null) == .done);
- var opened = false;
+ var linked = false;
while (p.nextEffect()) |e| switch (e) {
.open_link => |u| {
try testing.expectEqualStrings("https://ziglang.org", u.slice());
- opened = true;
+ linked = true;
},
else => {},
};
- try testing.expect(opened);
+ try testing.expect(linked);
}
test "plumb: rules written replace or add, a refusal keeps them as they were, and a dump keeps them" {
diff --git a/src/config.zig b/src/config.zig
index 8a1528a8..0568fa26 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -1828,6 +1828,7 @@ test "reference.typ's #fstree is the tree the session serves, file for file" {
const under = if (f.inPty() and f != .pty) "pane/<n>/pty/" else "pane/<n>/";
try served.put(gpa, try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ under, f.fileName(), if (f.isDir()) "/" else "" }), {});
};
+ try served.put(gpa, "plumb/<port>", {});
try served.put(gpa, "col/<n>/", {});
for (std.enums.values(tree.ColFile)) |f| if (f != .dir)
try served.put(gpa, try std.fmt.allocPrint(gpa, "col/<n>/{s}", .{f.fileName()}), {});
diff --git a/src/fs-help.txt b/src/fs-help.txt
index 4e43a476..9a87843d 100644
--- a/src/fs-help.txt
+++ b/src/fs-help.txt
@@ -19,7 +19,7 @@ recent files opened lately, closed ones too: open|closed <path>
dumps the dumps the state file keeps, the newest first: <label> <date> <size> <panes>
layout a line per column: serial index x width current|notcurrent empty|full pane-serials; then active <serial>
tag the workspace tag, tagexec a word as a click in it; col/<serial>/ a column's tag, ctl, exec; rmdir: empty only
-plumb/ rules: the plumber's rules, plumb(6)'s (a write adds rule sets, > replaces); send: write a message, six lines then data
+plumb/ rules: the plumber's rules, plumb(6)'s (a write adds rule sets, > replaces); send: write a message, six lines then data; <port>: read the messages sent to it
pane/new open it to make a pane (<session dir>/+New) in the active column; the read answers its serial
pane/<n>/ name body tag ctl addr dot limit data xdata sel dirty mark scroll errors event look exec tagexec rows; rmdir closes
rows: a line a row, kind (m c p; d decl, u unmarked) line col end_line end_col source_column location_end code_start styles path; styles - or N:start+len=role,... (keyword string number comment, add del emph line, joined by .); a write at 0 replaces
diff --git a/src/fs.zig b/src/fs.zig
index d90bb8c0..893f70fb 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -948,6 +948,10 @@ pub const Namespace = struct {
/// The editor-wide event ring: panes made, renamed, saved and closed, and
/// what the editor said. Recorded whether or not anyone reads /log.
log: tree.events.Queue = .{ .cap = limits.log_bytes },
+ /// Messages a plumbing rule's `client` holds for a port no one reads
+ /// yet (Plumb.zig), each its port's index then the message packed: the
+ /// port's first reader takes them (plumber(4)'s queueheld).
+ plumb_held: tree.events.Queue = .{},
/// What the last look or exec created or touched, answered by reading
/// either of those files.
results: [MAX_PANES]u32 = undefined,
@@ -969,6 +973,7 @@ pub const Namespace = struct {
for (st.closed_lines.items) |*line| line.bytes.deinit(gpa);
st.closed_lines.deinit(gpa);
st.log.deinit(gpa);
+ st.plumb_held.deinit(gpa);
st.out.deinit(gpa);
}
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 7bd586dc..7cdd3327 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -366,7 +366,7 @@ pub fn readResults(p: *Pardes, req: Req) Reply {
const looking = if (tree.Node.target(req.node)) |t| switch (t) {
.top => |f| f == .look,
.pane => |pt| pt.file == .look,
- .col => false,
+ .col, .port => false,
} else false;
for (kept) |serial| if (!looking or p.paneBySerial(serial) != null)
out.print(p.gpa, "{d}\n", .{serial}) catch return Reply.fail(req.tag, E.NOMEM);
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index dd9b488c..5b5378b1 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -233,6 +233,10 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
if ((f == .exec or f == .look) and p.fs.ran_at != 0)
serial = name.print("{d}", .{p.fs.ran_at});
},
+ .port => |i| {
+ serial = "-";
+ file = name.print("plumb/{s}", .{pardes.Plumb.portName(p, i) orelse "?"});
+ },
.col => |c| {
serial = "-";
file = if (c.file == .dir)
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index bd3f3b3b..e5e521c3 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -101,6 +101,7 @@ fn truncates(req: Req) bool {
.pane => true,
.col => |c| c.file == .tag,
.top => |f| f == .tag or f == .rules,
+ .port => false,
};
}
@@ -156,6 +157,9 @@ pub const Open = struct {
/// is not whole yet (rule sets with no blank line after them, a
/// message short of its data).
plumb,
+ /// An open reading a plumb port (Plumb.zig's ports, plumber(4)'s):
+ /// the messages sent to it since the open, packed, a read each.
+ port: struct { index: u8, queue: events.Queue = .{} },
} = .{ .snapshot = null },
/// What a write to a file of command lines left unfinished: a last line
/// with no newline yet, or an Edit block still open. A write through a
@@ -212,6 +216,7 @@ pub const Open = struct {
gpa.free(run.line);
},
.frozen => |bytes| gpa.free(bytes),
+ .port => |*port| port.queue.deinit(gpa),
.event, .pty_data, .ctl, .lines, .writes, .pager, .plumb => {},
}
o.pending.deinit(gpa);
@@ -380,6 +385,10 @@ pub const ColFile = enum(u5) {
}
};
const col_bit: u59 = 1 << 58;
+/// plumb/<port>: a port by its place in Plumb's list, which only grows;
+/// past a pane serial's 32 bits and clear of the host tree's and the
+/// archive's high bits (fs.os_node, sources.archive_node).
+const port_bit: u59 = 1 << 40;
pub const Node = packed struct(u64) {
file: u5 = 0,
@@ -394,11 +403,16 @@ pub const Node = packed struct(u64) {
return @bitCast(Node{ .file = @backingInt(file), .serial = col_bit | @as(u59, serial) });
}
+ pub fn ofPort(index: u8) u64 {
+ return @bitCast(Node{ .serial = port_bit | @as(u59, index) });
+ }
+
pub fn target(node: u64) ?Target {
const n: Node = @bitCast(node);
if (n.serial == 0) {
return .{ .top = std.enums.fromInt(TopFile, n.file) orelse return null };
}
+ if (n.serial & port_bit != 0) return .{ .port = std.math.cast(u8, n.serial & ~port_bit) orelse return null };
if (n.serial & col_bit != 0) return .{ .col = .{
.serial = std.math.cast(u32, n.serial & ~col_bit) orelse return null,
.file = std.enums.fromInt(ColFile, n.file) orelse return null,
@@ -414,6 +428,7 @@ pub const Target = union(enum) {
top: TopFile,
pane: struct { serial: u32, file: PaneFile },
col: struct { serial: u32, file: ColFile },
+ port: u8,
};
/// Opening /pane/new makes a pane and reading the open fid answers its
@@ -574,7 +589,7 @@ fn serve(p: *Pardes, req: Req) Reply {
const target = Node.target(req.node) orelse return Reply.fail(req.tag, E.NOENT);
if (req.op == .write or req.op == .setattr) p.fs.origin = switch (target) {
.pane => |t| @as(u8, if (t.file == .body or t.file == .tag) 'E' else 'F'),
- .top, .col => 'F',
+ .top, .col, .port => 'F',
};
return switch (req.op) {
.lookup => lookup(p, req, target),
@@ -596,7 +611,7 @@ fn serve(p: *Pardes, req: Req) Reply {
fn runAttr(p: *Pardes, req: Req, target: Target) ?Reply.Attr {
const t = switch (target) {
.pane => |t| t,
- .top, .col => return null,
+ .top, .col, .port => return null,
};
if (t.file != .pty_run) return null;
const run = if (req.handle != 0) openOf(p, req) else for (&p.fs.opens) |*o| {
@@ -608,6 +623,12 @@ fn runAttr(p: *Pardes, req: Req, target: Target) ?Reply.Attr {
fn attrOf(p: *Pardes, target: Target) ?Reply.Attr {
switch (target) {
+ .port => |i| return .{
+ .name = Plumb.portName(p, i) orelse return null,
+ .node = Node.ofPort(i),
+ .mode = 0o444,
+ .mtime = p.fs.started,
+ },
.top => |f| return .{
.name = f.fileName(),
.node = @backingInt(f),
@@ -704,6 +725,7 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
else => return Reply.fail(req.tag, E.NOTDIR),
},
.col => |c| if (c.file == .dir) @backingInt(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
+ .port => return Reply.fail(req.tag, E.NOTDIR),
};
return handle(p, .{ .tag = req.tag, .op = .getattr, .node = parent });
}
@@ -728,9 +750,10 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
if (serial == 0) return Reply.fail(req.tag, E.NOENT);
break :dir if (f == .pane) Node.of(serial, .dir) else Node.ofCol(serial, .dir);
},
- .plumb => if (std.mem.eql(u8, name, "rules")) @backingInt(TopFile.rules) else if (std.mem.eql(u8, name, "send")) @backingInt(TopFile.send) else return Reply.fail(req.tag, E.NOENT),
+ .plumb => if (std.mem.eql(u8, name, "rules")) @backingInt(TopFile.rules) else if (std.mem.eql(u8, name, "send")) @backingInt(TopFile.send) else if (Plumb.portIndex(p, name)) |i| Node.ofPort(i) else return Reply.fail(req.tag, E.NOENT),
else => return Reply.fail(req.tag, E.NOTDIR),
},
+ .port => return Reply.fail(req.tag, E.NOTDIR),
.col => |c| col: {
if (c.file != .dir) return Reply.fail(req.tag, E.NOTDIR);
const f = std.meta.stringToEnum(ColFile, name) orelse return Reply.fail(req.tag, E.NOENT);
@@ -790,8 +813,15 @@ fn stageDir(p: *Pardes, out: *std.ArrayList(u8), target: Target, off: u64) error
try stageDirent(out, p.gpa, Node.of(serial, .dir), true, name);
}
},
- .plumb => inline for (.{ TopFile.rules, TopFile.send }) |t| {
- if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, @backingInt(t), false, t.fileName());
+ // plumber(4)'s order: rules, send, then the ports as rules
+ // named them.
+ .plumb => {
+ inline for (.{ TopFile.rules, TopFile.send }) |t| {
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, @backingInt(t), false, t.fileName());
+ }
+ for (p.plumber.ports.items, 0..) |name, i| {
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.ofPort(@intCast(i)), false, name);
+ }
},
.col => for (0..p.view().ncol) |c| {
if (skip > 0) {
@@ -812,6 +842,7 @@ fn stageDir(p: *Pardes, out: *std.ArrayList(u8), target: Target, off: u64) error
if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.ofCol(c.serial, f), false, f.fileName());
}
},
+ .port => return error.NotDir,
.pane => |t| {
const id = p.paneBySerial(t.serial) orelse return error.FileNotFound;
const terminal = p.panes[id].?.isTerminal();
@@ -872,6 +903,9 @@ fn open(p: *Pardes, req: Req, target: Target) Reply {
.col => |c| if (layout.columnBySerial(p, c.serial) == null)
return Reply.fail(req.tag, E.NOENT)
else if (linesOpen(target, req)) .lines else if (c.file == .ctl) .{ .frozen = &.{} } else return .{ .tag = req.tag },
+ // A reader of the port: what is sent to it from now on, and what a
+ // `client` rule held for its first.
+ .port => |i| if (req.omode & 3 != 0) return Reply.fail(req.tag, E.PERM) else .{ .port = .{ .index = i } },
.pane => |t| what: {
const pn = p.panes[p.paneBySerial(t.serial) orelse return Reply.fail(req.tag, E.NOENT)].?;
if (t.file.inPty() and !pn.isTerminal()) return Reply.fail(req.tag, E.NOENT);
@@ -929,6 +963,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply {
pn.fs.event_reader = pn.fs.event_reader or reader;
},
.pty_data => pane_of.?.fs.pty_reader = true,
+ .port => |*port| Plumb.opened(p, port.index, &port.queue),
.run, .ctl, .lines, .writes, .pager, .plumb => {},
}
return .{ .tag = req.tag, .handle = @intCast(i + 1) };
@@ -940,7 +975,7 @@ fn remove(p: *Pardes, req: Req) Reply {
const target = Node.target(req.node) orelse return Reply.fail(req.tag, E.NOENT);
const t = switch (target) {
.pane => |t| t,
- .top => return Reply.fail(req.tag, E.PERM),
+ .top, .port => return Reply.fail(req.tag, E.PERM),
.col => |c| return cols.remove(p, req, c.serial, c.file),
};
if (t.file != .dir) return Reply.fail(req.tag, E.PERM);
@@ -1027,7 +1062,7 @@ fn releaseHandle(p: *Pardes, req: Req) void {
.ctl => if (pn.fs.lock == req.handle) {
pn.fs.lock = null;
},
- .snapshot, .log, .lines, .writes, .frozen, .pager, .plumb => {},
+ .snapshot, .log, .lines, .writes, .frozen, .pager, .plumb, .port => {},
};
o.deinit(p.gpa);
}
@@ -1046,6 +1081,7 @@ fn setattr(p: *Pardes, req: Req, target: Target) Reply {
},
.col => |c| if (c.file == .tag and cols.truncate(p, c.serial) != .ok) return Reply.fail(req.tag, E.NOENT),
.top => |f| if (f == .tag and cols.truncate(p, null) != .ok) return Reply.fail(req.tag, E.NOMEM) else if (f == .rules) Plumb.clear(p),
+ .port => return Reply.fail(req.tag, E.PERM),
};
return .{ .tag = req.tag, .attr = attrOf(p, target) orelse return Reply.fail(req.tag, E.NOENT) };
}
@@ -1056,6 +1092,8 @@ fn read(p: *Pardes, req: Req, target: Target) Reply {
if (open_record) |o| if (o.what == .pager) ctl.fillPager(p, o.what.pager, &o.pending) catch return Reply.fail(req.tag, E.NOMEM);
// A listing reads what it was at the open.
if (open_record) |o| if (o.what == .frozen) return window(p, req, o.what.frozen);
+ // A port: a message a read, held until one is sent.
+ if (open_record) |o| if (o.what == .port) return events.readQueue(p, req, &o.what.port.queue);
const stream = if (open_record) |o| switch (o.what) {
.log => o,
.event => |reader| if (reader) o else null,
@@ -1182,6 +1220,8 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply {
.exec => ctl.readResults(p, req),
else => Reply.fail(req.tag, E.PERM),
},
+ // Read through its open (read), never without one.
+ .port => return Reply.fail(req.tag, E.PERM),
}
}
@@ -1193,6 +1233,7 @@ fn linesFile(target: Target) bool {
// `name` too: one name, however its writes cut it, applied once
// its newline comes, or with its write when that is whole.
.pane => |t| t.file == .look or t.file == .exec or t.file == .ctl or t.file == .tagexec or t.file == .name or t.file == .rows,
+ .port => false,
};
}
@@ -1202,6 +1243,7 @@ fn resultsFile(target: Target) bool {
.top => |f| f == .look or f == .exec or f == .tagexec or f == .pager,
.col => |c| c.file == .exec,
.pane => |t| t.file == .look or t.file == .exec or t.file == .tagexec,
+ .port => false,
};
}
@@ -1248,6 +1290,7 @@ fn ctlFile(target: Target) bool {
.top => |f| f == .ctl,
.col => |c| c.file == .ctl,
.pane => |t| t.file == .ctl,
+ .port => false,
};
}
@@ -1398,6 +1441,7 @@ fn writeNow(p: *Pardes, req: Req, target: Target) Reply {
.exec => cols.writeExec(p, req, c.serial),
.dir => Reply.fail(req.tag, E.PERM),
},
+ .port => return Reply.fail(req.tag, E.PERM),
}
}
@@ -1671,9 +1715,9 @@ test "readdir lists the root and a pane directory without creating anything" {
@memcpy(plumb_bytes[0..plumb_reply.bytes.len], plumb_reply.bytes);
var plumb_buf: [4]th.Dirent = undefined;
const plumb = th.dirents(plumb_bytes[0..plumb_reply.bytes.len], &plumb_buf);
- try testing.expectEqual(@as(usize, 2), plumb.len);
- try testing.expectEqualStrings("rules", plumb[0].name);
- try testing.expectEqualStrings("send", plumb[1].name);
+ // Then the ports the default rules name, in their order.
+ try testing.expectEqual(@as(usize, 4), plumb.len);
+ for ([_][]const u8{ "rules", "send", "web", "edit" }, plumb) |want, got| try testing.expectEqualStrings(want, got.name);
var idbuf: [16]u8 = undefined;
try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null);
try testing.expect(th.nameAt(top, "self") == null);