# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
# some C compilers supported these specifiers prior to C99 as an extension.
#
+# Define HAVE_LINUX_SENDFILE to use sendfile()
#-include config.mak
*
*/
+#ifdef HAVE_LINUX_SENDFILE
+#include <sys/sendfile.h>
+#endif
#include "cgit.h"
#include "cache.h"
#include "html.h"
const char *lock_name;
int match;
struct stat cache_st;
- struct stat lock_st;
int bufsize;
char buf[CACHE_BUFSIZE];
};
/* Print the content of the active cache slot (but skip the key). */
static int print_slot(struct cache_slot *slot)
{
+#ifdef HAVE_LINUX_SENDFILE
+ off_t start_off;
+ int ret;
+
+ start_off = slot->keylen + 1;
+
+ do {
+ ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off,
+ slot->cache_st.st_size - start_off);
+ if (ret < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
+ return errno;
+ }
+ return 0;
+ } while (1);
+#else
ssize_t i, j;
i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET);
return errno;
else
return 0;
+#endif
}
/* Check if the slot has expired */
/* Generate cache content */
slot->fn();
+ /* update stat info */
+ if (fstat(slot->lock_fd, &slot->cache_st))
+ return errno;
+
/* Restore stdout */
if (dup2(tmp, STDOUT_FILENO) == -1)
return errno;
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