]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll, net, os: remove poll.Splice syscall name return value
authorTobias Klauser <tklauser@distanz.ch>
Tue, 2 Apr 2024 09:23:47 +0000 (11:23 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 2 Apr 2024 21:49:26 +0000 (21:49 +0000)
The sc return value of internal/poll.Splice is always set to the same
value "splice" in the error case and then passed to wrapSyscallError.
Move that value to the wrapSyscallError calls to simplify the code a
bit.

Change-Id: I98104d755da68ff9f301fabc43c2618fda21a175
Reviewed-on: https://go-review.googlesource.com/c/go/+/575655
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

src/internal/poll/splice_linux.go
src/internal/poll/splice_linux_test.go
src/net/splice_linux.go
src/net/splice_linux_test.go
src/os/readfrom_linux_test.go
src/os/zero_copy_linux.go

index 72cca34fe4ae5ec88c81d4413459d49294e4691a..193a56215c727c75bd1b1a16dcd8c3853bc26aa3 100644 (file)
@@ -31,12 +31,10 @@ const (
 //
 // Splice gets a pipe buffer from the pool or creates a new one if needed, to serve as a buffer for the data transfer.
 // src and dst must both be stream-oriented sockets.
-//
-// If err != nil, sc is the system call which caused the error.
-func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, err error) {
-       p, sc, err := getPipe()
+func Splice(dst, src *FD, remain int64) (written int64, handled bool, err error) {
+       p, err := getPipe()
        if err != nil {
-               return 0, false, sc, err
+               return 0, false, err
        }
        defer putPipe(p)
        var inPipe, n int
@@ -71,9 +69,9 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string,
                }
        }
        if err != nil {
-               return written, handled, "splice", err
+               return written, handled, err
        }
-       return written, true, "", nil
+       return written, true, nil
 }
 
 // spliceDrain moves data from a socket to a pipe.
@@ -204,15 +202,12 @@ func newPoolPipe() any {
 }
 
 // getPipe tries to acquire a pipe buffer from the pool or create a new one with newPipe() if it gets nil from the cache.
-//
-// Note that it may fail to create a new pipe buffer by newPipe(), in which case getPipe() will return a generic error
-// and system call name splice in a string as the indication.
-func getPipe() (*splicePipe, string, error) {
+func getPipe() (*splicePipe, error) {
        v := splicePipePool.Get()
        if v == nil {
-               return nil, "splice", syscall.EINVAL
+               return nil, syscall.EINVAL
        }
-       return v.(*splicePipe), "", nil
+       return v.(*splicePipe), nil
 }
 
 func putPipe(p *splicePipe) {
index 29bcaab4140f7c5999c6597e464a51d146975e0a..e4a7eb2b435d1248f0cc7e91bf2cef26133fe160 100644 (file)
@@ -41,7 +41,7 @@ func TestSplicePipePool(t *testing.T) {
        t.Cleanup(func() { closeHook.Store((func(int))(nil)) })
 
        for i := 0; i < N; i++ {
-               p, _, err = poll.GetPipe()
+               p, err = poll.GetPipe()
                if err != nil {
                        t.Skipf("failed to create pipe due to error(%v), skip this test", err)
                }
@@ -93,7 +93,7 @@ func TestSplicePipePool(t *testing.T) {
 func BenchmarkSplicePipe(b *testing.B) {
        b.Run("SplicePipeWithPool", func(b *testing.B) {
                for i := 0; i < b.N; i++ {
-                       p, _, err := poll.GetPipe()
+                       p, err := poll.GetPipe()
                        if err != nil {
                                continue
                        }
@@ -114,7 +114,7 @@ func BenchmarkSplicePipe(b *testing.B) {
 func BenchmarkSplicePipePoolParallel(b *testing.B) {
        b.RunParallel(func(pb *testing.PB) {
                for pb.Next() {
-                       p, _, err := poll.GetPipe()
+                       p, err := poll.GetPipe()
                        if err != nil {
                                continue
                        }
index 9fc26b4c23e9d2b58ef0005b39faaef26fce60fd..b62e8a722db851552e36b83477a3e96a9c0a24a3 100644 (file)
@@ -41,11 +41,11 @@ func spliceFrom(c *netFD, r io.Reader) (written int64, err error, handled bool)
                return 0, nil, false
        }
 
-       written, handled, sc, err := pollSplice(&c.pfd, &s.pfd, remain)
+       written, handled, err = pollSplice(&c.pfd, &s.pfd, remain)
        if lr != nil {
                lr.N -= written
        }
-       return written, wrapSyscallError(sc, err), handled
+       return written, wrapSyscallError("splice", err), handled
 }
 
 // spliceTo transfers data from c to w using the splice system call to minimize
@@ -59,6 +59,6 @@ func spliceTo(w io.Writer, c *netFD) (written int64, err error, handled bool) {
                return
        }
 
-       written, handled, sc, err := pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
-       return written, wrapSyscallError(sc, err), handled
+       written, handled, err = pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
+       return written, wrapSyscallError("splice", err), handled
 }
index 2edd7444068b94c4bb0bd04ff2770044edda0838..52efafa8c542789b4ce21c72b572cee67e48dcf4 100644 (file)
@@ -519,21 +519,20 @@ type spliceHook struct {
 
        written int64
        handled bool
-       sc      string
        err     error
 
-       original func(dst, src *poll.FD, remain int64) (int64, bool, string, error)
+       original func(dst, src *poll.FD, remain int64) (int64, bool, error)
 }
 
 func (h *spliceHook) install() {
        h.original = pollSplice
-       pollSplice = func(dst, src *poll.FD, remain int64) (int64, bool, string, error) {
+       pollSplice = func(dst, src *poll.FD, remain int64) (int64, bool, error) {
                h.called = true
                h.dstfd = dst.Sysfd
                h.srcfd = src.Sysfd
                h.remain = remain
-               h.written, h.handled, h.sc, h.err = h.original(dst, src, remain)
-               return h.written, h.handled, h.sc, h.err
+               h.written, h.handled, h.err = h.original(dst, src, remain)
+               return h.written, h.handled, h.err
        }
 }
 
index b292bffe2b5fc2fa1bdaafb43fce264c27294e43..8dcb9cb217288263221afa03f877fe5503879e54 100644 (file)
@@ -693,21 +693,20 @@ type spliceFileHook struct {
 
        written int64
        handled bool
-       sc      string
        err     error
 
-       original func(dst, src *poll.FD, remain int64) (int64, bool, string, error)
+       original func(dst, src *poll.FD, remain int64) (int64, bool, error)
 }
 
 func (h *spliceFileHook) install() {
        h.original = *PollSpliceFile
-       *PollSpliceFile = func(dst, src *poll.FD, remain int64) (int64, bool, string, error) {
+       *PollSpliceFile = func(dst, src *poll.FD, remain int64) (int64, bool, error) {
                h.called = true
                h.dstfd = dst.Sysfd
                h.srcfd = src.Sysfd
                h.remain = remain
-               h.written, h.handled, h.sc, h.err = h.original(dst, src, remain)
-               return h.written, h.handled, h.sc, h.err
+               h.written, h.handled, h.err = h.original(dst, src, remain)
+               return h.written, h.handled, h.err
        }
 }
 
index d9cf18c22f0fcb8c1d4ae286714483643b7360db..70a05ffa1e15dc29fc05ec8e4124a44fb09eb3a5 100644 (file)
@@ -87,14 +87,13 @@ func (f *File) spliceToFile(r io.Reader) (written int64, handled bool, err error
                return
        }
 
-       var syscallName string
-       written, handled, syscallName, err = pollSplice(&f.pfd, pfd, remain)
+       written, handled, err = pollSplice(&f.pfd, pfd, remain)
 
        if lr != nil {
                lr.N = remain - written
        }
 
-       return written, handled, wrapSyscallError(syscallName, err)
+       return written, handled, wrapSyscallError("splice", err)
 }
 
 func (f *File) copyFileRange(r io.Reader) (written int64, handled bool, err error) {