summaryrefslogtreecommitdiff
path: root/src/daemon.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon.zig')
-rw-r--r--src/daemon.zig14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index 467af8b8..b93f5d43 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -379,10 +379,13 @@ pub const Note = union(enum) {
/// stub's pipe; for a window session, both -1: open a window.
attach: struct { tty: c_int, stub: c_int },
adopted: struct { pids: [max_fds]libc.pid_t, fds: [max_fds]c_int, n: usize },
- /// A replica's connection, its hello taken (src/replica.zig `Peers`).
- replica: c_int,
+ /// A replica's connection, its hello taken (src/replica.zig `Peers`),
+ /// and the view it joins again for, if it does.
+ replica: Joining,
};
+pub const Joining = struct { fd: c_int, view: ?u8 = null };
+
/// Hands every note the daemon sends on to `deliver`, on a thread of its
/// own, until the link ends (`quit`). Called each loop: started once.
pub fn watch(ctx: *anyopaque, deliver: *const fn (ctx: *anyopaque, note: Note) void) void {
@@ -409,7 +412,8 @@ fn readNotes(fd: c_int, ctx: *anyopaque, deliver: *const fn (ctx: *anyopaque, no
} });
for (got.fds[@min(got.nfds, 2)..got.nfds]) |f| _ = libc.close(f);
} else if (std.mem.eql(u8, verb, "replica")) {
- if (got.nfds >= 1) deliver(ctx, .{ .replica = got.fds[0] });
+ const view = std.fmt.parseInt(u8, words.next() orelse "", 10) catch null;
+ if (got.nfds >= 1) deliver(ctx, .{ .replica = .{ .fd = got.fds[0], .view = view } });
for (got.fds[@min(got.nfds, 1)..got.nfds]) |f| _ = libc.close(f);
} else if (std.mem.eql(u8, verb, "adopted")) {
var note: Note = .{ .adopted = .{ .pids = undefined, .fds = undefined, .n = 0 } };
@@ -951,7 +955,9 @@ const Daemon = struct {
} else return refuse(r, std.fmt.bufPrint(&why, "no session called '{s}'", .{h.session}) catch "no such session");
const t = &d.conns[target];
if (t.semantics != h.semantics) return refuse(r, std.fmt.bufPrint(&why, "session '{s}' runs another build of pardes (semantics {x:0>16}, this client's {x:0>16}): a replica needs the same build at both ends, as `pardes --version` shows", .{ h.session, t.semantics, h.semantics }) catch "another build");
- if (!send(t.fd, "replica", &.{r.fd})) {
+ var words: [16]u8 = undefined;
+ const note = if (h.view) |k| std.fmt.bufPrint(&words, "replica {d}", .{k}) catch unreachable else "replica";
+ if (!send(t.fd, note, &.{r.fd})) {
d.hangUp(@intCast(target));
return refuse(r, "that session does not answer");
}