1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 17:27:23 -05:00

Add TCP keep alive support in Windows

This commit is contained in:
ValdikSS 2021-11-13 22:13:37 +00:00 committed by Xiaokang Wang
parent dc709f56dd
commit 1a3d6eeca8

View File

@ -25,6 +25,11 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil { if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
return err 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 return nil
@ -35,6 +40,11 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil { if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
return err 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 return nil