summaryrefslogtreecommitdiff
path: root/src/tty/tty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tty/tty.zig')
-rw-r--r--src/tty/tty.zig25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 430c020d..4c054021 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -153,7 +153,7 @@ pub const Command = struct {
files_changed,
fs_ready,
/// A replica's connection, handed over by the daemon (Peers).
- replica: posix.fd_t,
+ replica: daemon.Joining,
/// A replica's reader posted: the step boundary takes it in.
replica_mail,
/// A replica client's: what the session streamed (replica.Link).
@@ -1333,7 +1333,7 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
defer have_store.deinit();
const have: ?*replica.Have = if (far) &have_store else null;
var dial_t0 = std.Io.Clock.awake.now(io).nanoseconds;
- var joined = replica.dial(gpa, path, session, &why, have) orelse Said.no(io, "{s}", .{std.mem.sliceTo(&why, 0)});
+ var joined = replica.dial(gpa, path, session, &why, have, null) orelse Said.no(io, "{s}", .{std.mem.sliceTo(&why, 0)});
if (joined.semantics != wire.semantics) Said.no(io, "{s}", .{replica.Link.upgrade_words});
const allocs = pardes.memory.init(gpa);
@@ -1445,7 +1445,7 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
if (r.diverged != null) link.quit = true;
}
if (init.environ_map.get("PARDES_REPLICA_STATS")) |file| link.writeStats(file);
- if (!link.gone) replica.bye(joined.fd);
+ if (!link.gone) replica.bye(joined.fd, r.diverged != null);
// The link's reader ends with the link, posting as it goes: what it
// and the terminal posted is let go until it has. Its end is read
// before the drain, not after: its last post (`link_gone`) comes
@@ -1482,7 +1482,7 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se
// are not sent again.
if (have) |h| h.leaving(r.core());
dial_t0 = std.Io.Clock.awake.now(io).nanoseconds;
- joined = replica.Link.redial(gpa, path, session, &why, have, r.diverged == null) orelse {
+ joined = replica.Link.redial(gpa, path, session, &why, have, r.diverged == null, joined.view) orelse {
screen.leave();
Said.no(io, "could not join again: {s}", .{std.mem.sliceTo(&why, 0)});
};
@@ -1916,8 +1916,8 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
};
loop.postEvent(.{ .adopted = .{ .pid = 0, .fd = -1 } }) catch {};
},
- .replica => |fd| loop.postEvent(.{ .replica = fd }) catch {
- _ = libc.close(fd);
+ .replica => |j| loop.postEvent(.{ .replica = j }) catch {
+ _ = libc.close(j.fd);
},
}
}
@@ -2338,7 +2338,7 @@ const Shell = struct {
/// An upgraded session's terminals, each its view's again (`primary`,
/// run's, entered already); in a fresh session each but the primary a
/// view of its own, as `--attach` makes one. A view left with none
- /// closes.
+ /// closes, but a replica client's, kept for its rejoin (views.away).
fn resumeTerminals(s: *Shell, rec: *const upgrade.Record, primary: *Screen) void {
if (comptime builtin.is_test) unreachable;
const core = s.core;
@@ -2348,8 +2348,11 @@ const Shell = struct {
}
s.terms = @splat(null);
if (rec.nttys == 0) {
- pardes.views.only(core);
+ // The live view alone (never one kept for a rejoin) is the
+ // session's own.
+ for (0..pardes.views.max) |k| if (k != core.view and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
s.terms[core.view] = primary;
+ primary.feed.view = core.view;
return;
}
for (rec.ttys[0..rec.nttys]) |t| {
@@ -2386,7 +2389,7 @@ const Shell = struct {
sc.feed.view = t.view;
s.terms[t.view] = sc;
}
- for (0..pardes.views.max) |k| if (pardes.views.isOpen(core, @intCast(k)) and s.terms[k] == null) core.closeView(@intCast(k));
+ for (0..pardes.views.max) |k| if (pardes.views.isOpen(core, @intCast(k)) and s.terms[k] == null and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
if (s.terms[core.view] == null) s.terms[core.view] = primary;
}
@@ -2623,8 +2626,8 @@ const Shell = struct {
},
.attach => |a| s.attachTerminal(a.tty, a.stub, null),
.adopted => |a| s.adoptShell(a.pid, a.fd),
- .replica => |fd| {
- s.peers.handed(fd);
+ .replica => |j| {
+ s.peers.handed(j.fd, j.view);
s.input_seen = true;
},
.replica_mail => s.input_seen = true,