2016-07-22 20:15:38 +02:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
2013-11-06 20:49:01 +01:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2014-06-07 00:37:27 +02:00
|
|
|
"os"
|
2017-09-14 19:11:35 +02:00
|
|
|
"runtime"
|
2014-06-07 00:37:27 +02:00
|
|
|
"syscall"
|
2013-11-06 20:49:01 +01:00
|
|
|
"time"
|
2014-06-07 00:37:27 +02:00
|
|
|
"unsafe"
|
2013-11-06 20:49:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
|
2015-01-15 01:27:56 +01:00
|
|
|
// The kernel expects milliseconds so round to next highest
|
|
|
|
// millisecond.
|
2014-06-07 00:37:27 +02:00
|
|
|
d += (time.Millisecond - time.Nanosecond)
|
2015-01-15 01:27:56 +01:00
|
|
|
msecs := uint32(d / time.Millisecond)
|
2014-06-07 00:37:27 +02:00
|
|
|
ka := syscall.TCPKeepalive{
|
|
|
|
OnOff: 1,
|
2015-01-15 01:27:56 +01:00
|
|
|
Time: msecs,
|
|
|
|
Interval: msecs,
|
2014-06-07 00:37:27 +02:00
|
|
|
}
|
|
|
|
ret := uint32(0)
|
|
|
|
size := uint32(unsafe.Sizeof(ka))
|
2017-09-14 19:11:35 +02:00
|
|
|
err := fd.pfd.WSAIoctl(syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0)
|
|
|
|
runtime.KeepAlive(fd)
|
2015-10-31 01:59:47 +01:00
|
|
|
return os.NewSyscallError("wsaioctl", err)
|
2013-11-06 20:49:01 +01:00
|
|
|
}
|