os: fix sendfile for macos

In python, `count` in `sendfile` doesn't include nbytes in headers or trailers.
But in `nix::sys::sendfile::sendfile` does.

From nix doc,
```
If any headers are specified and `count` is non-zero,
the length of the headers will be counted in the limit of total bytes sent.
```
This commit is contained in:
Dean Li
2021-08-14 00:17:15 +08:00
parent 8f4719222c
commit 3bb4e5d808

View File

@@ -579,6 +579,11 @@ mod _os {
#[pyfunction]
fn sendfile(args: SendFileArgs, vm: &VirtualMachine) -> PyResult {
let headers = _extract_vec_bytes(args.headers, vm)?;
let count = headers
.as_ref()
.map(|v| v.iter().map(|s| s.len()).sum())
.unwrap_or(0) as i64
+ args.count;
let headers = headers
.as_ref()
@@ -602,7 +607,7 @@ mod _os {
args.in_fd,
args.out_fd,
args.offset,
Some(args.count),
Some(count),
headers,
trailers,
);