fdset.go 730 B

123456789101112131415161718192021222324252627282930313233
  1. // +build !freebsd,!windows,!plan9
  2. package goselect
  3. import "syscall"
  4. const FD_SETSIZE = syscall.FD_SETSIZE
  5. // FDSet wraps syscall.FdSet with convenience methods
  6. type FDSet syscall.FdSet
  7. // Set adds the fd to the set
  8. func (fds *FDSet) Set(fd uintptr) {
  9. fds.Bits[fd/NFDBITS] |= (1 << (fd % NFDBITS))
  10. }
  11. // Clear remove the fd from the set
  12. func (fds *FDSet) Clear(fd uintptr) {
  13. fds.Bits[fd/NFDBITS] &^= (1 << (fd % NFDBITS))
  14. }
  15. // IsSet check if the given fd is set
  16. func (fds *FDSet) IsSet(fd uintptr) bool {
  17. return fds.Bits[fd/NFDBITS]&(1<<(fd%NFDBITS)) != 0
  18. }
  19. // Keep a null set to avoid reinstatiation
  20. var nullFdSet = &FDSet{}
  21. // Zero empties the Set
  22. func (fds *FDSet) Zero() {
  23. copy(fds.Bits[:], (nullFdSet).Bits[:])
  24. }