Browse Source

Add TCP keep alive support in Windows

ValdikSS 4 years ago
parent
commit
3b02e7d75e
1 changed files with 10 additions and 0 deletions
  1. 10 0
      transport/internet/sockopt_windows.go

+ 10 - 0
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