2 * $Id: ad_sendfile.c,v 1.7 2003-06-06 20:43:14 srittau 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 #if defined(HAVE_SENDFILE_READ) || defined(HAVE_SENDFILE_WRITE)
33 static __inline__ int ad_sendfile_init(const struct adouble *ad,
34 const int eid, off_t *off,
40 *off = ad_size(ad, eid) - *off;
42 if (eid == ADEID_DFORK) {
45 *off += ad_getentryoff(ad, eid);
54 /* read from adouble file and write to socket. sendfile doesn't change
55 * the file pointer position. */
56 #ifdef HAVE_SENDFILE_READ
57 ssize_t ad_readfile(const struct adouble *ad, const int eid,
58 const int sock, off_t off, const size_t len)
63 fd = ad_sendfile_init(ad, eid, &off, 0);
65 cc = sendfile(sock, fd, &off, len);
66 #endif /* __linux__ */
69 if (sendfile(fd, sock, off, len, NULL, &cc, 0) < 0)
75 #endif /* HAVE_SENDFILE_READ */
78 #ifdef HAVE_SENDFILE_WRITE
79 /* read from a socket and write to an adouble file */
80 ssize_t ad_writefile(struct adouble *ad, const int eid,
81 const int sock, off_t off, const int end,
88 fd = ad_sendfile_init(ad, eid, &off, end);
89 if ((cc = sendfile(fd, sock, &off, len)) < 0)
92 if ((eid != ADEID_DFORK) && (off > ad_getentrylen(ad, eid)))
93 ad_setentrylen(ad, eid, off);
96 #endif /* __linux__ */
98 #endif /* HAVE_SENDFILE_WRITE */