2 Unix SMB/Netbios implementation.
4 sendfile implementations.
5 Copyright (C) Jeremy Allison 2002.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * This file handles the OS dependent sendfile implementations.
23 * The API is such that it returns -1 on error, else returns the
24 * number of bytes written.
29 #if defined(LINUX_SENDFILE_API)
31 #include <sys/sendfile.h>
34 #define MSG_MORE 0x8000
37 ssize_t sys_sendfile(int outfd, int infd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
43 * Send the header first.
44 * Use MSG_MORE to cork the TCP output until sendfile is called.
47 while (total < header->length) {
48 ret = sys_send(outfd, header->data + total,header->length - total, MSG_MORE);
58 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(SENDFILE64)
59 nwritten = sendfile64(outfd, infd, &offset, total);
61 nwritten = sendfile(outfd, infd, &offset, total);
63 } while (nwritten == -1 && errno == EINTR);
67 return -1; /* I think we're at EOF here... */
70 return count + header->length;
73 #elif defined(SOLARIS_SENDFILE_API)
75 ssize_t sys_sendfile(int outfd, int infd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
79 #elif defined(HPUX_SENDFILE_API)
81 #include <sys/socket.h>
84 ssize_t sys_sendfile(int outfd, int infd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
87 struct iovec hdtrl[2];
89 /* Set up the header/trailer iovec. */
90 hdtrl[0].iov_base = header->data;
91 hdtrl[0].iov_len = header->length;
92 hdtrl[1].iov_base = NULL;
93 hdtrl[1].iov_base = 0;
99 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(SENDFILE64)
100 nwritten = sendfile64(outfd, infd, &offset, total, &hdtrl, 0);
102 nwritten = sendfile(outfd, infd, &offset, total, &hdtrl, 0);
104 } while (nwritten == -1 && errno == EINTR);
109 return count + header->length;
112 #elif defined(FREEBSD_SENDFILE_API)
114 #include <sys/types.h>
115 #include <sys/socket.h>
118 ssize_t sys_sendfile(int outfd, int infd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
124 hdr->headers = &hdtrl;
126 hdr->trailers = NULL;
129 /* Set up the header iovec. */
130 hdtrl.iov_base = header->data;
131 hdtrl.iov_len = header->length;
137 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(SENDFILE64)
138 nwritten = sendfile64(outfd, infd, &offset, total, &hdr, NULL, 0);
140 nwritten = sendfile(outfd, infd, &offset, total, &hdr, NULL, 0);
142 } while (nwritten == -1 && errno == EINTR);
147 return count + header->length;
150 #else /* No sendfile implementation. Return error. */
152 ssize_t sys_sendfile(int outfd, int infd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
154 /* No sendfile syscall. */