package poll
import (
- "internal/syscall/unix"
"runtime"
"sync"
- "sync/atomic"
"syscall"
"unsafe"
)
splicePipePool.Put(p)
}
-var disableSplice unsafe.Pointer
-
// newPipe sets up a pipe for a splice operation.
-func newPipe() (sp *splicePipe) {
- p := (*bool)(atomic.LoadPointer(&disableSplice))
- if p != nil && *p {
- return nil
- }
-
+func newPipe() *splicePipe {
var fds [2]int
- // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it
- // might not be implemented. Falling back to pipe is possible, but prior to
- // 2.6.29 splice returns -EAGAIN instead of 0 when the connection is
- // closed.
- const flags = syscall.O_CLOEXEC | syscall.O_NONBLOCK
- if err := syscall.Pipe2(fds[:], flags); err != nil {
+ if err := syscall.Pipe2(fds[:], syscall.O_CLOEXEC|syscall.O_NONBLOCK); err != nil {
return nil
}
-
- sp = &splicePipe{splicePipeFields: splicePipeFields{rfd: fds[0], wfd: fds[1]}}
-
- if p == nil {
- p = new(bool)
- defer atomic.StorePointer(&disableSplice, unsafe.Pointer(p))
-
- // F_GETPIPE_SZ was added in 2.6.35, which does not have the -EAGAIN bug.
- if _, _, errno := syscall.Syscall(unix.FcntlSyscall, uintptr(fds[0]), syscall.F_GETPIPE_SZ, 0); errno != 0 {
- *p = true
- destroyPipe(sp)
- return nil
- }
- }
-
- return
+ return &splicePipe{splicePipeFields: splicePipeFields{rfd: fds[0], wfd: fds[1]}}
}
// destroyPipe destroys a pipe.