package net
import (
+ "os"
+ "syscall"
"time"
+ "unsafe"
)
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
}
defer fd.decref()
- // We can't actually set this per connection. Act as a noop rather than an error.
- return nil
+ // Windows expects milliseconds so round to next highest millisecond.
+ 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)
}
IOC_OUT = 0x40000000
IOC_IN = 0x80000000
+ IOC_VENDOR = 0x18000000
IOC_INOUT = IOC_IN | IOC_OUT
IOC_WS2 = 0x08000000
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
ChainLen int32
ChainEntries [MAX_PROTOCOL_CHAIN]uint32
}
+
+type TCPKeepalive struct {
+ OnOff uint32
+ Time uint32
+ Interval uint32
+}