Skip to content

Commit e074fcc

Browse files
tklausergopherbot
authored andcommitted
internal/poll, net, os: remove poll.Splice syscall name return value
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Tobias Klauser <[email protected]>
1 parent b6efc3b commit e074fcc

File tree

6 files changed

+25
-33
lines changed

6 files changed

+25
-33
lines changed

src/internal/poll/splice_linux.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ const (
3131
//
3232
// Splice gets a pipe buffer from the pool or creates a new one if needed, to serve as a buffer for the data transfer.
3333
// src and dst must both be stream-oriented sockets.
34-
//
35-
// If err != nil, sc is the system call which caused the error.
36-
func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, err error) {
37-
p, sc, err := getPipe()
34+
func Splice(dst, src *FD, remain int64) (written int64, handled bool, err error) {
35+
p, err := getPipe()
3836
if err != nil {
39-
return 0, false, sc, err
37+
return 0, false, err
4038
}
4139
defer putPipe(p)
4240
var inPipe, n int
@@ -71,9 +69,9 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string,
7169
}
7270
}
7371
if err != nil {
74-
return written, handled, "splice", err
72+
return written, handled, err
7573
}
76-
return written, true, "", nil
74+
return written, true, nil
7775
}
7876

7977
// spliceDrain moves data from a socket to a pipe.
@@ -204,15 +202,12 @@ func newPoolPipe() any {
204202
}
205203

206204
// getPipe tries to acquire a pipe buffer from the pool or create a new one with newPipe() if it gets nil from the cache.
207-
//
208-
// Note that it may fail to create a new pipe buffer by newPipe(), in which case getPipe() will return a generic error
209-
// and system call name splice in a string as the indication.
210-
func getPipe() (*splicePipe, string, error) {
205+
func getPipe() (*splicePipe, error) {
211206
v := splicePipePool.Get()
212207
if v == nil {
213-
return nil, "splice", syscall.EINVAL
208+
return nil, syscall.EINVAL
214209
}
215-
return v.(*splicePipe), "", nil
210+
return v.(*splicePipe), nil
216211
}
217212

218213
func putPipe(p *splicePipe) {

src/internal/poll/splice_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestSplicePipePool(t *testing.T) {
4141
t.Cleanup(func() { closeHook.Store((func(int))(nil)) })
4242

4343
for i := 0; i < N; i++ {
44-
p, _, err = poll.GetPipe()
44+
p, err = poll.GetPipe()
4545
if err != nil {
4646
t.Skipf("failed to create pipe due to error(%v), skip this test", err)
4747
}
@@ -93,7 +93,7 @@ func TestSplicePipePool(t *testing.T) {
9393
func BenchmarkSplicePipe(b *testing.B) {
9494
b.Run("SplicePipeWithPool", func(b *testing.B) {
9595
for i := 0; i < b.N; i++ {
96-
p, _, err := poll.GetPipe()
96+
p, err := poll.GetPipe()
9797
if err != nil {
9898
continue
9999
}
@@ -114,7 +114,7 @@ func BenchmarkSplicePipe(b *testing.B) {
114114
func BenchmarkSplicePipePoolParallel(b *testing.B) {
115115
b.RunParallel(func(pb *testing.PB) {
116116
for pb.Next() {
117-
p, _, err := poll.GetPipe()
117+
p, err := poll.GetPipe()
118118
if err != nil {
119119
continue
120120
}

src/net/splice_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func spliceFrom(c *netFD, r io.Reader) (written int64, err error, handled bool)
4141
return 0, nil, false
4242
}
4343

44-
written, handled, sc, err := pollSplice(&c.pfd, &s.pfd, remain)
44+
written, handled, err = pollSplice(&c.pfd, &s.pfd, remain)
4545
if lr != nil {
4646
lr.N -= written
4747
}
48-
return written, wrapSyscallError(sc, err), handled
48+
return written, wrapSyscallError("splice", err), handled
4949
}
5050

5151
// 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) {
5959
return
6060
}
6161

62-
written, handled, sc, err := pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
63-
return written, wrapSyscallError(sc, err), handled
62+
written, handled, err = pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
63+
return written, wrapSyscallError("splice", err), handled
6464
}

src/net/splice_linux_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,21 +519,20 @@ type spliceHook struct {
519519

520520
written int64
521521
handled bool
522-
sc string
523522
err error
524523

525-
original func(dst, src *poll.FD, remain int64) (int64, bool, string, error)
524+
original func(dst, src *poll.FD, remain int64) (int64, bool, error)
526525
}
527526

528527
func (h *spliceHook) install() {
529528
h.original = pollSplice
530-
pollSplice = func(dst, src *poll.FD, remain int64) (int64, bool, string, error) {
529+
pollSplice = func(dst, src *poll.FD, remain int64) (int64, bool, error) {
531530
h.called = true
532531
h.dstfd = dst.Sysfd
533532
h.srcfd = src.Sysfd
534533
h.remain = remain
535-
h.written, h.handled, h.sc, h.err = h.original(dst, src, remain)
536-
return h.written, h.handled, h.sc, h.err
534+
h.written, h.handled, h.err = h.original(dst, src, remain)
535+
return h.written, h.handled, h.err
537536
}
538537
}
539538

src/os/readfrom_linux_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,21 +693,20 @@ type spliceFileHook struct {
693693

694694
written int64
695695
handled bool
696-
sc string
697696
err error
698697

699-
original func(dst, src *poll.FD, remain int64) (int64, bool, string, error)
698+
original func(dst, src *poll.FD, remain int64) (int64, bool, error)
700699
}
701700

702701
func (h *spliceFileHook) install() {
703702
h.original = *PollSpliceFile
704-
*PollSpliceFile = func(dst, src *poll.FD, remain int64) (int64, bool, string, error) {
703+
*PollSpliceFile = func(dst, src *poll.FD, remain int64) (int64, bool, error) {
705704
h.called = true
706705
h.dstfd = dst.Sysfd
707706
h.srcfd = src.Sysfd
708707
h.remain = remain
709-
h.written, h.handled, h.sc, h.err = h.original(dst, src, remain)
710-
return h.written, h.handled, h.sc, h.err
708+
h.written, h.handled, h.err = h.original(dst, src, remain)
709+
return h.written, h.handled, h.err
711710
}
712711
}
713712

src/os/zero_copy_linux.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ func (f *File) spliceToFile(r io.Reader) (written int64, handled bool, err error
8787
return
8888
}
8989

90-
var syscallName string
91-
written, handled, syscallName, err = pollSplice(&f.pfd, pfd, remain)
90+
written, handled, err = pollSplice(&f.pfd, pfd, remain)
9291

9392
if lr != nil {
9493
lr.N = remain - written
9594
}
9695

97-
return written, handled, wrapSyscallError(syscallName, err)
96+
return written, handled, wrapSyscallError("splice", err)
9897
}
9998

10099
func (f *File) copyFileRange(r io.Reader) (written int64, handled bool, err error) {

0 commit comments

Comments
 (0)