github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/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 "syscall" 10 "time" 11 "unsafe" 12 ) 13 14 func setKeepAlivePeriod(fd *netFD, d time.Duration) error { 15 if err := fd.incref(); err != nil { 16 return err 17 } 18 defer fd.decref() 19 // The kernel expects milliseconds so round to next highest 20 // millisecond. 21 d += (time.Millisecond - time.Nanosecond) 22 msecs := uint32(d / time.Millisecond) 23 ka := syscall.TCPKeepalive{ 24 OnOff: 1, 25 Time: msecs, 26 Interval: msecs, 27 } 28 ret := uint32(0) 29 size := uint32(unsafe.Sizeof(ka)) 30 err := syscall.WSAIoctl(fd.sysfd, syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0) 31 return os.NewSyscallError("wsaioctl", err) 32 }