Retro68/gcc/libgo/go/net/tcpsockopt_windows.go

33 lines
817 B
Go
Raw Normal View History

// Copyright 2009 The Go Authors. All rights reserved.
2014-09-21 17:33:12 +00:00
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package net
import (
2015-08-28 15:33:40 +00:00
"os"
"syscall"
2014-09-21 17:33:12 +00:00
"time"
2015-08-28 15:33:40 +00:00
"unsafe"
2014-09-21 17:33:12 +00:00
)
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
if err := fd.incref(); err != nil {
return err
}
defer fd.decref()
2015-08-28 15:33:40 +00:00
// The kernel expects milliseconds so round to next highest
// millisecond.
d += (time.Millisecond - time.Nanosecond)
msecs := uint32(d / time.Millisecond)
ka := syscall.TCPKeepalive{
OnOff: 1,
Time: msecs,
Interval: msecs,
}
ret := uint32(0)
size := uint32(unsafe.Sizeof(ka))
err := syscall.WSAIoctl(fd.sysfd, syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0)
2017-04-10 11:32:00 +00:00
return os.NewSyscallError("wsaioctl", err)
2014-09-21 17:33:12 +00:00
}