[SCM] Samba Shared Repository - branch master updated
Björn Jacke
bjacke at samba.org
Thu Jul 26 09:20:02 MDT 2012
The branch, master has been updated
via 96340e6 s3: add Darwin sendfile support and merge with the FreeBSD code
via 887cebf s3:waf: add Darwin sendfile() test
via d347c8d s3:configure: add Darwin sendfile() test
from 115a88e lib/param: Merge "Filename Handling" section from source3/param
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 96340e60b7f7ff86a49cbb822ae9170812114dcd
Author: Björn Jacke <bj at sernet.de>
Date: Fri Jun 29 20:16:18 2012 +0200
s3: add Darwin sendfile support and merge with the FreeBSD code
This is based on the adpotion of the FreeBSD sendfile code that was done by
James Peach for Darwin.
Autobuild-User(master): Björn Jacke <bj at sernet.de>
Autobuild-Date(master): Thu Jul 26 17:19:09 CEST 2012 on sn-devel-104
commit 887cebffd06c1a9e8b3979c209cebf230de49d45
Author: Björn Jacke <bj at sernet.de>
Date: Mon Jul 2 12:47:06 2012 +0200
s3:waf: add Darwin sendfile() test
commit d347c8d5775261a59679bc7ecd3b5e9b5b9ccca7
Author: Björn Jacke <bj at sernet.de>
Date: Fri Jun 29 20:13:57 2012 +0200
s3:configure: add Darwin sendfile() test
-----------------------------------------------------------------------
Summary of changes:
source3/configure.in | 32 ++++++++++++++++
source3/lib/sendfile.c | 94 ++++++++++++++++++++++-------------------------
source3/wscript | 23 ++++++++++++
3 files changed, 99 insertions(+), 50 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source3/configure.in b/source3/configure.in
index 6a26038..bd21db9 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -5649,7 +5649,39 @@ samba_cv_HAVE_SENDFILE=yes,samba_cv_HAVE_SENDFILE=no)])
AC_MSG_RESULT(no);
fi
;;
+ *darwin*)
+ AC_CACHE_CHECK([for Darwin sendfile support],
+ samba_cv_HAVE_SENDFILE,
+ [
+ AC_TRY_LINK([
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+ ],
+ [
+ int fromfd, tofd, ret;
+ off_t offset, nwritten;
+ struct sf_hdtr hdr;
+ struct iovec hdtrl;
+ hdr.headers = &hdtrl;
+ hdr.hdr_cnt = 1;
+ hdr.trailers = (void *)0;
+ hdr.trl_cnt = 0;
+ hdtrl.iov_base = (void *)0;
+ hdtrl.iov_len = 0;
+ ret = sendfile(fromfd, tofd, offset, &nwritten, &hdr, 0);
+ ],
+ samba_cv_HAVE_SENDFILE=yes,
+ samba_cv_HAVE_SENDFILE=no)])
+ if test x"$samba_cv_HAVE_SENDFILE" = x"yes"; then
+ AC_DEFINE(HAVE_SENDFILE,1,[Whether sendfile() support is available])
+ AC_DEFINE(DARWIN_SENDFILE_API,1,[Whether the Darwin sendfile() API is available])
+ AC_DEFINE(WITH_SENDFILE,1,[Whether sendfile() support should be included])
+ else
+ AC_MSG_RESULT(no);
+ fi
+ ;;
*hpux*|*osf*)
AC_CACHE_CHECK([for osf/hpux sendfile support],samba_cv_HAVE_SENDFILE,[
AC_TRY_LINK([\
diff --git a/source3/lib/sendfile.c b/source3/lib/sendfile.c
index 196ef68..d5fd5a6 100644
--- a/source3/lib/sendfile.c
+++ b/source3/lib/sendfile.c
@@ -248,80 +248,74 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
return count + hdr_len;
}
-#elif defined(FREEBSD_SENDFILE_API)
+#elif defined(FREEBSD_SENDFILE_API) || defined(DARWIN_SENDFILE_API)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
-ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset, size_t count)
+ssize_t sys_sendfile(int tofd, int fromfd,
+ const DATA_BLOB *header, off_t offset, size_t count)
{
- size_t total=0;
- struct sf_hdtr hdr;
- struct iovec hdtrl;
- size_t hdr_len = 0;
+ struct sf_hdtr sf_header = {0};
+ struct iovec io_header = {0};
- hdr.headers = &hdtrl;
- hdr.hdr_cnt = 1;
- hdr.trailers = NULL;
- hdr.trl_cnt = 0;
+ off_t nwritten;
+ int ret;
- /* Set up the header iovec. */
if (header) {
- hdtrl.iov_base = (void *)header->data;
- hdtrl.iov_len = hdr_len = header->length;
- } else {
- hdtrl.iov_base = NULL;
- hdtrl.iov_len = 0;
+ sf_header.headers = &io_header;
+ sf_header.hdr_cnt = 1;
+ io_header.iov_base = header->data;
+ io_header.iov_len = header->length;
+ sf_header.trailers = NULL;
+ sf_header.trl_cnt = 0;
}
- total = count;
- while (total + hdtrl.iov_len) {
- off_t nwritten;
- int ret;
-
- /*
- * FreeBSD sendfile returns 0 on success, -1 on error.
- * Remember, the tofd and fromfd are reversed..... :-).
- * nwritten includes the header data sent.
- */
+ while (count != 0) {
- do {
- ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0);
+ nwritten = count;
+#if defined(DARWIN_SENDFILE_API)
+ /* Darwin recycles nwritten as a value-result parameter, apart from that this
+ sendfile implementation is quite the same as the FreeBSD one */
+ ret = sendfile(fromfd, tofd, offset, &nwritten, &sf_header, 0);
+#else
+ ret = sendfile(fromfd, tofd, offset, count, &sf_header, &nwritten, 0);
+#endif
#if defined(EWOULDBLOCK)
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
+ if (ret == -1 && errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) {
#else
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+ if (ret == -1 && errno != EINTR && errno != EAGAIN) {
#endif
- if (ret == -1)
+ /* Send failed, we are toast. */
return -1;
+ }
- if (nwritten == 0)
- return -1; /* I think we're at EOF here... */
-
- /*
- * If this was a short (signal interrupted) write we may need
- * to subtract it from the header data, or null out the header
- * data altogether if we wrote more than hdtrl.iov_len bytes.
- * We change nwritten to be the number of file bytes written.
- */
+ if (nwritten == 0) {
+ /* EOF of offset is after EOF. */
+ break;
+ }
- if (hdtrl.iov_base && hdtrl.iov_len) {
- if (nwritten >= hdtrl.iov_len) {
- nwritten -= hdtrl.iov_len;
- hdtrl.iov_base = NULL;
- hdtrl.iov_len = 0;
+ if (sf_header.hdr_cnt) {
+ if (io_header.iov_len <= nwritten) {
+ /* Entire header was sent. */
+ sf_header.headers = NULL;
+ sf_header.hdr_cnt = 0;
+ nwritten -= io_header.iov_len;
} else {
- hdtrl.iov_base =
- (void *)((caddr_t)hdtrl.iov_base + nwritten);
- hdtrl.iov_len -= nwritten;
+ /* Partial header was sent. */
+ io_header.iov_len -= nwritten;
+ io_header.iov_base =
+ ((uint8_t *)io_header.iov_base) + nwritten;
nwritten = 0;
}
}
- total -= nwritten;
+
offset += nwritten;
+ count -= nwritten;
}
- return count + hdr_len;
+
+ return nwritten;
}
#elif defined(AIX_SENDFILE_API)
diff --git a/source3/wscript b/source3/wscript
index 91ffc25..0be9a43 100755
--- a/source3/wscript
+++ b/source3/wscript
@@ -1061,6 +1061,29 @@ main() {
conf.DEFINE('HAVE_SENDFILE', '1')
conf.DEFINE('FREEBSD_SENDFILE_API', '1')
conf.DEFINE('WITH_SENDFILE', '1')
+ elif (host_os.rfind('darwin') > -1):
+ conf.CHECK_CODE('''
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <sys/uio.h>
+ int fromfd, tofd, ret;
+ off_t offset, nwritten;
+ struct sf_hdtr hdr;
+ struct iovec hdtrl;
+ hdr.headers = &hdtrl;
+ hdr.hdr_cnt = 1;
+ hdr.trailers = (void *)0;
+ hdr.trl_cnt = 0;
+ hdtrl.iov_base = (void *)0;
+ hdtrl.iov_len = 0;
+ ret = sendfile(fromfd, tofd, offset, &nwritten, &hdr, 0);
+ ''',
+ '_HAVE_SENDFILE',
+ msg='Checking for darwin sendfile support')
+ if conf.CONFIG_SET('_HAVE_SENDFILE'):
+ conf.DEFINE('HAVE_SENDFILE', '1')
+ conf.DEFINE('DARWIN_SENDFILE_API', '1')
+ conf.DEFINE('WITH_SENDFILE', '1')
elif (host_os.rfind('hpux') > -1) or (host_os.rfind('osf') > -1):
conf.CHECK_CODE('''
#include <sys/socket.h>
--
Samba Shared Repository
More information about the samba-cvs
mailing list