mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 18:17:52 -05:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package internet
|
|
|
|
import (
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
const (
|
|
TCP_FASTOPEN = 0x105
|
|
TCP_FASTOPEN_SERVER = 0x01
|
|
TCP_FASTOPEN_CLIENT = 0x02
|
|
)
|
|
|
|
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
|
if strings.HasPrefix(network, "tcp") {
|
|
switch config.Tfo {
|
|
case SocketConfig_Enable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_CLIENT); err != nil {
|
|
return err
|
|
}
|
|
case SocketConfig_Disable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
|
|
if strings.HasPrefix(network, "tcp") {
|
|
switch config.Tfo {
|
|
case SocketConfig_Enable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_SERVER); err != nil {
|
|
return err
|
|
}
|
|
case SocketConfig_Disable:
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|