authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-18 23:30:46-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:26-07:00
log8464efa5dd792de25ee8faa413c89f1daf8b5efb
tree4f442e36625e6798de96556174a6138dd7f4bf2a
parenta500651370b3ca60f0fe8fba67d0124f136f0ec0

std.posix.sendfile: don't write trailers on linux

After sending the file, better to return total bytes written. The caller will decide if they want to do another syscall with the trailers. Maybe the caller would rather buffer them.

1 files changed, 1 insertions(+), 12 deletions(-)

lib/std/posix.zig+1-12
......@@ -6092,17 +6092,13 @@ pub const SendError = error{
60926092pub const SendMsgError = SendError || error{
60936093 /// The passed address didn't have the correct address family in its sa_family field.
60946094 AddressFamilyNotSupported,
6095
60966095 /// Returned when socket is AF.UNIX and the given path has a symlink loop.
60976096 SymLinkLoop,
6098
60996097 /// Returned when socket is AF.UNIX and the given path length exceeds `max_path_bytes` bytes.
61006098 NameTooLong,
6101
61026099 /// Returned when socket is AF.UNIX and the given path does not point to an existing file.
61036100 FileNotFound,
61046101 NotDir,
6105
61066102 /// The socket is not connected (connection-oriented sockets only).
61076103 SocketNotConnected,
61086104 AddressNotAvailable,
......@@ -6400,14 +6396,7 @@ pub fn sendfile(
64006396 .SUCCESS => {
64016397 const amt: usize = @bitCast(rc);
64026398 total_written += amt;
6403 if (in_len == 0 and amt == 0) {
6404 // We have detected EOF from `in_fd`.
6405 break;
6406 } else if (amt < in_len) {
6407 return total_written;
6408 } else {
6409 break;
6410 }
6399 return total_written;
64116400 },
64126401
64136402 .BADF => unreachable, // Always a race condition.