X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ftpd.c;h=b35a9a04b1509d638204dd34061ba87c41420a6f;hb=9e83a47a9d9bd9a8020a80393e1f0e03bb34efe7;hp=637469b9a2b4c98cc41220cf4fbe9209c5d45ec9;hpb=84aa46cb6489dcd731776eb9e4a91943b8bc6d92;p=betaftpd diff --git a/ftpd.c b/ftpd.c index 637469b..b35a9a0 100644 --- a/ftpd.c +++ b/ftpd.c @@ -112,6 +112,10 @@ #include #endif +#if HAVE_LINUX_TCP_H +#include +#endif + #if HAVE_MMAP #include #endif @@ -198,6 +202,10 @@ fd_set master_fds, master_send_fds; 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 @@ -790,7 +798,7 @@ int do_download(struct ftran *f) * 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; @@ -997,6 +1005,19 @@ int main(void) 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 @@ -1373,7 +1394,7 @@ void init_file_transfer(struct ftran * const f) #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