1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 19:45:24 +00:00
v2fly/transport/internet/sockopt_darwin.go

52 lines
1.2 KiB
Go
Raw Normal View History

2018-09-10 12:39:57 +00:00
package internet
import (
"syscall"
2018-09-17 13:12:58 +00:00
"v2ray.com/core/common/net"
2018-09-10 12:39:57 +00:00
)
const (
2018-09-10 19:47:24 +00:00
TCP_FASTOPEN = 0x105
TCP_FASTOPEN_SERVER = 0x01
TCP_FASTOPEN_CLIENT = 0x02
2018-09-10 12:39:57 +00:00
)
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
2018-09-11 08:03:26 +00:00
if isTCPSocket(network) {
2018-09-10 12:39:57 +00:00
switch config.Tfo {
case SocketConfig_Enable:
2018-09-10 19:47:24 +00:00
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_CLIENT); err != nil {
2018-09-10 12:39:57 +00:00
return err
}
case SocketConfig_Disable:
2018-09-10 19:08:59 +00:00
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
2018-09-10 12:39:57 +00:00
return err
}
}
}
return nil
}
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
2018-09-11 08:03:26 +00:00
if isTCPSocket(network) {
2018-09-10 12:39:57 +00:00
switch config.Tfo {
case SocketConfig_Enable:
2018-09-10 19:47:24 +00:00
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_SERVER); err != nil {
2018-09-10 12:39:57 +00:00
return err
}
case SocketConfig_Disable:
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
return err
}
}
}
return nil
}
2018-09-17 13:12:58 +00:00
func bindAddr(fd uintptr, address net.Address, port net.Port) error {
return nil
}