tcpsockopt_dragonfly.go 784 B

123456789101112131415161718192021222324252627
  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. package net
  5. import (
  6. "os"
  7. "syscall"
  8. "time"
  9. )
  10. func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
  11. if err := fd.incref(); err != nil {
  12. return err
  13. }
  14. defer fd.decref()
  15. // The kernel expects milliseconds so round to next highest
  16. // millisecond.
  17. d += (time.Millisecond - time.Nanosecond)
  18. msecs := int(d / time.Millisecond)
  19. if err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, msecs); err != nil {
  20. return os.NewSyscallError("setsockopt", err)
  21. }
  22. return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, msecs))
  23. }