2018-09-10 08:39:57 -04:00
|
|
|
package internet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCP_FASTOPEN = 15
|
|
|
|
)
|
|
|
|
|
2018-09-11 04:03:26 -04:00
|
|
|
func setTFO(fd syscall.Handle, settings SocketConfig_TCPFastOpenState) error {
|
|
|
|
switch settings {
|
|
|
|
case SocketConfig_Enable:
|
|
|
|
if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, 1); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
case SocketConfig_Disable:
|
|
|
|
if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-10 08:39:57 -04:00
|
|
|
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
2018-09-11 04:03:26 -04:00
|
|
|
if isTCPSocket(network) {
|
2018-09-11 04:18:26 -04:00
|
|
|
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
|
2018-09-11 04:03:26 -04:00
|
|
|
return err
|
2018-09-10 08:39:57 -04:00
|
|
|
}
|
2018-09-11 04:03:26 -04:00
|
|
|
|
2018-09-10 08:39:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
|
2018-09-11 04:03:26 -04:00
|
|
|
if isTCPSocket(network) {
|
2018-09-11 04:18:26 -04:00
|
|
|
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
|
2018-09-11 04:03:26 -04:00
|
|
|
return err
|
2018-09-10 08:39:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-09-17 09:12:58 -04:00
|
|
|
|
2018-11-21 08:54:40 -05:00
|
|
|
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
2018-09-17 09:12:58 -04:00
|
|
|
return nil
|
|
|
|
}
|