|
|
@@ -59,10 +59,16 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if config.TcpKeepAliveInterval != 0 {
|
|
|
+ if config.TcpKeepAliveInterval > 0 {
|
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
|
|
return newError("failed to set TCP_KEEPINTVL", err)
|
|
|
}
|
|
|
+ if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, int(config.TcpKeepAliveIdle)); err != nil {
|
|
|
+ return newError("failed to set TCP_KEEPIDLE", err)
|
|
|
+ }
|
|
|
+ if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
|
|
+ return newError("failed to set SO_KEEPALIVE", err)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -93,10 +99,16 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if config.TcpKeepAliveInterval != 0 {
|
|
|
+ if config.TcpKeepAliveInterval > 0 {
|
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
|
|
return newError("failed to set TCP_KEEPINTVL", err)
|
|
|
}
|
|
|
+ if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, int(config.TcpKeepAliveIdle)); err != nil {
|
|
|
+ return newError("failed to set TCP_KEEPIDLE", err)
|
|
|
+ }
|
|
|
+ if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
|
|
+ return newError("failed to set SO_KEEPALIVE", err)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|