summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/echo.zig2
-rw-r--r--core/replica.zig40
-rw-r--r--test/replicas.zig4
3 files changed, 23 insertions, 23 deletions
diff --git a/core/echo.zig b/core/echo.zig
index 40200696..f35c9f9d 100644
--- a/core/echo.zig
+++ b/core/echo.zig
@@ -614,7 +614,7 @@ const Rig = struct {
for (msgs.items) |m| gpa.free(m);
msgs.deinit(gpa);
}
- try g.screens.flush(g.a.core, g.peer, g.r.view, &msgs);
+ try g.screens.flush(g.a.core, g.peer, &msgs);
for (msgs.items) |m| if (g.r.screen(m)) |reply| {
_ = try g.screens.take(g.a.core, g.peer, reply);
};
diff --git a/core/replica.zig b/core/replica.zig
index ff1e138e..1a127ad4 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -157,7 +157,7 @@ pub const Authority = struct {
seq: u32 = 0,
/// Each client's view (core/views.zig): its own layout, focus and
/// cursors over the session's text. The first client has the session's.
- view_of: [64]u8 = @splat(0),
+ view_of: [64]Pardes.View.Id = @splat(.at(0)),
/// Steps of its own taken since the last unit (`output`): one unit,
/// `pending`, sent before the next input it steps and at a frame.
batched: u32 = 0,
@@ -279,7 +279,7 @@ pub const Authority = struct {
};
a.core.pump(a.host) catch {};
was.end();
- a.view_of[client] = k.index();
+ a.view_of[client] = k;
a.seq += 1;
return .{ .view = k.index(), .unit = try a.unit(0, a.seq) };
}
@@ -296,7 +296,7 @@ pub const Authority = struct {
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.view_of[client] = .at(k);
a.seq += 1;
const u = try a.unit(0, a.seq);
var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty;
@@ -322,8 +322,8 @@ pub const Authority = struct {
std.debug.assert(a.batched == 0);
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(.at(k)) else a.core.closeView(.at(k));
+ a.core.undrawn &= ~(@as(u8, 1) << @intCast(k.index()));
+ if (again) a.core.awayView(k) else a.core.closeView(k);
was.end();
a.seq += 1;
return a.unit(0, a.seq);
@@ -333,7 +333,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(.at(a.view_of[client]));
+ a.core.closeView(a.view_of[client]);
was.end();
a.seq += 1;
return a.unit(0, a.seq);
@@ -345,7 +345,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(.at(a.view_of[in.client]));
+ a.core.toView(a.view_of[in.client]);
a.t.stamp = stampOf(in);
a.core.update(in.event);
a.core.step();
@@ -450,7 +450,7 @@ pub const Screens = struct {
/// What `peer` is owed of every terminal, each a message onto `out`
/// (owned): nothing for one it has as it is, or with `bound` in flight.
- pub fn flush(s: *Screens, core: *Pardes, peer: u16, _: u8, out: *std.ArrayListUnmanaged([]u8)) !void {
+ pub fn flush(s: *Screens, core: *Pardes, peer: u16, out: *std.ArrayListUnmanaged([]u8)) !void {
const t0 = nowNs();
defer s.encode_ns += nowNs() - t0;
for (core.panes, 0..) |slot, id| {
@@ -1667,7 +1667,7 @@ pub const Peer = struct {
peers: *Peers,
fd: c_int,
id: u16,
- view: u8,
+ view: Pardes.View.Id,
/// Its process (its socket's peer), for `--ps`; 0 not known.
pid: libc.pid_t = 0,
/// Its bye said it joins again for its view (a divergence's rejoin):
@@ -2201,7 +2201,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(.at(peer.view));
+ core.toView(peer.view);
ps.t.stamp = stampOf(in);
core.update(in.event);
core.step();
@@ -2239,7 +2239,7 @@ pub const Peers = struct {
ps.msgs.clearRetainingCapacity();
}
(switch (what) {
- .flush => ps.screens.flush(core, peer.sid, peer.view, &ps.msgs),
+ .flush => ps.screens.flush(core, peer.sid, &ps.msgs),
.fill => ps.screens.fill(core, peer.sid, &ps.msgs),
}) catch return;
if (what == .flush) if (ps.flushed) |h| h.f(h.ctx, core, &ps.screens);
@@ -2325,12 +2325,12 @@ pub const Peers = struct {
core.gpa.free(bytes);
return daemon.refuseReplica(fd, "out of memory");
};
- peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = k, .limit = lag_max, .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa };
+ peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = .at(k), .limit = lag_max, .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa };
ps.next_id +%= 1;
if (ps.next_id == 0) ps.next_id = 1;
// The session's digest as dumped, for the joiner to check its load by.
const digest = tape.digestOf(core);
- peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = .at(k), .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
+ peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = peer.view, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null;
if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null;
if (ps.threads and (peer.writer == null or peer.reader == null)) {
@@ -2359,7 +2359,7 @@ pub const Peers = struct {
log.info("client {d} left '{s}'", .{ peer.id, ps.name });
ps.tellClients();
ps.screens.dropPeer(peer.sid);
- core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view));
+ core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view.index()));
ps.closeViewOf(core, peer, peer.again);
if (ps.count() == 0) core.unattended = ps.detached;
if (ps.count() == 0 and peer.close and !ps.kept) ps.closed = true;
@@ -2374,7 +2374,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(.at(peer.view)) else if (ps.count() == 0 and ps.detached) core.leaveView(.at(peer.view)) else core.closeView(.at(peer.view));
+ if (again) core.awayView(peer.view) else if (ps.count() == 0 and ps.detached) core.leaveView(peer.view) else core.closeView(peer.view);
}
/// Its threads ended and joined, its link closed.
@@ -2466,7 +2466,7 @@ pub const Peers = struct {
/// Detach typed in client view `k`'s: told it left the session running
/// (`left`), its last word; the client goes, and its reader says so.
pub fn detach(ps: *Peers, k: u8) bool {
- for (ps.list) |slot| if (slot) |peer| if (peer.view == k) {
+ for (ps.list) |slot| if (slot) |peer| if (peer.view.index() == k) {
ps.kept = true;
var out: [wire.max_name + 8]u8 = undefined;
peer.last(wire.encodeServer(&out, .{ .left = ps.name[0..@min(ps.name.len, wire.max_name)] }) catch unreachable);
@@ -2504,7 +2504,7 @@ pub const Peers = struct {
fn drop(ps: *Peers, core: *Pardes, again: bool) void {
for (&ps.list) |*slot| if (slot.*) |peer| {
slot.* = null;
- core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view));
+ core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view.index()));
ps.closeViewOf(core, peer, again);
ps.screens.dropPeer(peer.sid);
ps.letGo(peer);
@@ -3470,7 +3470,7 @@ fn deliver(a: *Authority, screens: *Screens, peer: u16, r: *Replica, comptime wh
msgs.deinit(gpa);
}
switch (what) {
- .flush => try screens.flush(a.core, peer, r.view, &msgs),
+ .flush => try screens.flush(a.core, peer, &msgs),
.fill => {
try screens.fill(a.core, peer, &msgs);
screens.filled(a.core);
@@ -3503,7 +3503,7 @@ fn farJoinOnce(ps: *Peers, core: *Pardes, have: ?*Have) !Joined {
var whole = state.len;
for (blobs.items) |b| whole += b.bytes.len;
const peer = try ps.gpa.create(Peer);
- peer.* = .{ .peers = ps, .fd = fds[0], .id = 1, .view = 0, .dump = state, .blobs = blobs, .dump_gpa = core.gpa };
+ peer.* = .{ .peers = ps, .fd = fds[0], .id = 1, .view = .at(0), .dump = state, .blobs = blobs, .dump_gpa = core.gpa };
peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = 1, .session = "t", .dump_len = whole, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
const Serve = struct {
fn run(p: *Peer) void {
@@ -5159,7 +5159,7 @@ test "a client that diverged joins again for its view: kept for it meanwhile, it
const back = try joinedNow(a, 3, opened.view);
defer back.deinit();
try std.testing.expectEqual(digestOf(a), back.digest());
- a.view_of[3] = opened.view;
+ a.view_of[3] = .at(opened.view);
const u = try gpa.dupe(u8, try a.take(try back.input(.{ .key = .{ .cp = 'l', .text = "l" } })));
defer gpa.free(u);
old.confirm(u);
diff --git a/test/replicas.zig b/test/replicas.zig
index 6a6d43b4..d78e3e02 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -1044,7 +1044,7 @@ const Soak = struct {
// A Detach typed in a client's view, or one cut off for its lag: its
// link shut, it hears its end and nothing after; its reader's end
// said (the next boundary lets it go).
- if (s.detach_view) |k| for (s.clients) |*cl| if (cl.peer) |p| if (p.view == k and !cl.shut) {
+ if (s.detach_view) |k| for (s.clients) |*cl| if (cl.peer) |p| if (p.view.index() == k and !cl.shut) {
cl.shut = true;
};
s.detach_view = null;
@@ -1931,7 +1931,7 @@ fn flushAll(sc: *replica.Screens, core: *pardes.Pardes, ps: []const u16, list: *
for (ps, 0..) |peer, c| {
list.clearRetainingCapacity();
// Terminals alone cross: the view is not read.
- try sc.flush(core, peer, 0, list);
+ try sc.flush(core, peer, list);
for (list.items) |bytes| {
tot.deltas += 1;
tot.delta_bytes += bytes.len;