select_posix.go 421 B

1234567891011121314151617181920
  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. func Select(nfd int, r *unix.FdSet, w *unix.FdSet, e *unix.FdSet, timeout time.Duration) (n int, err error) {
  9. if timeout < 0 {
  10. return unix.Pselect(nfd, r, w, e, nil, nil)
  11. }
  12. ts := unix.NsecToTimespec(int64(timeout))
  13. return unix.Pselect(nfd, r, w, e, &ts, nil)
  14. }