-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet_linux.go
36 lines (31 loc) · 849 Bytes
/
net_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
package l2
import (
"net"
"syscall"
"time"
"golang.org/x/sys/unix"
)
var listenConfig = &net.ListenConfig{
Control: func(network, address string, conn syscall.RawConn) (err error) {
defer he(&err)
ce(conn.Control(func(fd uintptr) {
ce(syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, unix.TCP_NODELAY, 1))
ce(syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, unix.TCP_QUICKACK, 1))
}))
return nil
},
}
func newDialer() *net.Dialer {
return &net.Dialer{
Timeout: time.Second * 16,
Control: func(network, address string, conn syscall.RawConn) (err error) {
defer he(&err)
ce(conn.Control(func(fd uintptr) {
ce(syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, unix.TCP_NODELAY, 1))
ce(syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, unix.TCP_QUICKACK, 1))
}))
return nil
},
}
}
var dialer = newDialer()