summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig46
1 files changed, 23 insertions, 23 deletions
diff --git a/core/replica.zig b/core/replica.zig
index fb3a81c4..625153d1 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -233,7 +233,7 @@ pub const Authority = struct {
pub fn own(a: *Authority, ev: pardes.Event) ![]const u8 {
std.debug.assert(a.batched == 0);
const was = Stepping.begin(&a.t, null);
- a.core.toView(0);
+ a.core.toView(.at(0));
was.end();
return a.local(ev);
}
@@ -276,9 +276,9 @@ pub const Authority = struct {
};
a.core.pump(a.host) catch {};
was.end();
- a.view_of[client] = k;
+ a.view_of[client] = k.index();
a.seq += 1;
- return .{ .view = k, .unit = try a.unit(0, a.seq) };
+ return .{ .view = k.index(), .unit = try a.unit(0, a.seq) };
}
/// A client joining as `Peers.join` takes one: its view kept for it
@@ -290,8 +290,8 @@ pub const Authority = struct {
std.debug.assert(a.batched == 0);
const was = Stepping.begin(&a.t, null);
defer was.end();
- const again = if (back) |v| a.core.rejoinView(v) else false;
- const k = (if (again) back else a.core.openView()) orelse return null;
+ const again = if (back) |v| a.core.rejoinView(.at(v)) else false;
+ const k = (if (again) back else if (a.core.openView()) |o| o.index() else null) orelse return null;
a.core.undrawn |= @as(u8, 1) << @intCast(k);
a.view_of[client] = k;
a.seq += 1;
@@ -320,7 +320,7 @@ pub const Authority = struct {
const was = Stepping.begin(&a.t, null);
const k = a.view_of[client];
a.core.undrawn &= ~(@as(u8, 1) << @intCast(k));
- if (again) a.core.awayView(k) else a.core.closeView(k);
+ if (again) a.core.awayView(.at(k)) else a.core.closeView(.at(k));
was.end();
a.seq += 1;
return a.unit(0, a.seq);
@@ -330,7 +330,7 @@ pub const Authority = struct {
pub fn closeView(a: *Authority, client: u16) ![]const u8 {
std.debug.assert(a.batched == 0);
const was = Stepping.begin(&a.t, null);
- a.core.closeView(a.view_of[client]);
+ a.core.closeView(.at(a.view_of[client]));
was.end();
a.seq += 1;
return a.unit(0, a.seq);
@@ -342,7 +342,7 @@ pub const Authority = struct {
std.debug.assert(a.batched == 0);
const in = parseInput(msg) orelse return error.BadInput;
const was = Stepping.begin(&a.t, null);
- a.core.toView(a.view_of[in.client]);
+ a.core.toView(.at(a.view_of[in.client]));
a.t.stamp = stampOf(in);
a.core.update(in.event);
a.core.step();
@@ -1127,7 +1127,7 @@ pub const Replica = struct {
tape.beginSpeculation(&r.t);
// The time it was sent with, every time it is applied.
r.t.guess = p.guess;
- c.toView(r.view);
+ c.toView(.at(r.view));
// Input into a terminal: what reaches its program (a key in tty
// mode, a paste, a mouse report) is a pty write, the authority's,
// and stops here (phase 6 predicts its echo). The rest (pardes's
@@ -2162,7 +2162,7 @@ pub const Peers = struct {
// The terminals as this step reads them, then the step, the rows
// it read, its unit (part B terminal notes' order).
ps.screensOut(core, .flush);
- core.toView(peer.view);
+ core.toView(.at(peer.view));
ps.t.stamp = stampOf(in);
core.update(in.event);
core.step();
@@ -2234,8 +2234,8 @@ pub const Peers = struct {
// link's end (posted by that link's reader, microseconds after the
// bye; the redial is a dial and the daemon's hand-over later) finds
// its view not kept yet, and takes a new one.
- const back = if (joining.view) |v| core.rejoinView(v) else false;
- const k = (if (back) joining.view else core.openView()) orelse {
+ const back = if (joining.view) |v| core.rejoinView(.at(v)) else false;
+ const k = (if (back) joining.view else if (core.openView()) |o| o.index() else null) orelse {
core.unattended = ps.count() == 0 and ps.detached;
if (ps.count() == 0) ps.stop(core);
return daemon.refuseReplica(fd, "that session has as many views as it takes");
@@ -2251,7 +2251,7 @@ pub const Peers = struct {
const bytes = pardes.dump.dumpJoin(core, &blobs) catch |err| {
blobs.deinit(core.gpa);
core.undrawn &= ~(@as(u8, 1) << @intCast(k));
- core.closeView(k);
+ core.closeView(.at(k));
ps.unit(0, ps.seq);
if (ps.count() == 0) ps.stop(core);
var why: [96]u8 = undefined;
@@ -2284,7 +2284,7 @@ pub const Peers = struct {
if (ps.threads and (peer.writer == null or peer.reader == null)) {
ps.letGo(peer);
core.undrawn &= ~(@as(u8, 1) << @intCast(k));
- core.closeView(k);
+ core.closeView(.at(k));
ps.unit(0, ps.seq);
return;
}
@@ -2321,7 +2321,7 @@ pub const Peers = struct {
/// session no one else watches leaves the session its layout, for a
/// client that comes after to find.
fn closeViewOf(ps: *Peers, core: *Pardes, peer: *Peer, again: bool) void {
- if (again) core.awayView(peer.view) else if (ps.count() == 0 and ps.detached) core.leaveView(peer.view) else core.closeView(peer.view);
+ if (again) core.awayView(.at(peer.view)) else if (ps.count() == 0 and ps.detached) core.leaveView(.at(peer.view)) else core.closeView(.at(peer.view));
}
/// Its threads ended and joined, its link closed.
@@ -3916,7 +3916,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
try deliver(a, &screens, peer, r, .flush);
{
const was = Stepping.begin(&a.t, null);
- a.core.toView(0);
+ a.core.toView(.at(0));
a.core.update(.{ .key = .{ .cp = 'k', .text = "k" } });
a.core.step();
was.end();
@@ -4249,9 +4249,9 @@ test "a host's Adopt and a terminal reader's failure are inputs: a replica makes
// What tui.zig's and gui.zig's adoptShell and a failed reader do between
// steps: they wrote the core straight, and every client joined again.
const host = Stepping.begin(&a.t, null);
- const id = a.core.adoptShell().?;
+ const id = a.core.adoptShell().?.index();
try std.testing.expect(a.core.panes[id].?.isTerminal() and !a.core.panes[id].?.greet);
- a.core.readerFailed(id, error.InputOutput);
+ a.core.readerFailed(.at(id), error.InputOutput);
a.core.pump(a.host) catch {};
host.end();
a.seq += 1;
@@ -4570,7 +4570,7 @@ test "a client leaves, and one joins: what the leave queued (a terminal's resize
// It leaves: the terminal is the first view's size again, its pty's
// resize queued for the next pump; and a client joins at that boundary.
var was = Stepping.begin(&a.t, null);
- a.core.closeView(opened.view);
+ a.core.closeView(.at(opened.view));
was.end();
old.confirm(try a.unit(0, 100));
// The client left idle takes its copy ahead (Replica.ready): of a core
@@ -4580,7 +4580,7 @@ test "a client leaves, and one joins: what the leave queued (a terminal's resize
const k = a.core.openView() orelse return error.NoView;
was.end();
old.confirm(try a.unit(0, 101));
- const joiner = try joinedNow(a, 3, k);
+ const joiner = try joinedNow(a, 3, k.index());
defer joiner.deinit();
try std.testing.expectEqual(digestOf(a), joiner.digest());
// The next pump's unit, every client's.
@@ -4607,13 +4607,13 @@ test "a client that diverged joins again for its view: kept for it meanwhile, it
const made = a.core.view().active;
// Its bye says it joins again: its view is kept, as every replica keeps it.
var was = Stepping.begin(&a.t, null);
- a.core.awayView(opened.view);
+ a.core.awayView(.at(opened.view));
was.end();
old.confirm(try a.unit(0, 100));
try agrees(a, old);
// Back for it: its own, its pane in it, in the dump it loads.
was = Stepping.begin(&a.t, null);
- try std.testing.expect(a.core.rejoinView(opened.view));
+ try std.testing.expect(a.core.rejoinView(.at(opened.view)));
was.end();
old.confirm(try a.unit(0, 101));
const back = try joinedNow(a, 3, opened.view);
@@ -5092,7 +5092,7 @@ const SeenHost = struct {
fn setClipboard(ctx: ?*anyopaque, _: []const u8) void {
const h = of(ctx);
h.yanked += 1;
- if (h.tell) h.core.?.setMessage(h.core.?.view().active, "yanked");
+ if (h.tell) h.core.?.setMessage(.at(h.core.?.view().active), "yanked");
}
fn readClipboard(ctx: ?*anyopaque) void {
of(ctx).asked += 1;