summaryrefslogtreecommitdiff
path: root/runtime/client.zig
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/client.zig')
-rw-r--r--runtime/client.zig40
1 files changed, 34 insertions, 6 deletions
diff --git a/runtime/client.zig b/runtime/client.zig
index 7941889e..d4b76a1b 100644
--- a/runtime/client.zig
+++ b/runtime/client.zig
@@ -125,11 +125,14 @@ pub const Ended = union(enum) { done, gone, failed, left, ended: u8, upgrade: u8
/// process's child still), joining for `view` (PARDES_JOIN_VIEW; far,
/// PARDES_REPLICA_FAR). The terminal's blink: no record crosses the exec.
/// Returns only when the exec failed: why.
-pub fn execAgain(s: *Start, view: u8) []const u8 {
+pub fn execAgain(s: *Start, view: u8, size: ?[2]c_int) []const u8 {
const path = upgrade.exe() orelse return "Upgrade: this client does not know the path it was started from";
var at_buf: [4200]u8 = undefined;
const at = std.fmt.bufPrintSentinel(&at_buf, "--attach={s}:{s}", .{ s.dial.path, s.dial.session }, 0) catch return "Upgrade: the session's socket's path is too long to attach again by";
- const argv = [_:null]?[*:0]const u8{ path, at };
+ // A window's new window the size it had (`--geometry`), not the default.
+ var size_buf: [48]u8 = undefined;
+ const geometry: ?[*:0]const u8 = if (size) |wh| (std.fmt.bufPrintSentinel(&size_buf, "--geometry={d}x{d}", .{ wh[0], wh[1] }, 0) catch unreachable).ptr else null; // two c_ints fit 48
+ const argv = [_:null]?[*:0]const u8{ path, at, geometry };
var view_buf: [32]u8 = undefined;
const joining = std.fmt.bufPrintSentinel(&view_buf, "PARDES_JOIN_VIEW={d}", .{view}, 0) catch unreachable; // a u8 fits 32
var n: usize = 0;
@@ -182,15 +185,18 @@ pub fn Loop(comptime Frontend: type) type {
l.link.take(msg);
}
- /// A join a pass: the first, and one after the replica diverged or
- /// the session let it go to upgrade; the frontend stays as it is.
+ /// A join a pass: the first, and one after the replica diverged, fell
+ /// too far behind (replica.behind_max_ms) or the session let it go
+ /// (to upgrade, or cut off); the frontend stays as it is.
pub fn run(l: *L, s: *Start) !Ended {
const link = &l.link;
// Its start path's file, for an Upgrade's question (`upgrade`).
upgrade.locate();
while (true) {
link.reset(s.r, &s.joined);
- l.fe.start(l);
+ if (s.joined.booted) {
+ if (!l.confirm(s)) return .failed;
+ } else l.fe.start(l);
var done: std.atomic.Value(bool) = .init(false);
const reader = try std.Thread.spawn(.{}, read, .{ l, s, &done });
while (!link.quit) {
@@ -198,7 +204,7 @@ pub fn Loop(comptime Frontend: type) type {
l.after();
}
if (s.env.get("PARDES_REPLICA_STATS")) |file| link.writeStats(file);
- if (!link.gone) replica.bye(s.joined.fd, .{ .again = s.r.diverged != null, .close = link.close });
+ if (!link.gone) replica.bye(s.joined.fd, .{ .again = s.r.diverged != null or link.lagged != 0, .close = link.close });
// The link's reader ends with the link, posting as it goes:
// what it posted is let go until it has (a terminal's queue
// is bounded: a reader blocked on it would never end).
@@ -231,6 +237,28 @@ pub fn Loop(comptime Frontend: type) type {
}
}
+ /// A pair's first join, its replica its own boot (replica.ownBoot): its
+ /// start's inputs held and its first pass drawn, then the session's
+ /// welcome read: the same core, what was held is sent; another (the
+ /// dump came), the dump's replica in place of the boot's, started
+ /// again. False, and why in `s.why`: no session to go on with.
+ fn confirm(l: *L, s: *Start) bool {
+ const link = &l.link;
+ link.held = .empty;
+ l.fe.start(l);
+ _ = l.before();
+ const r = replica.confirmBoot(s.gpa, &s.joined, s.r, s.o, &s.why) orelse {
+ link.release(s.gpa, false);
+ return false;
+ };
+ link.release(s.gpa, r == s.r);
+ if (r == s.r) return true;
+ s.r = r;
+ link.reset(r, &s.joined);
+ l.fe.start(l);
+ return true;
+ }
+
/// The session's stream, onto the frontend's queue: its messages,
/// and its end.
fn read(l: *L, s: *Start, done: *std.atomic.Value(bool)) void {