Do not use vmsplice in case of underflow (near end-of-file)
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Wed, 10 Dec 2008 20:07:37 +0000 (22:07 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Wed, 10 Dec 2008 20:07:37 +0000 (22:07 +0200)
modules/stream_filter/decomp.c

index aa183e5..5283f44 100644 (file)
@@ -82,6 +82,9 @@ static void *Thread (void *data)
 {
     stream_t *stream = data;
     stream_sys_t *p_sys = stream->p_sys;
+#ifdef __linux__
+    uintptr_t page_mask = sysconf (_SC_PAGE_SIZE) - 1;
+#endif
     int fd = p_sys->write_fd;
     bool error = false;
 
@@ -108,9 +111,11 @@ static void *Thread (void *data)
             struct iovec iov[1] = { { buf + i, len - i, } };
 
 #ifdef __linux__
-            j = vmsplice (fd, iov, 1, SPLICE_F_GIFT);
+            if (((len | i) & page_mask) == 0)
+                j = vmsplice (fd, iov, 1, SPLICE_F_GIFT);
+            else
 #else
-            j = writev (fd, iov, 1);
+                j = writev (fd, iov, 1);
 #endif
             if (j <= 0)
             {