summaryrefslogtreecommitdiff
path: root/abi/wire.zig
diff options
context:
space:
mode:
Diffstat (limited to 'abi/wire.zig')
-rw-r--r--abi/wire.zig32
1 files changed, 26 insertions, 6 deletions
diff --git a/abi/wire.zig b/abi/wire.zig
index e68e8462..658cff23 100644
--- a/abi/wire.zig
+++ b/abi/wire.zig
@@ -10,9 +10,11 @@ const pardes = @import("core");
const config = @import("pardes_options");
const build_info = @import("build_info");
-/// 24: the 9P state a session's requests made (its open records, each
+/// 25: the 9P state a session's requests made (its open records, each
/// pane's, the panes the last look or exec touched, a header's
/// truncation) is in its join's dump and its digest (core/fs.zig Namespace);
+/// 24: a bye's byte says the client's window was closed (2), which ends a
+/// pair's session at its last client;
/// 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
@@ -39,7 +41,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 = 24;
+pub const version: u16 = 25;
/// The terminal's build and the window's step alike (`semantics`).
const family = switch (config.platform) {
@@ -195,6 +197,10 @@ pub const ServerTag = enum(u8) {
/// unit naming it: the hash, the whole's length and this piece's place
/// (u64le each), then at most 1 MiB of it (core/replica.zig).
blob = 0x0a,
+ /// The session's last word on a link: it ended, with its exit code.
+ ended = 0x0b,
+ /// ...or this client left it running (a Detach typed in it): its name.
+ left = 0x0c,
};
pub const ServerMsg = union(ServerTag) {
@@ -212,6 +218,8 @@ pub const ServerMsg = union(ServerTag) {
blobs: []const u8,
zstd: []const u8,
blob: []const u8,
+ ended: u8,
+ left: []const u8,
};
/// A message's header, for a payload sent on its own (a unit, a dump's
@@ -247,6 +255,8 @@ pub fn decodeServer(tag: u8, payload: []const u8) Error!ServerMsg {
.blobs => return .{ .blobs = payload },
.zstd => return .{ .zstd = payload },
.blob => return .{ .blob = payload },
+ .ended => .{ .ended = try r.takeByte() },
+ .left => .{ .left = try r.take(try r.takeInt(u16, .little)) },
};
try end(&r);
return msg;
@@ -271,6 +281,8 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 {
.pong => |v| try w.writeInt(u64, v, .little),
.dump, .unit, .screen, .blobs, .zstd, .blob => |bytes| try w.writeAll(bytes),
.check => |v| try w.writeInt(u64, v, .little),
+ .ended => |code| try w.writeByte(code),
+ .left => |name| try putSlice16(&w, name),
}
try finishMessage(&w, at);
return w.buffered();
@@ -289,8 +301,9 @@ pub fn helloVersion(payload: []const u8) Error!u16 {
/// one call and no longer.
pub const ClientMsg = union(enum) {
hello: Hello,
- /// The client's end: `again`, it joins again for its view at once.
- bye: struct { again: bool = false },
+ /// The client's end: `again`, it joins again for its view at once;
+ /// `close`, its window was closed (a pair's session ends at its last).
+ bye: struct { again: bool = false, close: bool = false },
/// A round trip's probe, answered `pong` with the same value.
ping: u64,
screen_ack: []const u8,
@@ -507,7 +520,8 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
try putSlice16(&w, h.session);
try w.writeByte(h.view orelse 0xff);
},
- .bye => |b| try w.writeByte(@intFromBool(b.again)),
+ // 0 it leaves, 1 it joins again, 2 its window was closed.
+ .bye => |b| try w.writeByte(if (b.close) 2 else @intFromBool(b.again)),
.ping => |v| try w.writeInt(u64, v, .little),
.screen_ack, .want => |bytes| try w.writeAll(bytes),
.check => {},
@@ -577,7 +591,12 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg {
else => |k| k,
},
} },
- .bye => .{ .bye = .{ .again = try getBool(&r) } },
+ .bye => .{ .bye = switch (try r.takeByte()) {
+ 0 => .{},
+ 1 => .{ .again = true },
+ 2 => .{ .close = true },
+ else => return error.BadValue,
+ } },
.ping => .{ .ping = try r.takeInt(u64, .little) },
.screen_ack => return .{ .screen_ack = payload },
.check => .check,
@@ -692,6 +711,7 @@ test "detached wire: every Event variant round-trips" {
try testing.expectEqualStrings("work", got.hello.session);
}
try testing.expect((try roundClient(&buf, .{ .bye = .{ .again = true } })).bye.again);
+ try testing.expect((try roundClient(&buf, .{ .bye = .{ .close = true } })).bye.close);
try testing.expectEqual(@as(?u8, 2), (try roundClient(&buf, .{ .hello = .{ .session = "work", .view = 2 } })).hello.view);
try testing.expectEqual(@as(u64, 0xfeed_beef_0000_0001), (try roundClient(&buf, .{ .ping = 0xfeed_beef_0000_0001 })).ping);
{