-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathutil_linux.go
42 lines (33 loc) · 837 Bytes
/
util_linux.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
//go:build linux
package fastdns
import (
"context"
"net"
"syscall"
"unsafe"
)
func listen(network, address string) (*net.UDPConn, error) {
lc := &net.ListenConfig{
Control: func(network, address string, conn syscall.RawConn) error {
return conn.Control(func(fd uintptr) {
const SO_REUSEPORT = 15
_ = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, SO_REUSEPORT, 1)
})
},
}
conn, err := lc.ListenPacket(context.Background(), network, address)
if err != nil {
return nil, err
}
return conn.(*net.UDPConn), nil
}
func taskset(cpu int) error {
const SYS_SCHED_SETAFFINITY = 203
mask := make([]byte, 128)
mask[cpu/8] = 1 << (cpu % 8)
_, _, e := syscall.RawSyscall(SYS_SCHED_SETAFFINITY, uintptr(0), uintptr(len(mask)), uintptr(unsafe.Pointer(&mask[0])))
if e == 0 {
return nil
}
return e
}