]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: fall back on unsupported splice from unix socket
authorBen Burkert <ben@benburkert.com>
Wed, 5 Sep 2018 17:20:26 +0000 (10:20 -0700)
committerTobias Klauser <tobias.klauser@gmail.com>
Sat, 15 Sep 2018 09:25:07 +0000 (09:25 +0000)
Gracefully fallback to a userspace copy when the kernel does not support
splice(2) on a unix domain socket. EINVAL is returned by the splice
syscall if it does not support unix domain sockets. Keeping the handled
return value as false when the first splice call fails with EINVAL will
cause the caller to fall back to a userspace copy.

Fixes #27513

Change-Id: I4b10c1900ba3c096cb32edb7c8a6044f468efb52
Reviewed-on: https://go-review.googlesource.com/133575
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
src/internal/poll/splice_linux.go

index aa237e587adabf45945f8841c78966a755053f9c..9ba94d648b6846ada887d0aff3688b6c075531fd 100644 (file)
@@ -32,8 +32,6 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string,
                return 0, false, sc, err
        }
        defer destroyTempPipe(prfd, pwfd)
-       // From here on, the operation should be considered handled,
-       // even if Splice doesn't transfer any data.
        var inPipe, n int
        for err == nil && remain > 0 {
                max := maxSpliceSize
@@ -41,6 +39,12 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string,
                        max = int(remain)
                }
                inPipe, err = spliceDrain(pwfd, src, max)
+               // the operation is considered handled if splice returns no error, or
+               // an error other than EINVAL. An EINVAL means the kernel does not
+               // support splice for the socket type of dst and/or src. The failed
+               // syscall does not consume any data so it is safe to fall back to a
+               // generic copy.
+               handled = handled || (err != syscall.EINVAL)
                // spliceDrain should never return EAGAIN, so if err != nil,
                // Splice cannot continue. If inPipe == 0 && err == nil,
                // src is at EOF, and the transfer is complete.
@@ -54,7 +58,7 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string,
                }
        }
        if err != nil {
-               return written, true, "splice", err
+               return written, handled, "splice", err
        }
        return written, true, "", nil
 }