From 1a3d6eeca8dfdde2920b9dcca5462a9797d095fd Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sat, 13 Nov 2021 22:13:37 +0000 Subject: [PATCH] Add TCP keep alive support in Windows --- transport/internet/sockopt_windows.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/transport/internet/sockopt_windows.go b/transport/internet/sockopt_windows.go index 2c990b643..e63c7790f 100644 --- a/transport/internet/sockopt_windows.go +++ b/transport/internet/sockopt_windows.go @@ -25,6 +25,11 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil { return err } + if config.TcpKeepAliveInterval > 0 { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil { + return newError("failed to set SO_KEEPALIVE", err) + } + } } return nil @@ -35,6 +40,11 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil { return err } + if config.TcpKeepAliveInterval > 0 { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil { + return newError("failed to set SO_KEEPALIVE", err) + } + } } return nil