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