tcpsockopt_unix.go 730 B

123456789101112131415161718192021222324
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build aix || freebsd || hurd || linux || netbsd
  5. package net
  6. import (
  7. "runtime"
  8. "syscall"
  9. "time"
  10. )
  11. func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
  12. // The kernel expects seconds so round to next highest second.
  13. secs := int(roundDurationUp(d, time.Second))
  14. if err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs); err != nil {
  15. return wrapSyscallError("setsockopt", err)
  16. }
  17. err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, secs)
  18. runtime.KeepAlive(fd)
  19. return wrapSyscallError("setsockopt", err)
  20. }