mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
package internet
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"v2ray.com/core/common/net"
|
|
)
|
|
|
|
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) {
|
|
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 isTCPSocket(network) {
|
|
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
|
|
}
|
|
|
|
func bindAddr(fd uintptr, address net.Address, port net.Port) error {
|
|
return nil
|
|
}
|