From eb34b31bb76c14523945b890f3312977a7a81831 Mon Sep 17 00:00:00 2001 From: robin Date: Sat, 15 Aug 2026 13:25:33 +0200 Subject: [PATCH] helpers: use `std.c.sendfile` Co-authored-by: june --- src/helpers.zig | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/helpers.zig b/src/helpers.zig index 2df6415..46489e4 100644 --- a/src/helpers.zig +++ b/src/helpers.zig @@ -76,13 +76,14 @@ pub fn sendfile(conn: Handler.Connection, dir: std.Io.Dir, path: []const u8) !vo var offset: i64 = 0; while (remaining > 0) { const count: usize = @intCast(@min(remaining, 0x7ffff000)); // ~2GiB - const ret: isize = @intCast(std.os.linux.sendfile(conn.handle, file.handle, &offset, count)); + const ret = std.c.sendfile(conn.handle, file.handle, &offset, count); defer remaining -= @intCast(ret); - switch (ret) { - 0 => return error.UnexpectedEndOfFile, - -1 => return error.SendFileFailed, - else => {}, - } + if (ret == -1) { + const errno = std.c.errno(ret); + if (errno == .AGAIN or errno == .INTR) continue; + return error.SendFileFailed; + } else if (ret == 0) + return error.UnexpectedEndOfFile; } b.state = .end; -- 2.51.2