mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-27 01:13:01 +00:00
55 lines
928 B
Go
55 lines
928 B
Go
package internet
|
|
|
|
import (
|
|
"syscall"
|
|
)
|
|
|
|
const (
|
|
TCP_FASTOPEN = 15
|
|
)
|
|
|
|
func setTFO(fd syscall.Handle, tfo int32) error {
|
|
if tfo > 0 {
|
|
tfo = 1
|
|
}
|
|
if tfo >= 0 {
|
|
if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, int(tfo)); 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
|
|
}
|
|
|
|
func setReuseAddr(fd uintptr) error {
|
|
return nil
|
|
}
|
|
|
|
func setReusePort(fd uintptr) error {
|
|
return nil
|
|
}
|