tcpsockopt_windows.go 741 B

1234567891011121314151617181920212223242526272829
  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. "runtime"
  8. "syscall"
  9. "time"
  10. "unsafe"
  11. )
  12. func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
  13. // The kernel expects milliseconds so round to next highest
  14. // millisecond.
  15. msecs := uint32(roundDurationUp(d, time.Millisecond))
  16. ka := syscall.TCPKeepalive{
  17. OnOff: 1,
  18. Time: msecs,
  19. Interval: msecs,
  20. }
  21. ret := uint32(0)
  22. size := uint32(unsafe.Sizeof(ka))
  23. err := fd.pfd.WSAIoctl(syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0)
  24. runtime.KeepAlive(fd)
  25. return os.NewSyscallError("wsaioctl", err)
  26. }