cache: use sendfile() instead of a pair of read() + write()

sendfile() does the same job and avoids to copy the content into userland
and back. One has to define NO_SENDFILE in case the OS (kernel / libc)
does not supported. It is disabled by default on non-linux environemnts.
According to the glibc, sendfile64() was added in Linux 2.4 (so it has
been there for a while) but after browsing over the mapage of FreeBSD's I
noticed that the prototype is little different.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
This commit is contained in:
Sebastian Andrzej Siewior
2014-01-18 21:24:58 +01:00
committed by Jason A. Donenfeld
parent ea7210bef3
commit d3581b5889
3 changed files with 34 additions and 1 deletions

View File

@ -68,6 +68,14 @@ ifeq ($(findstring BSD,$(uname_S)),)
CGIT_LIBS += -ldl
endif
# glibc 2.1+ offers sendfile which the most common C library on Linux
ifeq ($(uname_S),Linux)
HAVE_LINUX_SENDFILE = YesPlease
endif
ifdef HAVE_LINUX_SENDFILE
CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE
endif
CGIT_OBJ_NAMES += cgit.o
CGIT_OBJ_NAMES += cache.o