pkg/sys: Unify select_{linux,bsd}.go.

This commit is contained in:
Qi Xiao 2020-01-14 10:17:25 -05:00
parent 995879dcb6
commit f7a5b6002a
3 changed files with 4 additions and 26 deletions

View File

@ -1,23 +0,0 @@
// +build linux
package sys
import (
"time"
"golang.org/x/sys/unix"
)
func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout time.Duration) error {
// On ARM64, MIPS64 and MIPS64LE, unix.Select is emulated in userland and
// will dereference timeout. In that case, we use Pselect to work around the
// problem. Bug: https://github.com/golang/go/issues/24189
var ptimespec *unix.Timespec
if timeout >= 0 {
timespec := unix.NsecToTimespec(int64(timeout))
ptimespec = &timespec
}
_, err := unix.Pselect(nfd, r.s(), w.s(), e.s(), ptimespec, nil)
return err
}

View File

@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!plan9
package sys

View File

@ -1,4 +1,4 @@
// +build darwin dragonfly freebsd netbsd openbsd
// +build !windows,!plan9
package sys
@ -14,5 +14,6 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout time.Duration) error
timeval := unix.NsecToTimeval(int64(timeout))
ptimeval = &timeval
}
return unix.Select(nfd, r.s(), w.s(), e.s(), ptimeval)
_, err := unix.Select(nfd, r.s(), w.s(), e.s(), ptimeval)
return err
}