summaryrefslogtreecommitdiff
path: root/src/9p_io.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:13:41 -0300
committerGabriel Schneider <[email protected]>2026-11-05 00:58:19 -0300
commit1e1212c86a13d3087a5db61e9f2a28cfcba4cc45 (patch)
treeff355c2d86482e1d21280fca2fc0fade773aa6c8 /src/9p_io.zig
parent6a665eb3d9b6542bc1765f57f19cd2fc8ce04e82 (diff)
downloadpardes-1e1212c86a13d3087a5db61e9f2a28cfcba4cc45.tar.gz
pardes-1e1212c86a13d3087a5db61e9f2a28cfcba4cc45.zip
9p_io, build: 9P over QUIC is gone: src/9p_quic.zig, the Listener's poll path on the editor's thread (its accept, fill, flush and watcher thread), the Client's quic! dials, -Dquic with its OpenSSL linking, the quic-test step that ran no test, Namespace.quic_address and /listeners' quic row, the QUIC process case, the perf baselines' quic key and every mention in the docs; main.zig still parses --9p-quic until the processes change takes it out, so 9p_io.quic_enabled stays, false, until then
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/9p_io.zig')
-rw-r--r--src/9p_io.zig415
1 files changed, 39 insertions, 376 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig
index ab7dd13f..c985845c 100644
--- a/src/9p_io.zig
+++ b/src/9p_io.zig
@@ -6,8 +6,9 @@ const cloud9 = @import("cloud9");
const transport = cloud9.transport;
const pardes = @import("pardes.zig");
const limits = @import("memory.zig").limits;
-pub const quic_enabled = @import("9p_options").quic;
-const quic = if (quic_enabled) @import("9p_quic.zig") else struct {};
+// shortcut: main.zig's --9p-quic refusal reads this until the processes
+// change takes the flag out; then it goes.
+pub const quic_enabled = false;
const log = std.log.scoped(.ninep);
@@ -62,7 +63,7 @@ extern "c" fn inet_pton(family: c_int, src: [*:0]const u8, dst: *anyopaque) c_in
pub fn networkAddress(dial: []const u8, allow_zero_port: bool) error{BadDial}!std.Io.net.IpAddress {
if (comptime !supported) return error.BadDial;
- const host_start: usize = if (std.mem.startsWith(u8, dial, "tcp!")) 4 else if (std.mem.startsWith(u8, dial, "quic!")) 5 else return error.BadDial;
+ const host_start: usize = if (std.mem.startsWith(u8, dial, "tcp!")) 4 else return error.BadDial;
const split = std.mem.lastIndexOfScalar(u8, dial, '!') orelse return error.BadDial;
if (split <= host_start or split + 1 == dial.len) return error.BadDial;
const port_text = dial[split + 1 ..];
@@ -131,33 +132,18 @@ fn localIp(address: std.Io.net.IpAddress) bool {
return false;
}
-const Srv = ninep.Server(pardes.ctlfs, ninep.editor);
-
/// The Unix and TCP listeners run on cloud9's `std.Io` runner: it accepts,
/// reads frames, steps each connection's engine and writes replies on its
/// own tasks, and every backend request is answered right there, on the
/// connection's task, by taking the editor's turn (`pardes.turn`): while the
/// editor waits for input, or while a step of it is out in a syscall --
-/// which is what lets the editor read its own tree through a mount. QUIC
-/// keeps the poll loop below, on the editor's thread.
+/// which is what lets the editor read its own tree through a mount.
const Runner = if (supported) cloud9.serve.Runner(pardes.ctlfs, ninep.editor, .{
.msize = msize,
.connections = max_conns,
.listeners = 2,
}) else void;
-const quic_slots = if (quic_enabled) max_conns else 0;
-
-/// A QUIC connection on the poll path.
-const Conn = struct {
- quic: if (quic_enabled) ?quic.Connection else void = if (quic_enabled) null else {},
- draining: bool = false,
- accepted_ms: i64 = 0,
- srv: Srv = undefined,
- in: [msize]u8 = undefined,
- out: [2 * msize]u8 = undefined,
-};
-
const accept_pause_ms: i64 = 100;
pub const Listener = struct {
@@ -190,8 +176,6 @@ pub const Listener = struct {
/// Connections accepted before this count are being cut by a Restore.
cut_before: u64 = 0,
tcp_address: ?std.Io.net.IpAddress = null,
- quic: if (quic_enabled) ?quic.Listener else void = if (quic_enabled) null else {},
- quic_address: ?std.Io.net.IpAddress = null,
paused_ms: i64 = 0,
path_buf: [sun_path_len]u8 = undefined,
path_len: usize = 0,
@@ -202,14 +186,6 @@ pub const Listener = struct {
/// (`$XDG_RUNTIME_DIR/9p/pardes/<name>`), zero when it did not.
posted_buf: [sun_path_len]u8 = undefined,
posted_len: usize = 0,
- conns: [quic_slots]Conn = @splat(.{}),
- control: [2]c_int = .{ -1, -1 },
- watcher: ?std.Thread = null,
- watch_stop: std.atomic.Value(bool) = .init(false),
- watch_lock: std.atomic.Mutex = .unlocked,
- watch_fds: [2]libc.pollfd = undefined,
- watch_len: usize = 0,
- watch_timeout: c_int = -1,
wake_ctx: ?*anyopaque = null,
wake: ?*const fn (?*anyopaque) void = null,
@@ -505,160 +481,19 @@ pub const Listener = struct {
if (l.wake) |f| f(l.wake_ctx);
}
- /// Accepts and reads QUIC connections (the runner does its own).
- pub fn accept(l: *Listener) void {
- if (comptime !quic_enabled) return;
- if (l.quic) |*listener| for (0..max_conns + 1) |_| {
- var connection = (listener.accept() catch |err| {
- log.warn("QUIC accept failed: {s}", .{@errorName(err)});
- return;
- }) orelse break;
- const c = for (&l.conns, 0..) |*cand, i| {
- if (!l.live(@intCast(i)) and !cand.draining) break cand;
- } else {
- connection.deinit();
- continue;
- };
- c.quic = connection;
- c.draining = false;
- c.accepted_ms = nowMs();
- c.srv = .init(.{ .in = &c.in, .out = &c.out, .root = pardes.ctlfs.root });
- };
- }
-
pub const greet_deadline_ms: i64 = 5000;
- pub fn expire(l: *Listener) void {
- if (comptime !quic_enabled) return;
- const now = nowMs();
- if (now == 0) return;
- for (&l.conns, 0..) |*c, i| {
- if (!l.live(@intCast(i)) or c.srv.protocol.msize != 0) continue;
- if (now - c.accepted_ms < greet_deadline_ms) continue;
- log.debug("QUIC slot {d} never sent Tversion; taking it back", .{i});
- l.drop(@intCast(i));
- }
- }
-
- pub fn nextDue(l: *const Listener) ?i32 {
- if (comptime !quic_enabled) return null;
- const now = nowMs();
- if (now == 0) return null;
- var due: ?i64 = null;
- if (l.quic) |*listener| if (listener.nextDue()) |ms| {
- const at = now + ms;
- due = if (due) |d| @min(d, at) else at;
- };
- for (&l.conns, 0..) |*c, i| {
- if (!l.live(@intCast(i))) continue;
- if (c.quic) |*connection| if (connection.pending()) return 0;
- if (c.srv.protocol.msize != 0) continue;
- const at = c.accepted_ms + greet_deadline_ms;
- due = if (due) |d| @min(d, at) else at;
- }
- const at = due orelse return null;
- return @intCast(@max(0, at - now));
- }
-
const nowMs = transport.nowMs;
- pub fn fill(l: *Listener, i: u8) void {
- if (comptime !quic_enabled) return;
- const c = &l.conns[i];
- if (c.srv.protocol.dead) return l.drop(i);
- const room = c.srv.protocol.in.len - c.srv.protocol.in_len;
- if (room == 0) return;
- var buf: [msize]u8 = undefined;
- const got = (c.quic.?.read(buf[0..@min(room, buf.len)]) catch return l.drop(i)) orelse return;
- if (got == 0) return l.drop(i);
- const n = c.srv.push(buf[0..@intCast(got)]);
- if (c.srv.protocol.dead) return l.drop(i);
- std.debug.assert(n == @as(usize, @intCast(got)));
- }
-
- pub fn flush(l: *Listener, i: u8) void {
- if (comptime !quic_enabled) return;
- const c = &l.conns[i];
- if (!l.live(i)) return;
- while (true) {
- const bytes = c.srv.output();
- if (bytes.len == 0) return;
- const n = c.quic.?.write(bytes) catch return l.drop(i);
- if (n == 0) return;
- c.srv.wrote(@intCast(n));
- }
- }
-
- pub fn live(l: *const Listener, i: u8) bool {
- if (comptime !quic_enabled) return false;
- return l.conns[i].quic != null;
- }
-
- pub fn drop(l: *Listener, i: u8) void {
- if (comptime !quic_enabled) return;
- const c = &l.conns[i];
- if (c.quic) |*connection| {
- connection.deinit();
- c.quic = null;
- }
- if (c.draining or c.accepted_ms == 0) return;
- c.srv.hangup();
- c.draining = true;
- }
-
- /// What one QUIC poll pass did: `pending` says there is more to do at
- /// once.
+ /// What a frontend's poll of the listener did; the runner's own tasks
+ /// serve every connection, so there is never more to do at once.
pub const Polled = struct { count: usize = 0, pending: bool = false };
- /// Answers one QUIC request, on the editor's thread.
- fn step(l: *Listener, srv: *Srv, req: pardes.ctlfs.Req) void {
- l.core.fs.write_room = if (srv.protocol.msize > 24) srv.protocol.msize - 24 else 0;
- const reply = l.core.serveFs(req);
- srv.reply(&reply, l.core.fsPayload(reply));
- if (req.op == .release) l.collectOs();
- }
-
- /// QUIC's events, accepts, reads, requests and replies, on the editor's
- /// thread after each of its steps; `pending` says there is more to do
- /// right away. Unix and TCP need none of this.
+ /// Between the editor's steps, which is when the host paths may be
+ /// swept: the editor's own directory listings leave nodes in it too.
pub fn tick(l: *Listener) Polled {
- var result: Polled = .{};
- // Between the editor's steps, which is when the table may be swept:
- // the editor's own directory listings leave nodes in it too.
l.collectOs();
- if (comptime quic_enabled) {
- if (l.quic) |*listener| listener.events() catch |err| {
- log.warn("QUIC listener stopped: {s}", .{@errorName(err)});
- for (&l.conns, 0..) |*conn, i| if (conn.quic != null) l.drop(@intCast(i));
- listener.deinit();
- l.quic = null;
- l.quic_address = null;
- };
- l.accept();
- for (0..quic_slots) |i| if (l.live(@intCast(i))) l.fill(@intCast(i));
- l.expire();
- for (&l.conns, 0..) |*conn, i| {
- if (!l.live(@intCast(i)) and !conn.draining) continue;
- var count: usize = 0;
- while (conn.srv.retry()) |req| {
- l.step(&conn.srv, req);
- count += 1;
- }
- while (count < 64) {
- const req = conn.srv.next() orelse break;
- l.step(&conn.srv, req);
- count += 1;
- }
- result.count += count;
- result.pending = result.pending or count >= 64;
- if (conn.draining) {
- if (count == 0) conn.draining = false else result.pending = true;
- } else l.flush(@intCast(i));
- if (conn.quic) |*connection| result.pending = result.pending or connection.pending();
- }
- l.arm();
- }
- return result;
+ return .{};
}
/// Hangs every connection up, so that `replacement` starts with no
@@ -675,12 +510,9 @@ pub const Listener = struct {
l.core.fs.news = true;
answerHeld(l);
l.core.fs.hanging_up = false;
- for (0..quic_slots) |i| l.drop(@intCast(i));
- if (comptime quic_enabled) while (l.tick().pending) {};
l.core = replacement;
replacement.fs.socket_path = l.path();
replacement.fs.tcp_address = l.tcp_address;
- replacement.fs.quic_address = l.quic_address;
if (comptime supported) {
// The Restore's writer answers as it wakes (`onServe`), and its
// answer gets 200 ms to leave before the cut; every other request
@@ -716,8 +548,6 @@ pub const Listener = struct {
l.cut_before = 0;
}
l.collectOs();
- for (&l.conns) |*conn| conn.accepted_ms = 0;
- l.arm();
}
/// Forgets the host paths no connection names any more. With the turn,
@@ -753,70 +583,13 @@ pub const Listener = struct {
if (conn.engine.references(node)) return true;
}
}
- for (&l.conns, 0..) |*conn, j| {
- if (!l.live(@intCast(j)) and !conn.draining) continue;
- if (conn.srv.references(node)) return true;
- }
return false;
}
- /// Where the runner's tasks report that a request changed the core,
- /// and for QUIC a thread that watches its socket and calls `wake` when
- /// `tick` has something to read.
+ /// Where the runner's tasks report that a request changed the core.
pub fn watch(l: *Listener, ctx: ?*anyopaque, wake: *const fn (?*anyopaque) void) !void {
l.wake_ctx = ctx;
l.wake = wake;
- if (comptime !quic_enabled) return;
- if (l.quic == null or l.watcher != null) return;
- if (libc.pipe(&l.control) != 0) return error.PipeFailed;
- errdefer {
- _ = libc.close(l.control[0]);
- _ = libc.close(l.control[1]);
- l.control = .{ -1, -1 };
- }
- for (l.control) |fd| {
- setCloexec(fd);
- _ = setNonblock(fd);
- }
- l.arm();
- l.watcher = try std.Thread.spawn(.{}, watchQuic, .{l});
- }
-
- fn arm(l: *Listener) void {
- if (comptime !quic_enabled) return;
- if (l.control[1] < 0) return;
- while (!l.watch_lock.tryLock()) std.atomic.spinLoopHint();
- l.watch_fds[0] = .{ .fd = l.control[0], .events = @intCast(libc.POLL.IN), .revents = 0 };
- l.watch_len = 1;
- if (l.quic) |*listener| {
- l.watch_fds[l.watch_len] = listener.poll();
- l.watch_len += 1;
- }
- l.watch_timeout = l.nextDue() orelse -1;
- l.watch_lock.unlock();
- _ = libc.write(l.control[1], "w", 1);
- }
-
- fn watchQuic(l: *Listener) void {
- var notified = false;
- while (!l.watch_stop.load(.acquire)) {
- var fds: [2]libc.pollfd = undefined;
- while (!l.watch_lock.tryLock()) std.atomic.spinLoopHint();
- const len = if (notified) 1 else l.watch_len;
- @memcpy(fds[0..len], l.watch_fds[0..len]);
- const timeout = if (notified) -1 else l.watch_timeout;
- l.watch_lock.unlock();
- const ready = libc.poll(&fds, @intCast(len), timeout);
- if (ready < 0) continue;
- if (fds[0].revents != 0) {
- var buf: [64]u8 = undefined;
- while (libc.read(l.control[0], &buf, buf.len) > 0) {}
- notified = false;
- continue;
- }
- if (!l.watch_stop.load(.acquire)) l.wake.?(l.wake_ctx);
- notified = true;
- }
}
/// Advertises this editor in the posted-9P registry so a
@@ -924,16 +697,6 @@ pub const Listener = struct {
pub fn deinit(l: *Listener, gpa: std.mem.Allocator) void {
l.stopping.store(true, .release);
l.unpostFromRegistry();
- if (l.watcher) |thread| {
- l.watch_stop.store(true, .release);
- _ = libc.write(l.control[1], "q", 1);
- thread.join();
- for (l.control) |fd| _ = libc.close(fd);
- }
- for (0..quic_slots) |i| l.drop(@intCast(i));
- if (comptime quic_enabled) {
- if (l.quic) |*listener| listener.deinit();
- }
if (comptime supported) {
// A connection task may be waiting for the turn; it answers
// nothing more once stopping, but the wait itself must end.
@@ -1159,7 +922,7 @@ pub fn socketPath(buf: *[sun_path_len]u8, dir: []const u8, name: []const u8) ?[:
/// Serves `core`. From here on the calling thread has the editor's turn
/// (`pardes.turn`) and must give it up while it waits.
-pub fn listen(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, named: []const u8, fallback: []const u8, tcp_dial: ?[]const u8, quic_dial: ?[]const u8) ?*Listener {
+pub fn listen(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, named: []const u8, fallback: []const u8, tcp_dial: ?[]const u8) ?*Listener {
if (comptime !supported) return null;
var dir_buf: [sun_path_len:0]u8 = undefined;
const dir = socketDir(&dir_buf) orelse {
@@ -1271,34 +1034,9 @@ pub fn listen(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, named: [
l.tcp_address = canonicalIp(bound);
log.info("serving 9P2000 over TCP on {f}", .{l.tcp_address.?});
}
- if (quic_dial) |dial| {
- if (comptime quic_enabled) {
- if (!std.mem.startsWith(u8, dial, "quic!")) {
- l.deinit(gpa);
- return null;
- }
- const address = networkAddress(dial, true) catch {
- log.warn("invalid QUIC address {s}", .{dial});
- l.deinit(gpa);
- return null;
- };
- l.quic = quic.Listener.init(address) catch |err| {
- log.warn("cannot listen on {s}: {s}", .{ dial, @errorName(err) });
- l.deinit(gpa);
- return null;
- };
- l.quic_address = l.quic.?.address;
- log.info("serving 9P2000 over QUIC on {f}", .{l.quic_address.?});
- } else {
- log.warn("QUIC is unavailable in this build", .{});
- l.deinit(gpa);
- return null;
- }
- }
log.info("serving 9P2000 on {s}", .{p});
core.fs.socket_path = l.path();
core.fs.tcp_address = l.tcp_address;
- core.fs.quic_address = l.quic_address;
return l;
}
@@ -1656,10 +1394,6 @@ test "one connection's buffers are sized from the one msize constant" {
try testing.expectEqual(@as(usize, msize), @typeInfo(@FieldType(Runner.Conn, "in")).array.len);
try testing.expectEqual(@as(usize, 2 * msize), @typeInfo(@FieldType(Runner.Conn, "out")).array.len);
try testing.expectEqual(@as(usize, max_conns), Runner.max_connections);
- if (quic_enabled) {
- const c: Conn = .{};
- try testing.expectEqual(@as(usize, msize), c.in.len);
- }
}
test "TCP addresses are numeric and normalize mapped IPv4" {
@@ -1681,9 +1415,7 @@ test "TCP addresses are numeric and normalize mapped IPv4" {
try testing.expectError(error.BadDial, Client.validateDial("unix!/tmp/a\x00b"));
try testing.expectError(error.BadDial, Client.validateDial("tcp!localhost!5640"));
try testing.expectError(error.BadDial, Client.validateDial("/tmp/a\x00b"));
- if (quic_enabled) {
- try Client.validateDial("quic!127.0.0.1!5640");
- } else try testing.expectError(error.QuicUnavailable, Client.validateDial("quic!127.0.0.1!5640"));
+ try testing.expectError(error.BadDial, Client.validateDial("quic!127.0.0.1!5640"));
}
extern "c" fn mkdtemp(template: [*:0]u8) ?[*:0]u8;
@@ -1712,7 +1444,7 @@ test "a socket path too long for sun_path is no listener, and leaves the editor'
_ = @import("host_io.zig").testUnsetenv("XDG_RUNTIME_DIR");
};
const long = &@as([120]u8, @splat('n'));
- try testing.expect(listen(testing.io, testing.allocator, p, long, "", null, null) == null);
+ try testing.expect(listen(testing.io, testing.allocator, p, long, "", null) == null);
try testing.expect(pardes.turn.answer_held == null);
try testing.expect(pardes.turn.wake_parked == null);
try testing.expect(pardes.turn.io == null);
@@ -1755,7 +1487,7 @@ test "a listening editor posts itself into the 9P registry and unposts on stop"
{
const p = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 });
defer p.deinit();
- const l = listen(testing.io, gpa, p, "unit", "", null, null) orelse return error.ListenFailed;
+ const l = listen(testing.io, gpa, p, "unit", "", null) orelse return error.ListenFailed;
defer l.deinit(gpa);
// The socket stays exactly where pardes has always bound it:
// adopting the registry moves nothing, it only advertises.
@@ -1789,7 +1521,7 @@ test "a listening editor posts itself into the 9P registry and unposts on stop"
try testing.expectEqual(Probe.none, lockState(sock));
}
-test "Unix TCP and QUIC share one listener through reads writes reconnects and reset" {
+test "Unix and TCP share one listener through reads writes reconnects and reset" {
if (comptime !supported) return error.SkipZigTest;
const gpa = testing.allocator;
var directory: [64:0]u8 = undefined;
@@ -1850,28 +1582,24 @@ test "Unix TCP and QUIC share one listener through reads writes reconnects and r
}
};
- const protocols: []const []const u8 = if (quic_enabled) &.{ "tcp", "quic" } else &.{"tcp"};
- for (protocols) |protocol| for ([_][]const u8{ "127.0.0.1", "::1" }) |host| {
+ for ([_][]const u8{ "127.0.0.1", "::1" }) |host| {
const p = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 });
defer p.deinit();
const pane = try p.setTestFile("initial\n");
while (p.nextEffect()) |_| {}
var bind_buf: [64]u8 = undefined;
- const bind = try std.fmt.bufPrint(&bind_buf, "{s}!{s}!0", .{ protocol, host });
- const tcp = std.mem.eql(u8, protocol, "tcp");
- const l = listen(testing.io, gpa, p, "roundtrip", "", if (tcp) bind else null, if (tcp) null else bind) orelse return error.ListenFailed;
+ const bind = try std.fmt.bufPrint(&bind_buf, "tcp!{s}!0", .{host});
+ const l = listen(testing.io, gpa, p, "roundtrip", "", bind) orelse return error.ListenFailed;
defer {
l.reset(p);
l.deinit(gpa);
}
try testing.expect(l.path().len != 0);
- try testing.expectEqual(tcp, l.tcp_address != null);
try testing.expectEqual(@as(usize, max_conns), l.runner.conns.len);
- try testing.expect(l.watcher == null);
- const port = (if (tcp) l.tcp_address else l.quic_address).?.getPort();
+ const port = l.tcp_address.?.getPort();
try testing.expect(port != 0);
var dial_buf: [64]u8 = undefined;
- const network_dial = try std.fmt.bufPrint(&dial_buf, "{s}!{s}!{d}", .{ protocol, host, port });
+ const network_dial = try std.fmt.bufPrint(&dial_buf, "tcp!{s}!{d}", .{ host, port });
var body_buf: [64]u8 = undefined;
const body = try std.fmt.bufPrint(&body_buf, "/pane/{d}/body", .{pane.serial});
for ([_][]const u8{ network_dial, l.path(), network_dial }, 0..) |dial, attempt| {
@@ -1882,14 +1610,7 @@ test "Unix TCP and QUIC share one listener through reads writes reconnects and r
// answered on the runner's tasks, not by this thread.
const deadline = Client.nowMs() + 3 * Client.budget_ms;
pardes.turn.rest();
- while (!worker.done.load(.acquire) and Client.nowMs() < deadline) {
- if (quic_enabled) {
- pardes.turn.wake();
- _ = l.tick();
- pardes.turn.rest();
- }
- Client.nap(1);
- }
+ while (!worker.done.load(.acquire) and Client.nowMs() < deadline) Client.nap(1);
// The client has hung up, but its connection's task may not have
// seen that yet. The releases it then owes are refused once
// `reset` starts cutting (they name the old editor's opens), and
@@ -1904,10 +1625,9 @@ test "Unix TCP and QUIC share one listener through reads writes reconnects and r
try testing.expectEqual(@as(usize, 0), l.runner.count());
l.reset(p);
try testing.expectEqual(@as(usize, 0), l.runner.count());
- for (&l.conns, 0..) |conn, i| try testing.expect(!l.live(@intCast(i)) and !conn.draining);
for (p.fs.opens) |o| try testing.expect(o.node == 0);
}
- };
+ }
}
test "a change waits while the editor is out mid-step, a read does not, and the change lands when the editor rests" {
@@ -1932,7 +1652,7 @@ test "a change waits while the editor is out mid-step, a read does not, and the
const pane = try p.setTestFile("before\n");
while (p.nextEffect()) |_| {}
// This thread is the editor's: it has the turn from here on.
- const l = listen(testing.io, gpa, p, "park", "", null, null) orelse return error.ListenFailed;
+ const l = listen(testing.io, gpa, p, "park", "", null) orelse return error.ListenFailed;
defer {
l.reset(p);
l.deinit(gpa);
@@ -2008,7 +1728,7 @@ test "a mount's connection is kept between operations, and one the peer hung up
defer p.deinit();
const pane = try p.setTestFile("before\n");
while (p.nextEffect()) |_| {}
- const l = listen(testing.io, gpa, p, "kept", "", null, null) orelse return error.ListenFailed;
+ const l = listen(testing.io, gpa, p, "kept", "", null) orelse return error.ListenFailed;
defer {
l.reset(p);
l.deinit(gpa);
@@ -2096,7 +1816,7 @@ test "a held read is answered when the log has news, and a flushed one spends no
_ = try p.setTestFile("held\n");
p.update(.tick); // the pane is logged, before the log is opened
while (p.nextEffect()) |_| {}
- const l = listen(testing.io, gpa, p, "held", "", null, null) orelse return error.ListenFailed;
+ const l = listen(testing.io, gpa, p, "held", "", null) orelse return error.ListenFailed;
defer {
l.reset(p);
l.deinit(gpa);
@@ -2232,7 +1952,7 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes) ?*Listene
var name: [16]u8 = undefined;
// unreachable: a u32 is at most 10 digits
const fallback = std.fmt.bufPrint(&name, "{d}", .{@as(u32, @intCast(libc.getpid()))}) catch unreachable;
- return listen(io, gpa, core, core.opts.ninep_name, fallback, core.opts.ninep_tcp, core.opts.ninep_quic) orelse {
+ return listen(io, gpa, core, core.opts.ninep_name, fallback, core.opts.ninep_tcp) orelse {
core.reportError(0, "9p listener", error.ListenFailed);
return null;
};
@@ -2386,7 +2106,7 @@ pub const Client = struct {
const uname = "pardes";
- const Dial = union(enum) { unix: [:0]const u8, tcp: std.Io.net.IpAddress, quic: std.Io.net.IpAddress };
+ const Dial = union(enum) { unix: [:0]const u8, tcp: std.Io.net.IpAddress };
pub const Error = error{
PathTooDeep,
@@ -2399,7 +2119,6 @@ pub const Client = struct {
IsDirectory,
NotFound,
FileTooLarge,
- QuicUnavailable,
};
pub fn read(gpa: std.mem.Allocator, dial: []const u8, path: []const u8, display_path: []const u8) ![]u8 {
@@ -2500,13 +2219,9 @@ pub const Client = struct {
return n;
}
- fn resolve(buf: *[sun_path_len]u8, dial: []const u8) error{ BadDial, QuicUnavailable }!Dial {
+ fn resolve(buf: *[sun_path_len]u8, dial: []const u8) error{BadDial}!Dial {
if (dial.len == 0) return error.BadDial;
if (std.mem.startsWith(u8, dial, "tcp!")) return .{ .tcp = try networkAddress(dial, false) };
- if (std.mem.startsWith(u8, dial, "quic!")) {
- if (comptime !quic_enabled) return error.QuicUnavailable;
- return .{ .quic = try networkAddress(dial, false) };
- }
const explicit_unix = std.mem.startsWith(u8, dial, "unix!");
// A network this does not dial (`nowhere!x`) is a malformed address,
// not a session named so.
@@ -2525,14 +2240,13 @@ pub const Client = struct {
return .{ .unix = socketPath(buf, dir, dial) orelse return error.BadDial };
}
- pub fn validateDial(dial: []const u8) error{ BadDial, QuicUnavailable }!void {
+ pub fn validateDial(dial: []const u8) error{BadDial}!void {
var buf: [sun_path_len]u8 = undefined;
_ = try resolve(&buf, dial);
}
const Session = struct {
fd: c_int,
- quic: if (quic_enabled) ?quic.Connection else void = if (quic_enabled) null else {},
deadline: i64,
display_path: []const u8,
cl: ninep.Client = undefined,
@@ -2553,46 +2267,17 @@ pub const Client = struct {
dial_len: usize = 0,
fn wait(s: *Session, events: i16) Error!void {
- while (true) {
- const left = s.deadline - nowMs();
- if (left <= 0) return Error.Timeout;
- if (comptime quic_enabled) {
- if (s.quic) |*connection| {
- var fds = [1]libc.pollfd{connection.poll().?};
- const timeout = @min(left, connection.nextDue() orelse budget_ms);
- const ready = libc.poll(&fds, 1, @intCast(timeout));
- if (ready < 0) {
- if (libc.errno(ready) == .INTR) continue;
- return Error.Hangup;
- }
- if (nowMs() >= s.deadline) return Error.Timeout;
- if (fds[0].revents & @as(i16, @intCast(libc.POLL.NVAL)) != 0) return Error.Hangup;
- connection.events() catch return Error.Hangup;
- return;
- }
- }
- return transport.wait(s.fd, events, s.deadline) catch |err| switch (err) {
- error.Timeout => Error.Timeout,
- else => Error.Hangup,
- };
- }
+ if (s.deadline - nowMs() <= 0) return Error.Timeout;
+ return transport.wait(s.fd, events, s.deadline) catch |err| switch (err) {
+ error.Timeout => Error.Timeout,
+ else => Error.Hangup,
+ };
}
fn flush(s: *Session) Error!void {
while (s.cl.output().len != 0) {
if (nowMs() >= s.deadline) return Error.Timeout;
const bytes = s.cl.output();
- if (comptime quic_enabled) {
- if (s.quic) |*connection| {
- const sent = connection.write(bytes) catch return Error.Hangup;
- if (sent == 0) {
- try s.wait(poll_out);
- continue;
- }
- s.cl.wrote(sent);
- continue;
- }
- }
try s.wait(poll_out);
const sent = (transport.write(s.fd, bytes) catch return Error.Hangup) orelse continue;
s.cl.wrote(@intCast(sent));
@@ -2613,18 +2298,6 @@ pub const Client = struct {
if (s.cl.dead) return Error.Botch;
const room = s.cl.in.len - s.cl.in_len;
if (room == 0) return Error.Botch;
- if (comptime quic_enabled) {
- if (s.quic) |*connection| {
- const got = (connection.read(s.stage[0..@min(room, s.stage.len)]) catch return Error.Hangup) orelse {
- try s.wait(poll_in);
- continue;
- };
- if (got == 0) return Error.Hangup;
- const n = s.cl.push(s.stage[0..got]);
- std.debug.assert(n == got);
- continue;
- }
- }
try s.wait(poll_in);
const got = (transport.read(s.fd, s.stage[0..@min(room, s.stage.len)]) catch return Error.Hangup) orelse continue;
if (got == 0) return Error.Hangup;
@@ -3085,12 +2758,7 @@ pub const Client = struct {
const s = try std.heap.page_allocator.create(Session);
s.* = .{ .fd = -1, .deadline = deadline, .display_path = display_path };
errdefer endSession(s, false);
- if (sock == .quic) {
- if (comptime quic_enabled) {
- s.quic = quic.Connection.dial(sock.quic) catch return Error.Dial;
- s.fd = s.quic.?.fd;
- } else return Error.QuicUnavailable;
- } else s.fd = try connect(sock, deadline);
+ s.fd = try connect(sock, deadline);
s.cl = .init(.{ .in = &s.in, .out = &s.out });
if (dial.len <= s.dial_buf.len) {
@memcpy(s.dial_buf[0..dial.len], dial);
@@ -3100,10 +2768,8 @@ pub const Client = struct {
}
fn endSession(s: *Session, keep: bool) void {
- if (keep and s.attached and s.dial_len != 0 and !(quic_enabled and s.quic != null) and kept.put(s)) return;
- if (quic_enabled and s.quic != null) {
- s.quic.?.deinit();
- } else if (s.fd >= 0) _ = libc.close(s.fd);
+ if (keep and s.attached and s.dial_len != 0 and kept.put(s)) return;
+ if (s.fd >= 0) _ = libc.close(s.fd);
std.heap.page_allocator.destroy(s);
}
@@ -3250,7 +2916,6 @@ pub const Client = struct {
const address: transport.Address = switch (sock) {
.unix => |path| .{ .unix = path },
.tcp => |ip| .{ .tcp = ip },
- .quic => return Error.QuicUnavailable,
};
return transport.connectFd(address, deadline) catch return Error.Dial;
}
@@ -3315,10 +2980,8 @@ pub const Client = struct {
}
test "one fetch has three msize buffers and bounded transport metadata" {
- const transport_bytes = if (quic_enabled) @sizeOf(?quic.Connection) else 0;
try testing.expectEqual(@as(usize, msize), @as(usize, (Session{ .fd = -1, .deadline = 0, .display_path = "" }).in.len));
- try testing.expect(transport_bytes <= 64);
- try testing.expect(@sizeOf(Session) <= 3 * msize + @sizeOf(ninep.Client) + 128 + @sizeOf(@FieldType(Session, "dial_buf")) + transport_bytes);
+ try testing.expect(@sizeOf(Session) <= 3 * msize + @sizeOf(ninep.Client) + 128 + @sizeOf(@FieldType(Session, "dial_buf")));
try testing.expect(@sizeOf(ninep.Client) <= 512);
}