Commit 5277b90e authored by Nicholas Katsaros's avatar Nicholas Katsaros Committed by Alex Brainman

net: add SetKeepAlivePeriod for windows

R=golang-codereviews, alex.brainman, bradfitz, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/11393043
parent d155f6a3
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
package net package net
import ( import (
"os"
"syscall"
"time" "time"
"unsafe"
) )
func setKeepAlivePeriod(fd *netFD, d time.Duration) error { func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
...@@ -16,6 +19,16 @@ func setKeepAlivePeriod(fd *netFD, d time.Duration) error { ...@@ -16,6 +19,16 @@ func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
} }
defer fd.decref() defer fd.decref()
// We can't actually set this per connection. Act as a noop rather than an error. // Windows expects milliseconds so round to next highest millisecond.
return nil d += (time.Millisecond - time.Nanosecond)
millis := uint32(d / time.Millisecond)
ka := syscall.TCPKeepalive{
OnOff: 1,
Time: millis,
Interval: millis,
}
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)
return os.NewSyscallError("WSAIoctl", err)
} }
...@@ -512,9 +512,11 @@ const ( ...@@ -512,9 +512,11 @@ const (
IOC_OUT = 0x40000000 IOC_OUT = 0x40000000
IOC_IN = 0x80000000 IOC_IN = 0x80000000
IOC_VENDOR = 0x18000000
IOC_INOUT = IOC_IN | IOC_OUT IOC_INOUT = IOC_IN | IOC_OUT
IOC_WS2 = 0x08000000 IOC_WS2 = 0x08000000
SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6 SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4
// cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460 // cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
...@@ -1031,3 +1033,9 @@ type WSAProtocolChain struct { ...@@ -1031,3 +1033,9 @@ type WSAProtocolChain struct {
ChainLen int32 ChainLen int32
ChainEntries [MAX_PROTOCOL_CHAIN]uint32 ChainEntries [MAX_PROTOCOL_CHAIN]uint32
} }
type TCPKeepalive struct {
OnOff uint32
Time uint32
Interval uint32
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment