[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Emulation of sendfile().



lördag den 26 oktober 2013 klockan 18:09 skrev Robert Millan detta:
> 
> Please could you try:
> 
> 1. Rebuild freebsd-glue with attached patch
> 2. Add "-I /usr/include/freebsd" to CFLAGS in your package.
> 3. Add "-lfreebsd-glue" to LDFLAGS in your package.
>
> This should seamlessly map sendfile() to the BSD version.
> 
> Alternatively, you can skip step 2 and use bsd_sendfile() instead.

I now doubt the sanity of your undertaking, as the
patch is shadowing an existing sendfile() of glibc,
using a macro of a radically different signature.

Be that as it may, I wanted originally to find a mode
of attack that would allow my changes to work also in
Wheezy, but my efforts have so far been in vain, should
I hope to see it bring any effects. The intended patch
follows this letter as a reference only.

Regards,
  Mats E A
--- webfs-1.21+ds1.debian/response.c
+++ webfs-1.21+ds1/response.c
@@ -43,6 +43,8 @@ static inline size_t off_to_size(off_t o
     return off_bytes;
 }
 
+static ssize_t emulsendfile(int, int, off_t, off_t);
+
 #if defined(__linux__) && !defined(NO_SENDFILE)
 
 # include <sys/sendfile.h>
@@ -69,14 +71,49 @@ static ssize_t xsendfile(int out, int in
     }
     return nbytes;
 }
+
+#elif defined(__FreeBSD_kernel__) && !defined(__FreeBSD__) \
+      && !defined(NO_SENDFILE)
+
+# warning Accessing kernel sendfile() with GNU/kFreeBSD.
+# include <sys/sendfile.h>
+
+static ssize_t xsendfile(int out, int in, off_t offset, off_t off_bytes)
+{
+    size_t bytes = off_to_size(off_bytes);
+
+    off_t nbytes = sendfile(out, in, &offset, bytes);
+
+    if (nbytes < 0) {
+	/* Make sure GNU/kFreeBSD has gotten the right implementation. */
+	if (errno == ENOSYS) {
+# ifdef DEBUG_XSENDFILE
+	    /* Report only once per file transmission. */
+	    if (offset == 0)
+		syslog(LOG_NOTICE | LOG_DAEMON,
+		       "Off-loading via sendfile is not possible.");
+# endif /* DEBUG_XSENDFILE */
+	    return emulsendfile(out, in, offset, off_bytes);
+	}
+	return -1;
+    }
+    return nbytes;
+}
+
 #else
 
 # warning using slow sendfile() emulation.
 
+static ssize_t xsendfile(int out, int in, off_t offset, off_t off_bytes)
+{
+    return emulsendfile(out, in, offset, off_bytes);
+}
+#endif
+
 /* Poor man's sendfile() implementation. Performance sucks, but it works. */
 # define BUFSIZE 16384
 
-static ssize_t xsendfile(int out, int in, off_t offset, off_t off_bytes)
+static ssize_t emulsendfile(int out, int in, off_t offset, off_t off_bytes)
 {
     char buf[BUFSIZE];
     ssize_t nread;
@@ -117,8 +154,6 @@ static ssize_t xsendfile(int out, int in
     return nsent_total;
 }
 
-#endif
-
 /* ---------------------------------------------------------------------- */
 
 #if defined(USE_SSL) || defined(USE_GNUTLS)

Reply to: