github.com/v2fly/v2ray-core/v4@v4.45.2/transport/internet/sockopt_windows.go (about) 1 package internet 2 3 import "syscall" 4 5 const ( 6 TCP_FASTOPEN = 15 // nolint: golint,stylecheck 7 ) 8 9 func setTFO(fd syscall.Handle, settings SocketConfig_TCPFastOpenState) error { 10 switch settings { 11 case SocketConfig_Enable: 12 if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, 1); err != nil { 13 return err 14 } 15 case SocketConfig_Disable: 16 if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil { 17 return err 18 } 19 } 20 return nil 21 } 22 23 func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error { 24 if isTCPSocket(network) { 25 if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil { 26 return err 27 } 28 if config.TcpKeepAliveIdle > 0 { 29 if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil { 30 return newError("failed to set SO_KEEPALIVE", err) 31 } 32 } 33 } 34 35 return nil 36 } 37 38 func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error { 39 if isTCPSocket(network) { 40 if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil { 41 return err 42 } 43 if config.TcpKeepAliveIdle > 0 { 44 if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil { 45 return newError("failed to set SO_KEEPALIVE", err) 46 } 47 } 48 } 49 50 return nil 51 } 52 53 func bindAddr(fd uintptr, ip []byte, port uint32) error { 54 return nil 55 } 56 57 func setReuseAddr(fd uintptr) error { 58 return nil 59 } 60 61 func setReusePort(fd uintptr) error { 62 return nil 63 }