]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/basic/copy.c
basic/copy: use sendfile smarter
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Mar 2016 00:15:21 +0000 (20:15 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Mar 2016 18:54:27 +0000 (14:54 -0400)
commit00a8cf7763ec5e132efd4c974fbc6530c82240d0
treef03f8725f75ac6cce03f4b073adb04e2ee522998
parentce33fddad0806f859ff7324527ee0525dd10455e
basic/copy: use sendfile smarter

We called sendfile with 16kb (a.k.a. COPY_BUFFER_SIZE) as the maximum
number of bytes to copy. This seems rather inefficient, especially with
large files. Instead, call sendfile with a "large" maximum.

What "large" max means is a bit tricky: current file offset + max
must fit in loff_t. This means that as we call sendfile more than once,
we have to lower the max size.

With this patch, test-copy calls sendfile twice, e.g.:
sendfile(4, 3, NULL, 9223372036854775807) = 738760
sendfile(4, 3, NULL, 9223372036854037047) = 0
The second call is necessary to determine EOF.
src/basic/copy.c