fdset.go 781 B

1234567891011121314151617181920212223242526272829
  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. package unix
  6. // Set adds fd to the set fds.
  7. func (fds *FdSet) Set(fd int) {
  8. fds.Bits[fd/NFDBITS] |= (1 << (uintptr(fd) % NFDBITS))
  9. }
  10. // Clear removes fd from the set fds.
  11. func (fds *FdSet) Clear(fd int) {
  12. fds.Bits[fd/NFDBITS] &^= (1 << (uintptr(fd) % NFDBITS))
  13. }
  14. // IsSet returns whether fd is in the set fds.
  15. func (fds *FdSet) IsSet(fd int) bool {
  16. return fds.Bits[fd/NFDBITS]&(1<<(uintptr(fd)%NFDBITS)) != 0
  17. }
  18. // Zero clears the set fds.
  19. func (fds *FdSet) Zero() {
  20. for i := range fds.Bits {
  21. fds.Bits[i] = 0
  22. }
  23. }