github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/go/src/net/tcpsockopt_windows.go (about) 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 5 package net 6 7 import ( 8 "os" 9 "runtime" 10 "syscall" 11 "time" 12 "unsafe" 13 ) 14 15 func setKeepAlivePeriod(fd *netFD, d time.Duration) error { 16 // The kernel expects milliseconds so round to next highest 17 // millisecond. 18 msecs := uint32(roundDurationUp(d, time.Millisecond)) 19 ka := syscall.TCPKeepalive{ 20 OnOff: 1, 21 Time: msecs, 22 Interval: msecs, 23 } 24 ret := uint32(0) 25 size := uint32(unsafe.Sizeof(ka)) 26 err := fd.pfd.WSAIoctl(syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0) 27 runtime.KeepAlive(fd) 28 return os.NewSyscallError("wsaioctl", err) 29 }