From 02c8b04230fc2fb6636a1fee31d06d4c7f8c5d4e Mon Sep 17 00:00:00 2001 From: Huang-Huang Bao Date: Mon, 9 May 2022 04:31:01 +0800 Subject: [PATCH] Fix: correct TCP keepalive sockopt names for darwin Fixes: a0eb84dbff80edad16c9b4c385e7487de5f2099a --- transport/internet/sockopt_darwin.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/transport/internet/sockopt_darwin.go b/transport/internet/sockopt_darwin.go index c0b65fda5..200b6abf8 100644 --- a/transport/internet/sockopt_darwin.go +++ b/transport/internet/sockopt_darwin.go @@ -24,18 +24,18 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf } } - if config.TcpKeepAliveIdle > 0 { - if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPALIVE, int(config.TcpKeepAliveInterval)); err != nil { + if config.TcpKeepAliveInterval > 0 { + if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil { return newError("failed to set TCP_KEEPINTVL").Base(err) } } - if config.TcpKeepAliveInterval > 0 { - if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPINTVL, int(config.TcpKeepAliveIdle)); err != nil { - return newError("failed to set TCP_KEEPIDLE").Base(err) + if config.TcpKeepAliveIdle > 0 { + if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPALIVE, int(config.TcpKeepAliveIdle)); err != nil { + return newError("failed to set TCP_KEEPALIVE (TCP keepalive idle time on Darwin)").Base(err) } } - if config.TcpKeepAliveIdle > 0 || config.TcpKeepAliveInterval > 0 { + if config.TcpKeepAliveInterval > 0 || config.TcpKeepAliveIdle > 0 { if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_KEEPALIVE, 1); err != nil { return newError("failed to set SO_KEEPALIVE").Base(err) } @@ -69,17 +69,17 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) return err } } - if config.TcpKeepAliveIdle > 0 { - if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPALIVE, int(config.TcpKeepAliveInterval)); err != nil { + if config.TcpKeepAliveInterval > 0 { + if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil { return newError("failed to set TCP_KEEPINTVL").Base(err) } } - if config.TcpKeepAliveInterval > 0 { - if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.SO_KEEPALIVE, int(config.TcpKeepAliveIdle)); err != nil { - return newError("failed to set TCP_KEEPIDLE").Base(err) + if config.TcpKeepAliveIdle > 0 { + if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_KEEPALIVE, int(config.TcpKeepAliveIdle)); err != nil { + return newError("failed to set TCP_KEEPALIVE (TCP keepalive idle time on Darwin)").Base(err) } } - if config.TcpKeepAliveIdle > 0 || config.TcpKeepAliveInterval > 0 { + if config.TcpKeepAliveInterval > 0 || config.TcpKeepAliveIdle > 0 { if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_KEEPALIVE, 1); err != nil { return newError("failed to set SO_KEEPALIVE").Base(err) }