2 * $Id: ad_sendfile.c,v 1.4 2002-01-04 04:45:48 sibaz Exp $
4 * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
5 * All rights reserved. See COPYRIGHT.
7 * NOTE: the following uses the fact that sendfile() only exists on
8 * machines with SA_RESTART behaviour. this is all very machine specific.
15 #endif /* HAVE_CONFIG_H */
20 #endif /* HAVE_UNISTD_H */
21 #include <sys/types.h>
23 #include <sys/socket.h>
26 #include <atalk/adouble.h>
28 #include <atalk/logger.h>
30 #include "ad_private.h"
32 static int _ad_sendfile_dummy;
34 #if defined(HAVE_SENDFILE_READ) || defined(HAVE_SENDFILE_WRITE)
35 static __inline__ int ad_sendfile_init(const struct adouble *ad,
36 const int eid, off_t *off,
42 *off = ad_size(ad, eid) - *off;
44 if (eid == ADEID_DFORK) {
47 *off += ad_getentryoff(ad, eid);
56 /* read from adouble file and write to socket. sendfile doesn't change
57 * the file pointer position. */
58 #ifdef HAVE_SENDFILE_READ
59 ssize_t ad_readfile(const struct adouble *ad, const int eid,
60 const int sock, off_t off, const size_t len)
65 fd = ad_sendfile_init(ad, eid, &off, 0);
67 cc = sendfile(sock, fd, &off, len);
68 #endif /* __linux__ */
71 if (sendfile(fd, sock, off, len, NULL, &cc, 0) < 0)
77 #endif /* HAVE_SENDFILE_READ */
80 #ifdef HAVE_SENDFILE_WRITE
81 /* read from a socket and write to an adouble file */
82 ssize_t ad_writefile(struct adouble *ad, const int eid,
83 const int sock, off_t off, const int end,
90 fd = ad_sendfile_init(ad, eid, &off, end);
91 if ((cc = sendfile(fd, sock, &off, len)) < 0)
94 if ((eid != ADEID_DFORK) && (off > ad_getentrylen(ad, eid)))
95 ad_setentrylen(ad, eid, off);
98 #endif /* __linux__ */
100 #endif /* HAVE_SENDFILE_WRITE */