#include <linux/socket.h>
#endif
+#if HAVE_LINUX_TCP_H
+#include <linux/tcp.h>
+#endif
+
#if HAVE_MMAP
#include <sys/mman.h>
#endif
FILE *xferlog = NULL;
#endif
+#if HAVE_LINUX_SENDFILE
+int sendfile_supported = 1;
+#endif
+
/*
* This variable specifies if it's soon time to check for timed out
* clients, and timed out directory listing cache entries. It is
* Here we use a rather simplified sending `algorithm',
* leaving most of the quirks to the system calls.
*/
- if (f->dir_listing == 0) {
+ if (sendfile_supported == 1 && f->dir_listing == 0) {
int err;
size = f->size - f->pos;
alarm(60);
signal(SIGALRM, handle_alarm);
+#if HAVE_LINUX_SENDFILE
+ /* check that sendfile() is really implemented (same check as configure does) */
+ {
+ int out_fd = 1, in_fd = 0;
+ off_t offset = 0;
+ size_t size = 1024;
+
+ errno = 0;
+ sendfile(out_fd, in_fd, &offset, size);
+ if (errno == ENOSYS) sendfile_supported = 0;
+ }
+#endif
+
for ( ;; ) {
int i;
#ifndef HAVE_POLL
#if HAVE_MMAP
if (f->dir_listing == 0) {
#if HAVE_LINUX_SENDFILE
- int do_mmap = 0;
+ int do_mmap = (sendfile_supported) ? 0 : 1;
#else
int do_mmap = 1;
#endif