github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/sockopt_darwin.go (about) 1 package internet 2 3 import ( 4 "syscall" 5 ) 6 7 const ( 8 // TCP_FASTOPEN is the socket option on darwin for TCP fast open. 9 TCP_FASTOPEN = 0x105 10 // TCP_FASTOPEN_SERVER is the value to enable TCP fast open on darwin for server connections. 11 TCP_FASTOPEN_SERVER = 0x01 12 // TCP_FASTOPEN_CLIENT is the value to enable TCP fast open on darwin for client connections. 13 TCP_FASTOPEN_CLIENT = 0x02 14 ) 15 16 func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error { 17 if isTCPSocket(network) { 18 switch config.Tfo { 19 case SocketConfig_Enable: 20 if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_CLIENT); err != nil { 21 return err 22 } 23 case SocketConfig_Disable: 24 if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil { 25 return err 26 } 27 } 28 } 29 30 return nil 31 } 32 33 func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error { 34 if isTCPSocket(network) { 35 switch config.Tfo { 36 case SocketConfig_Enable: 37 if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_SERVER); err != nil { 38 return err 39 } 40 case SocketConfig_Disable: 41 if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil { 42 return err 43 } 44 } 45 } 46 47 return nil 48 } 49 50 func bindAddr(fd uintptr, address []byte, port uint32) error { 51 return nil 52 } 53 54 func setReuseAddr(fd uintptr) error { 55 return nil 56 } 57 58 func setReusePort(fd uintptr) error { 59 return nil 60 }