X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Fadouble%2Fad_sendfile.c;h=2cc9a1f4470f8e75fe7b35b3fd1b6da52f6aec23;hb=7b12c56c26d0ce7ef5834c71d3c8bcc90fef2532;hp=42971911f5beb4bedcb42482df89fa3d935f385e;hpb=ecfc96169ab669b578e53fa8e13592934fe37788;p=netatalk.git diff --git a/libatalk/adouble/ad_sendfile.c b/libatalk/adouble/ad_sendfile.c index 42971911..2cc9a1f4 100644 --- a/libatalk/adouble/ad_sendfile.c +++ b/libatalk/adouble/ad_sendfile.c @@ -1,5 +1,5 @@ /* - * $Id: ad_sendfile.c,v 1.8 2005-04-28 20:49:52 bfernhomberg Exp $ + * $Id: ad_sendfile.c,v 1.11 2010-01-21 14:14:49 didg Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * All rights reserved. See COPYRIGHT. @@ -43,7 +43,6 @@ #include #include - #include "ad_private.h" #if defined(LINUX_BROKEN_SENDFILE_API) @@ -52,8 +51,9 @@ extern int32_t sendfile (int fdout, int fdin, int32_t *offset, u_int32_t count); ssize_t sys_sendfile(int tofd, int fromfd, off_t *offset, size_t count) { -u_int32_t small_total = 0; +u_int32_t small_total; int32_t small_offset; +int32_t nwritten; /* * Fix for broken Linux 2.4 systems with no working sendfile64(). @@ -66,22 +66,13 @@ int32_t small_offset; errno = ENOSYS; return -1; } - small_total = (u_int32_t)count; small_offset = (int32_t)*offset; - - while (small_total) { - int32_t nwritten; - do { - nwritten = sendfile(tofd, fromfd, &small_offset, small_total); - } while (nwritten == -1 && errno == EINTR); - if (nwritten == -1) - return -1; - if (nwritten == 0) - return -1; /* I think we're at EOF here... */ - small_total -= nwritten; - } - *offset += count; - return count; + small_total = (u_int32_t)count; + nwritten = sendfile(tofd, fromfd, &small_offset, small_total); + if (nwritten > = 0) + *offset += nwritten; + + return nwritten; } #elif defined(SENDFILE_FLAVOR_LINUX) @@ -89,26 +80,12 @@ int32_t small_offset; ssize_t sys_sendfile(int tofd, int fromfd, off_t *offset, size_t count) { -size_t total=0; - - total = count; - while (total) { - ssize_t nwritten; - do { - nwritten = sendfile(tofd, fromfd, offset, total); - } while (nwritten == -1 && errno == EINTR); - if (nwritten == -1) - return -1; - if (nwritten == 0) - return -1; /* I think we're at EOF here... */ - total -= nwritten; - } - return count; + return sendfile(tofd, fromfd, offset, count); } - #elif defined(SENDFILE_FLAVOR_BSD ) /* FIXME untested */ +#error sendfile semantic broken #include ssize_t sys_sendfile(int tofd, int fromfd, off_t *offset, size_t count) { @@ -140,7 +117,7 @@ ssize_t sys_sendfile(int out_fd, int in_fd, off_t *_offset, size_t count) #endif /* ------------------------------- */ -static __inline__ int ad_sendfile_init(const struct adouble *ad, +int ad_readfile_init(const struct adouble *ad, const int eid, off_t *off, const int end) { @@ -150,30 +127,16 @@ static __inline__ int ad_sendfile_init(const struct adouble *ad, *off = ad_size(ad, eid) - *off; if (eid == ADEID_DFORK) { - fd = ad_dfileno(ad); + fd = ad_data_fileno(ad); } else { *off += ad_getentryoff(ad, eid); - fd = ad_hfileno(ad); + fd = ad_reso_fileno(ad); } return fd; } -/* -------------------------------- - * read from adouble file and write to socket. sendfile doesn't change - * the file pointer position. */ -ssize_t ad_readfile(const struct adouble *ad, const int eid, - const int sock, off_t off, const size_t len) -{ - off_t cc; - int fd; - - fd = ad_sendfile_init(ad, eid, &off, 0); - cc = sys_sendfile(sock, fd, &off, len); - return cc; -} - /* ------------------------ */ #if 0 #ifdef HAVE_SENDFILE_WRITE