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.
This commit is contained in:
Andrew Kelley 2025-02-18 23:30:46 -08:00
parent a500651370
commit 8464efa5dd

View File

@ -6092,17 +6092,13 @@ pub const SendError = error{
pub const SendMsgError = SendError || error{
/// The passed address didn't have the correct address family in its sa_family field.
AddressFamilyNotSupported,
/// Returned when socket is AF.UNIX and the given path has a symlink loop.
SymLinkLoop,
/// Returned when socket is AF.UNIX and the given path length exceeds `max_path_bytes` bytes.
NameTooLong,
/// Returned when socket is AF.UNIX and the given path does not point to an existing file.
FileNotFound,
NotDir,
/// The socket is not connected (connection-oriented sockets only).
SocketNotConnected,
AddressNotAvailable,
@ -6400,14 +6396,7 @@ pub fn sendfile(
.SUCCESS => {
const amt: usize = @bitCast(rc);
total_written += amt;
if (in_len == 0 and amt == 0) {
// We have detected EOF from `in_fd`.
break;
} else if (amt < in_len) {
return total_written;
} else {
break;
}
return total_written;
},
.BADF => unreachable, // Always a race condition.