fdset_windows.go 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // +build windows
  2. package goselect
  3. import "syscall"
  4. const FD_SETSIZE = 64
  5. // FDSet extracted from mingw libs source code
  6. type FDSet struct {
  7. fd_count uint
  8. fd_array [FD_SETSIZE]uintptr
  9. }
  10. // Set adds the fd to the set
  11. func (fds *FDSet) Set(fd uintptr) {
  12. var i uint
  13. for i = 0; i < fds.fd_count; i++ {
  14. if fds.fd_array[i] == fd {
  15. break
  16. }
  17. }
  18. if i == fds.fd_count {
  19. if fds.fd_count < FD_SETSIZE {
  20. fds.fd_array[i] = fd
  21. fds.fd_count++
  22. }
  23. }
  24. }
  25. // Clear remove the fd from the set
  26. func (fds *FDSet) Clear(fd uintptr) {
  27. var i uint
  28. for i = 0; i < fds.fd_count; i++ {
  29. if fds.fd_array[i] == fd {
  30. for i < fds.fd_count-1 {
  31. fds.fd_array[i] = fds.fd_array[i+1]
  32. i++
  33. }
  34. fds.fd_count--
  35. break
  36. }
  37. }
  38. }
  39. // IsSet check if the given fd is set
  40. func (fds *FDSet) IsSet(fd uintptr) bool {
  41. if isset, err := __WSAFDIsSet(syscall.Handle(fd), fds); err == nil && isset != 0 {
  42. return true
  43. }
  44. return false
  45. }
  46. // Zero empties the Set
  47. func (fds *FDSet) Zero() {
  48. fds.fd_count = 0
  49. }