mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-02 17:27:50 -04:00
49 lines
984 B
Go
49 lines
984 B
Go
package internet
|
|
|
|
import (
|
|
"syscall"
|
|
)
|
|
|
|
const (
|
|
TCP_FASTOPEN = 15
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
|
if isTCPSocket(network) {
|
|
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
|
|
return err
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
|
|
if isTCPSocket(network) {
|
|
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
|
return nil
|
|
}
|