summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 09:02:18 -0300
committerGabriel Schneider <[email protected]>2026-10-31 09:02:18 -0300
commit6d3b6cbc1361d174ffabb49b2ee84c5c6039dda5 (patch)
tree0809839cacd93451df22563271d0c07fd2bafdbd /src/replica.zig
parenta479792a1ab2b593642d7f648194bfa23ce01dba (diff)
downloadpardes-6d3b6cbc1361d174ffabb49b2ee84c5c6039dda5.tar.gz
pardes-6d3b6cbc1361d174ffabb49b2ee84c5c6039dda5.zip
Enable native macOS replica sockets and repair platform validation
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/replica.zig b/src/replica.zig
index 8cacb075..155492c3 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -1210,6 +1210,15 @@ fn terminalDigests(p: *const Pardes, out: *[pardes.MAX_PANES]u64) void {
const libc = std.c;
const log = std.log.scoped(.replica);
const nosignal: u32 = if (builtin.os.tag == .linux) libc.MSG.NOSIGNAL else 0;
+const stream_kind = libc.SOCK.STREAM | (if (builtin.os.tag.isDarwin()) 0 else libc.SOCK.CLOEXEC);
+
+fn prepareStream(fd: c_int) void {
+ @import("9p_io.zig").setCloexec(fd);
+ if (comptime builtin.os.tag.isDarwin()) {
+ const on: c_int = 1;
+ _ = libc.setsockopt(fd, libc.SOL.SOCKET, libc.SO.NOSIGPIPE, &on, @sizeOf(c_int));
+ }
+}
/// What a client may leave unread, past its join's dump, before it is cut
/// off: minutes of typing, a screenful of a flood's deltas many times over.
/// PARDES_REPLICA_LAG_KB says another (a test's).
@@ -2211,9 +2220,9 @@ pub const Peers = struct {
fn writeStats(ps: *Peers, path: []const u8) void {
var buf: [400]u8 = undefined;
const line = std.fmt.bufPrint(&buf, "session inputs {d} input_us {d}/{d}/{d} boundaries {d} boundary_us {d}/{d}/{d} join_us {d} dump_kb {d} state_kb {d} cut {d}\n", .{
- ps.input_ns.items.len, pctOf(ps.input_ns.items, 50) / 1000, pctOf(ps.input_ns.items, 99) / 1000, pctOf(ps.input_ns.items, 100) / 1000,
- ps.boundary_ns.items.len, pctOf(ps.boundary_ns.items, 50) / 1000, pctOf(ps.boundary_ns.items, 99) / 1000, pctOf(ps.boundary_ns.items, 100) / 1000,
- ps.join_ns / 1000, ps.dump_bytes >> 10, ps.state_bytes >> 10, ps.cut,
+ ps.input_ns.items.len, pctOf(ps.input_ns.items, 50) / 1000, pctOf(ps.input_ns.items, 99) / 1000, pctOf(ps.input_ns.items, 100) / 1000,
+ ps.boundary_ns.items.len, pctOf(ps.boundary_ns.items, 50) / 1000, pctOf(ps.boundary_ns.items, 99) / 1000, pctOf(ps.boundary_ns.items, 100) / 1000,
+ ps.join_ns / 1000, ps.dump_bytes >> 10, ps.state_bytes >> 10, ps.cut,
}) catch return;
var z: [4096]u8 = undefined;
const pz = std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return;
@@ -2265,8 +2274,9 @@ pub const Got = struct { pos: usize, len: usize, hash: [32]u8 };
/// for those it holds nowhere. Errors are said in `why`. `view`: the one
/// it had, joining again for it.
pub fn dial(gpa: Allocator, path: []const u8, session: []const u8, why: []u8, have: ?*Have, view: ?u8) ?Joined {
- const fd = libc.socket(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0);
+ const fd = libc.socket(libc.AF.UNIX, stream_kind, 0);
if (fd < 0) return said(why, "no socket", .{});
+ prepareStream(fd);
var addr: libc.sockaddr.un = .{ .path = @splat(0) };
if (path.len >= addr.path.len) {
_ = libc.close(fd);
@@ -2972,11 +2982,11 @@ pub const Link = struct {
const e = &c.r.echo.stats;
var w: std.Io.Writer = .fixed(&buf);
w.print("inputs {d} at_once {d} stopped {d} units {d} fast {d} neutral {d} mispredicted {d} foreign {d} visible {d} rtt_us {d} spec_us {d}/{d} copy_us {d}/{d} rollback_us {d}/{d} join_ms {d} blobs {d} from_memory {d} from_disk {d} sent_kb {d} echo {d}/{d} confirmed {d} missed {d}", .{
- st.inputs, st.speculated, st.stopped, st.units, st.fast,
- c.r.neutral, st.mispredicted, st.foreign, c.visible, c.r.rtt_ns / 1000,
- pctOf(st.spec_ns.items, 50) / 1000, pctOf(st.spec_ns.items, 99) / 1000, pctOf(st.copy_ns.items, 50) / 1000, pctOf(st.copy_ns.items, 99) / 1000, pctOf(st.rollback_ns.items, 50) / 1000,
- pctOf(st.rollback_ns.items, 99) / 1000, c.join_ms, c.join.blobs, c.join.from_memory, c.join.from_disk,
- c.join.sent_bytes >> 10, e.predicted, e.predicted + e.unpredicted, e.confirmed, e.mispredicted,
+ st.inputs, st.speculated, st.stopped, st.units, st.fast,
+ c.r.neutral, st.mispredicted, st.foreign, c.visible, c.r.rtt_ns / 1000,
+ pctOf(st.spec_ns.items, 50) / 1000, pctOf(st.spec_ns.items, 99) / 1000, pctOf(st.copy_ns.items, 50) / 1000, pctOf(st.copy_ns.items, 99) / 1000, pctOf(st.rollback_ns.items, 50) / 1000,
+ pctOf(st.rollback_ns.items, 99) / 1000, c.join_ms, c.join.blobs, c.join.from_memory, c.join.from_disk,
+ c.join.sent_bytes >> 10, e.predicted, e.predicted + e.unpredicted, e.confirmed, e.mispredicted,
}) catch return;
// What stopped its inputs, last: a word a pair before it.
w.writeAll(" stops ") catch return;
@@ -3507,7 +3517,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
// Normal mode in the shell, up a few rows, then half a screen and more:
// the cursor leaves the view, and the view follows it back.
const keys = [_]pardes.Key{
- .{ .cp = a.core.opts.tty_toggle, .ctrl = true }, .{ .cp = 'k', .text = "k" }, .{ .cp = 'k', .text = "k" },
+ .{ .cp = a.core.opts.tty_toggle, .ctrl = true }, .{ .cp = 'k', .text = "k" }, .{ .cp = 'k', .text = "k" },
.{ .cp = 'u', .ctrl = true }, .{ .cp = 'u', .ctrl = true }, .{ .cp = 'k', .text = "k" },
};
for (keys) |k| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .key = k })));
@@ -3789,7 +3799,9 @@ test "the blob cache stays under its cap, the least recently used going first" {
/// its hello read off first.
fn farJoinOnce(ps: *Peers, core: *Pardes, have: ?*Have) !Joined {
var fds: [2]c_int = undefined;
- if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket;
+ if (libc.socketpair(libc.AF.UNIX, stream_kind, 0, &fds) != 0) return error.NoSocket;
+ prepareStream(fds[0]);
+ prepareStream(fds[1]);
var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty;
const state = pardes.dump.dumpJoin(core, &blobs) catch |err| {
_ = libc.close(fds[0]);