[dovecot-cvs] dovecot/src/lib sendfile-util.c,1.1,1.2
cras at procontrol.fi
cras at procontrol.fi
Mon Oct 28 05:35:07 EET 2002
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv6761/src/lib
Modified Files:
sendfile-util.c
Log Message:
Support FreeBSD-compatible sendfile(). Completely untested.
Index: sendfile-util.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/sendfile-util.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sendfile-util.c 28 Aug 2002 00:11:51 -0000 1.1
+++ sendfile-util.c 28 Oct 2002 03:35:05 -0000 1.2
@@ -2,12 +2,15 @@
It's required to be able to include sys/sendfile.h with Linux. */
#include "../../config.h"
#undef HAVE_CONFIG_H
-#undef _FILE_OFFSET_BITS
+
+#ifdef HAVE_LINUX_SENDFILE
+# undef _FILE_OFFSET_BITS
+#endif
#include "lib.h"
#include "sendfile-util.h"
-#ifdef HAVE_SYS_SENDFILE_H
+#ifdef HAVE_LINUX_SENDFILE
#include <sys/sendfile.h>
@@ -21,7 +24,7 @@
if (sizeof(off_t) * CHAR_BIT == 32) {
/* 32bit off_t */
if (*offset > 2147483647L) {
- errno = EINVAL;
+ errno = EOVERFLOW;
return -1;
}
} else {
@@ -30,7 +33,7 @@
i_assert(sizeof(off_t) == sizeof(uoff_t));
if (*offset > OFF_T_MAX) {
- errno = EINVAL;
+ errno = EOVERFLOW;
return -1;
}
}
@@ -42,6 +45,29 @@
return ret;
}
+#elif defined(HAVE_FREEBSD_SENDFILE)
+
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+ssize_t safe_sendfile(int out_fd, int in_fd, uoff_t *offset, size_t count)
+{
+ struct sf_hdtr hdtr;
+ off_t sbytes;
+ int ret;
+
+ i_assert(count <= SSIZE_T_MAX);
+
+ memset(&hdtr, 0, sizeof(hdtr));
+ ret = sendfile(in_fd, out_fd, *offset, count, &hdtr, &sbytes, 0);
+
+ *offset += sbytes;
+
+ if (ret == 0 || (ret == 0 && errno == EAGAIN && sbytes > 0))
+ return (ssize_t)sbytes;
+ else
+ return -1;
+}
#else
ssize_t safe_sendfile(int out_fd __attr_unused__, int in_fd __attr_unused__,
uoff_t *offset __attr_unused__,
More information about the dovecot-cvs
mailing list