select_without_pselect.go 453 B

12345678910111213141516171819202122
  1. // License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
  2. //go:build !linux
  3. package utils
  4. import (
  5. "time"
  6. "golang.org/x/sys/unix"
  7. )
  8. // Go unix does not wrap pselect on darwin
  9. func Select(nfd int, r *unix.FdSet, w *unix.FdSet, e *unix.FdSet, timeout time.Duration) (n int, err error) {
  10. if timeout < 0 {
  11. return unix.Select(nfd, r, w, e, nil)
  12. }
  13. ts := unix.NsecToTimeval(int64(timeout))
  14. return unix.Select(nfd, r, w, e, &ts)
  15. }