]> git.sesse.net Git - betaftpd/commitdiff
Added FreeBSD support for sendfile() (thanks to <liangyi@netchina.com.cn>), and updat...
authorsgunderson <sgunderson>
Sat, 10 Mar 2001 14:46:06 +0000 (14:46 +0000)
committersgunderson <sgunderson>
Sat, 10 Mar 2001 14:46:06 +0000 (14:46 +0000)
doc/CREDITS
ftpd.c
ftpd.h

index 6c12e2ed89cef8400fa7aa89a4ef959804864ba1..2126946cf16488bbcb9b3bc6e6b74ef0ec1fe44d 100644 (file)
@@ -28,6 +28,10 @@ St
   network-wise, as well as assisting in testing, which led to
   BetaFTPD running properly on FreeBSD for the first time.
 
+Unknown <liangyi@netchina.com.cn>
+- Made the FreeBSD support for sendfile(), as well as did other
+  things (like testing and profiling) for the FreeBSD port.
+
 In addition, there are numerous users who by themselves may have
 done very little, but together have been the driving force behind
 the BetaFTPD development. To all of you who have ever sent in
diff --git a/ftpd.c b/ftpd.c
index 5208bf71386935db7ea70efd589dbdedcde658fd..2a84a715062c80c93f2d28cb93a976f95bc70a7b 100644 (file)
--- a/ftpd.c
+++ b/ftpd.c
@@ -202,7 +202,7 @@ fd_set master_fds, master_send_fds;
 FILE *xferlog = NULL;
 #endif
 
-#if HAVE_LINUX_SENDFILE
+#if HAVE_LINUX_SENDFILE || HAVE_BSD_SENDFILE
 int sendfile_supported = 1;
 #endif
 
@@ -768,7 +768,7 @@ int do_download(struct ftran *f)
 #endif
        int size;
 
-#if HAVE_LINUX_SENDFILE
+#if HAVE_LINUX_SENDFILE || HAVE_BSD_SENDFILE
        /*
         * We handle the optimal case first, which is sendfile().
         * Here we use a rather simplified sending `algorithm',
@@ -787,7 +787,7 @@ int do_download(struct ftran *f)
                }       
 #endif
 
-                       err = sendfile(f->sock, f->local_file, &f->pos, size);
+                       err = mysendfile(f->sock, f->local_file, &f->pos, size);
                return (f->pos < f->size) && (err > -1);
        }
 #endif
@@ -981,7 +981,7 @@ int main(void)
        alarm(60);
        signal(SIGALRM, handle_alarm);
 
-#if HAVE_LINUX_SENDFILE
+#if HAVE_LINUX_SENDFILE || HAVE_BSD_SENDFILE
        /* check that sendfile() is really implemented (same check as configure does) */
        {
                int out_fd = 1, in_fd = 0;
@@ -989,7 +989,7 @@ int main(void)
                size_t size = 1024;
 
                errno = 0;
-               sendfile(out_fd, in_fd, &offset, size);
+               mysendfile(out_fd, in_fd, &offset, size);
                if (errno == ENOSYS) sendfile_supported = 0;
        }
 #endif
@@ -1346,7 +1346,7 @@ void init_file_transfer(struct ftran * const f)
         */
 #if HAVE_MMAP
        if (f->dir_listing == 0) {
-#if HAVE_LINUX_SENDFILE
+#if HAVE_LINUX_SENDFILE || HAVE_BSD_SENDFILE
                int do_mmap = (sendfile_supported) ? 0 : 1;
 #else
                int do_mmap = 1;
@@ -1489,6 +1489,24 @@ void clear_bad_fds(int * const server_sock)
 }
 #endif
 
+#if HAVE_BSD_SENDFILE || HAVE_LINUX_SENDFILE
+int mysendfile(int sock, int fd, off_t *offset, size_t count)
+{
+#if HAVE_BSD_SENDFILE
+       int err;
+       off_t ssize = 0;
+       
+       err = sendfile(fd, sock, *offset, count, NULL, &ssize, 0);
+       if (ssize > 0) *offset += ssize;
+#else /* !HAVE_BSD_SENDFILE */
+#if HAVE_LINUX_SENDFILE
+       return sendfile(sock, fd, offset, count);
+#endif /* HAVE_LINUX_SENDFILE */
+#endif /* !HAVE_BSD_SENDFILE */
+}
+#endif /* HAVE_BSD_SENDFILE || HAVE_LINUX_SENDFILE */
+
+
 #if WANT_MESSAGE
 /*
  * dump_file(): Dumps a file on the control connection. Used for
diff --git a/ftpd.h b/ftpd.h
index e85ced495f36a993ef62de7903cacae9159d16b1..7a165dce05e7c5cb3182af297d406e323264c47f 100644 (file)
--- a/ftpd.h
+++ b/ftpd.h
@@ -213,6 +213,10 @@ int create_server_socket();
 void clear_bad_fds(int * const server_sock);
 #endif
 
+#if HAVE_BSD_SENDFILE || HAVE_LINUX_SENDFILE
+int mysendfile(int sock, int fd, off_t *offset, size_t count);
+#endif 
+
 #if WANT_MESSAGE
 void dump_file(struct conn * const c, const int num, const char * const filename);
 void list_readmes(struct conn * const c);