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