summaryrefslogtreecommitdiff
path: root/software/vendor/github.com/creack/goselect/fdset_windows.go
blob: ee34919753c8724882f3dc604656badc7c310cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// +build windows

package goselect

import "syscall"

const FD_SETSIZE = 64

// FDSet extracted from mingw libs source code
type FDSet struct {
	fd_count uint
	fd_array [FD_SETSIZE]uintptr
}

// Set adds the fd to the set
func (fds *FDSet) Set(fd uintptr) {
	var i uint
	for i = 0; i < fds.fd_count; i++ {
		if fds.fd_array[i] == fd {
			break
		}
	}
	if i == fds.fd_count {
		if fds.fd_count < FD_SETSIZE {
			fds.fd_array[i] = fd
			fds.fd_count++
		}
	}
}

// Clear remove the fd from the set
func (fds *FDSet) Clear(fd uintptr) {
	var i uint
	for i = 0; i < fds.fd_count; i++ {
		if fds.fd_array[i] == fd {
			for i < fds.fd_count-1 {
				fds.fd_array[i] = fds.fd_array[i+1]
				i++
			}
			fds.fd_count--
			break
		}
	}
}

// IsSet check if the given fd is set
func (fds *FDSet) IsSet(fd uintptr) bool {
	if isset, err := __WSAFDIsSet(syscall.Handle(fd), fds); err == nil && isset != 0 {
		return true
	}
	return false
}

// Zero empties the Set
func (fds *FDSet) Zero() {
	fds.fd_count = 0
}