diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:51:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 09:54:56 -0300 |
| commit | 0d12ef0cc421fededd38681a60e89dae593dee60 (patch) | |
| tree | 23299b78b51e37c93c3654faeb09c1d9c5b6cfb6 /src | |
| parent | b414dc1746552f94649109150fcd0855529acb9e (diff) | |
| download | pardes-0d12ef0cc421fededd38681a60e89dae593dee60.tar.gz pardes-0d12ef0cc421fededd38681a60e89dae593dee60.zip | |
replica: readStream, which nothing calls, goes, and readFramed, used once, is inlined in Peer.readLoop, its framer freed before the peer is said gone
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/replica.zig | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/replica.zig b/src/replica.zig index 8bc27256..0adadb7e 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -1408,12 +1408,6 @@ pub const Framer = struct { } }; -fn readFramed(gpa: Allocator, fd: c_int, ctx: anytype, comptime take: fn (@TypeOf(ctx), u8, []const u8) bool) void { - var fr: Framer = .{}; - defer fr.deinit(gpa); - fr.run(gpa, fd, ctx, take); -} - pub const Peer = struct { peers: *Peers, fd: c_int, @@ -1702,7 +1696,10 @@ pub const Peer = struct { } fn readLoop(peer: *Peer) void { - readFramed(peer.peers.gpa, peer.fd, peer, take); + // The framer goes before `gone`, after which the peer may be freed. + var fr: Framer = .{}; + fr.run(peer.peers.gpa, peer.fd, peer, take); + fr.deinit(peer.peers.gpa); peer.peers.post(.{ .gone = peer }); } }; @@ -2252,7 +2249,7 @@ pub const Joined = struct { /// Its build's (wire.semantics): the daemon judged the hello by what it /// last heard, which an upgrade under way may not have said yet. semantics: u64 = 0, - /// What was read past the dump: the stream's (`readStream`). + /// What was read past the dump: the stream's (`readLink`). rest: Framer = .{}, /// A far join's blobs that came over the link, for `Have.store` (the C /// heap's), and how it went: its blobs, those it held already (from the @@ -2731,13 +2728,6 @@ pub fn bye(fd: c_int, again: bool) void { if (wire.encodeClient(&out, .{ .bye = .{ .again = again } })) |b| _ = writeAll(fd, b) else |_| {} } -/// What follows the dump on the client's connection, each message handed -/// to `take` (a unit, a terminal's delta) until the link ends; `rest` is -/// what the dump's reader read past it. -pub fn readStream(gpa: Allocator, fd: c_int, rest: *Framer, ctx: anytype, comptime take: fn (@TypeOf(ctx), u8, []const u8) bool) void { - rest.run(gpa, fd, ctx, take); -} - /// What the session streams a client after its dump, as its frontend's loop /// takes it: a unit's and a terminal message's bytes and a refusal's words /// on the C heap, the loop's to free. |
