-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathselect_cgo.go
55 lines (43 loc) · 1020 Bytes
/
select_cgo.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2014, Nick Patavalis ([email protected]).
// All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE.txt file.
// +build linux,noepoll freebsd netbsd openbsd darwin dragonfly solaris
package poller
/*
#include <sys/select.h>
void fdclr(int fd, fd_set *set) {
FD_CLR(fd, set);
}
int fdisset(int fd, fd_set *set) {
return FD_ISSET(fd, set);
}
void fdset(int fd, fd_set *set) {
FD_SET(fd, set);
}
void fdzero(fd_set *set) {
FD_ZERO(set);
}
*/
import "C"
import (
"syscall"
"unsafe"
)
type fdSet syscall.FdSet
func (fs *fdSet) Clr(fds ...int) {
for _, fd := range fds {
C.fdclr(C.int(fd), (*C.fd_set)(unsafe.Pointer(fs)))
}
}
func (fs *fdSet) Set(fds ...int) {
for _, fd := range fds {
C.fdset(C.int(fd), (*C.fd_set)(unsafe.Pointer(fs)))
}
}
func (fs *fdSet) Zero() {
C.fdzero((*C.fd_set)(unsafe.Pointer(fs)))
}
func (fs *fdSet) IsSet(fd int) bool {
return C.fdisset(C.int(fd), (*C.fd_set)(unsafe.Pointer(fs))) != 0
}