fdset.go 853 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
  5. // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos
  6. package unix
  7. // Set adds fd to the set fds.
  8. func (fds *FdSet) Set(fd int) {
  9. fds.Bits[fd/NFDBITS] |= (1 << (uintptr(fd) % NFDBITS))
  10. }
  11. // Clear removes fd from the set fds.
  12. func (fds *FdSet) Clear(fd int) {
  13. fds.Bits[fd/NFDBITS] &^= (1 << (uintptr(fd) % NFDBITS))
  14. }
  15. // IsSet returns whether fd is in the set fds.
  16. func (fds *FdSet) IsSet(fd int) bool {
  17. return fds.Bits[fd/NFDBITS]&(1<<(uintptr(fd)%NFDBITS)) != 0
  18. }
  19. // Zero clears the set fds.
  20. func (fds *FdSet) Zero() {
  21. for i := range fds.Bits {
  22. fds.Bits[i] = 0
  23. }
  24. }