//
// 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
}
}
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.
}
// 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) {
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)
}
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
}
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
}
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
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
}
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
}
}
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
}
}
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) {