mirror of
https://github.com/golang/go
synced 2024-10-06 08:00:07 +00:00
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 <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>
This commit is contained in:
parent
b6efc3b755
commit
e074fcc945
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue