| ... | @@ -3734,7 +3734,8 @@ pub fn sendfile( | ... | @@ -3734,7 +3734,8 @@ pub fn sendfile( |
| 3734 | | 3734 | |
| 3735 | while (true) { | 3735 | while (true) { |
| 3736 | var sbytes: off_t = undefined; | 3736 | var sbytes: off_t = undefined; |
| 3737 | const err = errno(system.sendfile(out_fd, in_fd, in_offset, adjusted_count, hdtr, &sbytes, flags)); | 3737 | const offset = @bitCast(off_t, in_offset); |
| | 3738 | const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags)); |
| 3738 | const amt = @bitCast(usize, sbytes); | 3739 | const amt = @bitCast(usize, sbytes); |
| 3739 | switch (err) { | 3740 | switch (err) { |
| 3740 | 0 => return amt, | 3741 | 0 => return amt, |
| ... | @@ -3813,19 +3814,17 @@ pub fn sendfile( | ... | @@ -3813,19 +3814,17 @@ pub fn sendfile( |
| 3813 | while (true) { | 3814 | while (true) { |
| 3814 | var sbytes: off_t = adjusted_count; | 3815 | var sbytes: off_t = adjusted_count; |
| 3815 | const signed_offset = @bitCast(i64, in_offset); | 3816 | const signed_offset = @bitCast(i64, in_offset); |
| 3816 | const err = errno(system.sendfile(out_fd, in_fd, signed_offset, &sbytes, hdtr, flags)); | 3817 | const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags)); |
| 3817 | const amt = @bitCast(usize, sbytes); | 3818 | const amt = @bitCast(usize, sbytes); |
| 3818 | switch (err) { | 3819 | switch (err) { |
| 3819 | 0 => return amt, | 3820 | 0 => return amt, |
| 3820 | | 3821 | |
| | 3822 | EBADF => unreachable, // Always a race condition. |
| 3821 | EFAULT => unreachable, // Segmentation fault. | 3823 | EFAULT => unreachable, // Segmentation fault. |
| 3822 | EINVAL => unreachable, | 3824 | EINVAL => unreachable, |
| 3823 | ENOTCONN => unreachable, // `out_fd` is an unconnected socket. | 3825 | ENOTCONN => unreachable, // `out_fd` is an unconnected socket. |
| 3824 | | 3826 | |
| 3825 | // On macOS version 10.14.6, I observed Darwin return EBADF when | 3827 | ENOTSUP, ENOTSOCK, ENOSYS => break :sf, |
| 3826 | // using sendfile on a valid open file descriptor of a file | | |
| 3827 | // system file. | | |
| 3828 | ENOTSUP, ENOTSOCK, ENOSYS, EBADF => break :sf, | | |
| 3829 | | 3828 | |
| 3830 | EINTR => if (amt != 0) return amt else continue, | 3829 | EINTR => if (amt != 0) return amt else continue, |
| 3831 | | 3830 | |