Skip to content

Commit 3f007b5

Browse files
committed
exit,base,auto: disable keep alives if not req
1 parent 9ed0b64 commit 3f007b5

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

intra/core/sockopt.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,22 @@ func SetTimeoutSockOpt(c MinConn, timeoutms int) bool {
6565
return false
6666
}
6767

68+
func DisableKeepAlive(c MinConn) bool {
69+
if tc, ok := c.(*net.TCPConn); ok {
70+
tc.SetKeepAlive(false)
71+
return true
72+
}
73+
return false
74+
}
75+
6876
// SetKeepAliveConfigSockOpt sets for a TCP connection, SO_KEEPALIVE,
6977
// TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT, TCP_USER_TIMEOUT.
7078
// args is optional, and should be in the order of idle, interval, count.
7179
func SetKeepAliveConfigSockOpt(c MinConn, args ...int) (ok bool) {
72-
var tc *net.TCPConn
73-
if tc, ok = c.(*net.TCPConn); ok {
74-
id := conn2str(tc)
80+
if pc, ok := c.(PoolableConn); ok {
81+
id := conn2str(c)
7582

76-
rawConn, err := tc.SyscallConn()
83+
rawConn, err := pc.SyscallConn()
7784
if err != nil || rawConn == nil {
7885
ok = false
7986
return ok

intra/ipn/auto.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,5 +536,8 @@ func maybeKeepAlive(c net.Conn) {
536536
if settings.GetDialerOpts().LowerKeepAlive {
537537
// adjust TCP keepalive config if c is a TCPConn
538538
core.SetKeepAliveConfigSockOpt(c)
539+
} else {
540+
// disable TCP keepalive config if c is a TCPConn
541+
core.DisableKeepAlive(c)
539542
}
540543
}

0 commit comments

Comments
 (0)