github.com/xraypb/xray-core@v1.6.6/transport/internet/sockopt_windows.go (about) 1 package internet 2 3 import ( 4 "syscall" 5 ) 6 7 const ( 8 TCP_FASTOPEN = 15 9 ) 10 11 func setTFO(fd syscall.Handle, tfo int) error { 12 if tfo > 0 { 13 tfo = 1 14 } 15 if tfo >= 0 { 16 if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); 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.ParseTFOValue()); 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 } else if config.TcpKeepAliveIdle < 0 { 33 if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 0); err != nil { 34 return newError("failed to unset SO_KEEPALIVE", err) 35 } 36 } 37 } 38 39 return nil 40 } 41 42 func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error { 43 if isTCPSocket(network) { 44 if err := setTFO(syscall.Handle(fd), config.ParseTFOValue()); err != nil { 45 return err 46 } 47 if config.TcpKeepAliveIdle > 0 { 48 if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil { 49 return newError("failed to set SO_KEEPALIVE", err) 50 } 51 } else if config.TcpKeepAliveIdle < 0 { 52 if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 0); err != nil { 53 return newError("failed to unset SO_KEEPALIVE", err) 54 } 55 } 56 } 57 58 return nil 59 } 60 61 func bindAddr(fd uintptr, ip []byte, port uint32) error { 62 return nil 63 } 64 65 func setReuseAddr(fd uintptr) error { 66 return nil 67 } 68 69 func setReusePort(fd uintptr) error { 70 return nil 71 }