2016-07-22 18:15:38 +00:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
2013-11-06 19:49:01 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-07-30 14:28:58 -07:00
|
|
|
//go:build aix || freebsd || hurd || linux || netbsd
|
2013-11-06 19:49:01 +00:00
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2017-09-14 17:11:35 +00:00
|
|
|
"runtime"
|
2013-11-06 19:49:01 +00:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
|
|
|
|
// The kernel expects seconds so round to next highest second.
|
2020-01-02 15:05:27 -08:00
|
|
|
secs := int(roundDurationUp(d, time.Second))
|
2017-09-14 17:11:35 +00:00
|
|
|
if err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs); err != nil {
|
|
|
|
return wrapSyscallError("setsockopt", err)
|
2013-11-06 19:49:01 +00:00
|
|
|
}
|
2017-09-14 17:11:35 +00:00
|
|
|
err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, secs)
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return wrapSyscallError("setsockopt", err)
|
2013-11-06 19:49:01 +00:00
|
|
|
}
|