Chore: make tcpKeepaliveCount explicit

This commit is contained in:
xjasonlyu
2022-02-13 14:57:31 +08:00
parent 5679d15442
commit c68dd0771e

View File

@@ -20,6 +20,12 @@ const (
// of in-flight tcp connection attempts.
maxConnAttempts = 2 << 10
// tcpKeepaliveCount is the maximum number of
// TCP keep-alive probes to send before giving up
// and killing the connection if no response is
// obtained from the other end.
tcpKeepaliveCount = 9
// tcpKeepaliveIdle specifies the time a connection
// must remain idle before the first TCP keepalive
// packet is sent. Once this time is reached,
@@ -68,6 +74,10 @@ func setKeepalive(ep tcpip.Endpoint) error {
if err := ep.SetSockOpt(&interval); err != nil {
return fmt.Errorf("set keepalive interval: %s", err)
}
if err := ep.SetSockOptInt(tcpip.KeepaliveCountOption, tcpKeepaliveCount); err != nil {
return fmt.Errorf("set keepalive count: %s", err)
}
return nil
}