mirror of https://github.com/golang/go.git
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.
|
// 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.
|
// src and dst must both be stream-oriented sockets.
|
||||||
//
|
func Splice(dst, src *FD, remain int64) (written int64, handled bool, err error) {
|
||||||
// If err != nil, sc is the system call which caused the error.
|
p, err := getPipe()
|
||||||
func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, err error) {
|
|
||||||
p, sc, err := getPipe()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false, sc, err
|
return 0, false, err
|
||||||
}
|
}
|
||||||
defer putPipe(p)
|
defer putPipe(p)
|
||||||
var inPipe, n int
|
var inPipe, n int
|
||||||
|
|
@ -71,9 +69,9 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
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.
|
// 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.
|
// getPipe tries to acquire a pipe buffer from the pool or create a new one with newPipe() if it gets nil from the cache.
|
||||||
//
|
func getPipe() (*splicePipe, error) {
|
||||||
// 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) {
|
|
||||||
v := splicePipePool.Get()
|
v := splicePipePool.Get()
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil, "splice", syscall.EINVAL
|
return nil, syscall.EINVAL
|
||||||
}
|
}
|
||||||
return v.(*splicePipe), "", nil
|
return v.(*splicePipe), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func putPipe(p *splicePipe) {
|
func putPipe(p *splicePipe) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func TestSplicePipePool(t *testing.T) {
|
||||||
t.Cleanup(func() { closeHook.Store((func(int))(nil)) })
|
t.Cleanup(func() { closeHook.Store((func(int))(nil)) })
|
||||||
|
|
||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
p, _, err = poll.GetPipe()
|
p, err = poll.GetPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Skipf("failed to create pipe due to error(%v), skip this test", err)
|
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) {
|
func BenchmarkSplicePipe(b *testing.B) {
|
||||||
b.Run("SplicePipeWithPool", func(b *testing.B) {
|
b.Run("SplicePipeWithPool", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
p, _, err := poll.GetPipe()
|
p, err := poll.GetPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +114,7 @@ func BenchmarkSplicePipe(b *testing.B) {
|
||||||
func BenchmarkSplicePipePoolParallel(b *testing.B) {
|
func BenchmarkSplicePipePoolParallel(b *testing.B) {
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
p, _, err := poll.GetPipe()
|
p, err := poll.GetPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@ func spliceFrom(c *netFD, r io.Reader) (written int64, err error, handled bool)
|
||||||
return 0, nil, false
|
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 {
|
if lr != nil {
|
||||||
lr.N -= written
|
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
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
written, handled, sc, err := pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
|
written, handled, err = pollSplice(&uc.fd.pfd, &c.pfd, 1<<63-1)
|
||||||
return written, wrapSyscallError(sc, err), handled
|
return written, wrapSyscallError("splice", err), handled
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -519,21 +519,20 @@ type spliceHook struct {
|
||||||
|
|
||||||
written int64
|
written int64
|
||||||
handled bool
|
handled bool
|
||||||
sc string
|
|
||||||
err error
|
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() {
|
func (h *spliceHook) install() {
|
||||||
h.original = pollSplice
|
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.called = true
|
||||||
h.dstfd = dst.Sysfd
|
h.dstfd = dst.Sysfd
|
||||||
h.srcfd = src.Sysfd
|
h.srcfd = src.Sysfd
|
||||||
h.remain = remain
|
h.remain = remain
|
||||||
h.written, h.handled, h.sc, h.err = h.original(dst, src, remain)
|
h.written, h.handled, h.err = h.original(dst, src, remain)
|
||||||
return h.written, h.handled, h.sc, h.err
|
return h.written, h.handled, h.err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -693,21 +693,20 @@ type spliceFileHook struct {
|
||||||
|
|
||||||
written int64
|
written int64
|
||||||
handled bool
|
handled bool
|
||||||
sc string
|
|
||||||
err error
|
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() {
|
func (h *spliceFileHook) install() {
|
||||||
h.original = *PollSpliceFile
|
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.called = true
|
||||||
h.dstfd = dst.Sysfd
|
h.dstfd = dst.Sysfd
|
||||||
h.srcfd = src.Sysfd
|
h.srcfd = src.Sysfd
|
||||||
h.remain = remain
|
h.remain = remain
|
||||||
h.written, h.handled, h.sc, h.err = h.original(dst, src, remain)
|
h.written, h.handled, h.err = h.original(dst, src, remain)
|
||||||
return h.written, h.handled, h.sc, h.err
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var syscallName string
|
written, handled, err = pollSplice(&f.pfd, pfd, remain)
|
||||||
written, handled, syscallName, err = pollSplice(&f.pfd, pfd, remain)
|
|
||||||
|
|
||||||
if lr != nil {
|
if lr != nil {
|
||||||
lr.N = remain - written
|
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) {
|
func (f *File) copyFileRange(r io.Reader) (written int64, handled bool, err error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue