-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsys_posix.go
39 lines (31 loc) · 868 Bytes
/
sys_posix.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
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package irtt
import (
"net"
"golang.org/x/sys/unix"
)
/*
// old syscall code, not used with golang.org/x/net
func setSockoptTOS(conn *net.UDPConn, tos int) error {
return setSockoptInt(conn, unix.IPPROTO_IP, unix.IP_TOS, tos)
}
func setSockoptTrafficClass(conn *net.UDPConn, tclass int) error {
return setSockoptInt(conn, unix.IPPROTO_IPV6, unix.IPV6_TCLASS, tclass)
}
func setSockoptTTL(conn *net.UDPConn, ttl int) error {
return setSockoptInt(conn, unix.IPPROTO_IP, unix.IP_TTL, ttl)
}
*/
func setSockoptInt(conn *net.UDPConn, level int, opt int, value int) error {
cfile, err := conn.File()
if err != nil {
return err
}
defer cfile.Close()
fd := int(cfile.Fd())
err = unix.SetsockoptInt(fd, level, opt, value)
if err != nil {
return err
}
return unix.SetNonblock(fd, true)
}