Xray-core/transport/internet/sockopt_darwin.go

59 lines
1.3 KiB
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package internet
import (
"syscall"
)
const (
// TCP_FASTOPEN is the socket option on darwin for TCP fast open.
TCP_FASTOPEN = 0x105
// TCP_FASTOPEN_SERVER is the value to enable TCP fast open on darwin for server connections.
TCP_FASTOPEN_SERVER = 0x01
// TCP_FASTOPEN_CLIENT is the value to enable TCP fast open on darwin for client connections.
TCP_FASTOPEN_CLIENT = 0x02
)
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
if isTCPSocket(network) {
2021-03-30 16:42:02 +00:00
tfo := config.ParseTFOValue()
2021-03-06 14:45:12 +00:00
if tfo > 0 {
tfo = TCP_FASTOPEN_CLIENT
}
if tfo >= 0 {
2021-03-30 16:42:02 +00:00
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
2020-11-25 11:01:53 +00:00
return err
}
}
}
return nil
}
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
if isTCPSocket(network) {
2021-03-30 16:42:02 +00:00
tfo := config.ParseTFOValue()
2021-03-06 14:45:12 +00:00
if tfo > 0 {
tfo = TCP_FASTOPEN_SERVER
}
if tfo >= 0 {
2021-03-30 16:42:02 +00:00
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
2020-11-25 11:01:53 +00:00
return err
}
}
}
return nil
}
func bindAddr(fd uintptr, address []byte, port uint32) error {
return nil
}
func setReuseAddr(fd uintptr) error {
return nil
}
func setReusePort(fd uintptr) error {
return nil
}