From 3bb4e5d8080d0ee6795f1540153ad040ec37ae9c Mon Sep 17 00:00:00 2001 From: Dean Li Date: Sat, 14 Aug 2021 00:17:15 +0800 Subject: [PATCH] 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. ``` --- vm/src/stdlib/os.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 6550b8657..b62a25209 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -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, );