forked from jursonmo/tcpbinddev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdset.go
36 lines (26 loc) · 815 Bytes
/
fdset.go
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
// +build linux
//https://github.com/creack/goselect
// darwin, netbsd and openbsd uses uint32 on both amd64 and 386
package tcpbinddev
import "syscall"
const FD_SETSIZE = syscall.FD_SETSIZE
// FDSet wraps syscall.FdSet with convenience methods
type FDSet syscall.FdSet
// Set adds the fd to the set
func (fds *FDSet) Set(fd uintptr) {
fds.Bits[fd/NFDBITS] |= (1 << (fd % NFDBITS))
}
// Clear remove the fd from the set
func (fds *FDSet) Clear(fd uintptr) {
fds.Bits[fd/NFDBITS] &^= (1 << (fd % NFDBITS))
}
// IsSet check if the given fd is set
func (fds *FDSet) IsSet(fd uintptr) bool {
return fds.Bits[fd/NFDBITS]&(1<<(fd%NFDBITS)) != 0
}
// Keep a null set to avoid reinstatiation
var nullFdSet = &FDSet{}
// Zero empties the Set
func (fds *FDSet) Zero() {
copy(fds.Bits[:], (nullFdSet).Bits[:])
}