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{...@@ -6092,17 +6092,13 @@ pub const SendError = error{
6092pub const SendMsgError = SendError || error{6092pub const SendMsgError = SendError || error{
6093 /// The passed address didn't have the correct address family in its sa_family field.6093 /// The passed address didn't have the correct address family in its sa_family field.
6094 AddressFamilyNotSupported,6094 AddressFamilyNotSupported,
6095
6096 /// Returned when socket is AF.UNIX and the given path has a symlink loop.6095 /// Returned when socket is AF.UNIX and the given path has a symlink loop.
6097 SymLinkLoop,6096 SymLinkLoop,
6098
6099 /// Returned when socket is AF.UNIX and the given path length exceeds `max_path_bytes` bytes.6097 /// Returned when socket is AF.UNIX and the given path length exceeds `max_path_bytes` bytes.
6100 NameTooLong,6098 NameTooLong,
6101
6102 /// Returned when socket is AF.UNIX and the given path does not point to an existing file.6099 /// Returned when socket is AF.UNIX and the given path does not point to an existing file.
6103 FileNotFound,6100 FileNotFound,
6104 NotDir,6101 NotDir,
6105
6106 /// The socket is not connected (connection-oriented sockets only).6102 /// The socket is not connected (connection-oriented sockets only).
6107 SocketNotConnected,6103 SocketNotConnected,
6108 AddressNotAvailable,6104 AddressNotAvailable,
...@@ -6400,14 +6396,7 @@ pub fn sendfile(...@@ -6400,14 +6396,7 @@ pub fn sendfile(
6400 .SUCCESS => {6396 .SUCCESS => {
6401 const amt: usize = @bitCast(rc);6397 const amt: usize = @bitCast(rc);
6402 total_written += amt;6398 total_written += amt;
6403 if (in_len == 0 and amt == 0) {6399 return total_written;
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 }
6411 },6400 },
64126401
6413 .BADF => unreachable, // Always a race condition.6402 .BADF => unreachable, // Always a race condition.