tcpsockopt_solaris.go 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2015 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. "runtime"
  7. "syscall"
  8. "time"
  9. )
  10. func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
  11. // The kernel expects milliseconds so round to next highest
  12. // millisecond.
  13. msecs := int(roundDurationUp(d, time.Millisecond))
  14. // Normally we'd do
  15. // syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs)
  16. // here, but we can't because Solaris does not have TCP_KEEPINTVL.
  17. // Solaris has TCP_KEEPALIVE_ABORT_THRESHOLD, but it's not the same
  18. // thing, it refers to the total time until aborting (not between
  19. // probes), and it uses an exponential backoff algorithm instead of
  20. // waiting the same time between probes. We can't hope for the best
  21. // and do it anyway, like on Darwin, because Solaris might eventually
  22. // allocate a constant with a different meaning for the value of
  23. // TCP_KEEPINTVL on illumos.
  24. err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE_THRESHOLD, msecs)
  25. runtime.KeepAlive(fd)
  26. return wrapSyscallError("setsockopt", err)
  27. }