diff options
Diffstat (limited to 'libgo/go/net/tcpsockopt_windows.go')
-rw-r--r-- | libgo/go/net/tcpsockopt_windows.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/libgo/go/net/tcpsockopt_windows.go b/libgo/go/net/tcpsockopt_windows.go index 0bf4312f24..091f5233f2 100644 --- a/libgo/go/net/tcpsockopt_windows.go +++ b/libgo/go/net/tcpsockopt_windows.go @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// TCP socket options for windows - package net import ( + "os" + "syscall" "time" + "unsafe" ) func setKeepAlivePeriod(fd *netFD, d time.Duration) error { @@ -15,7 +16,17 @@ func setKeepAlivePeriod(fd *netFD, d time.Duration) error { return err } defer fd.decref() - - // We can't actually set this per connection. Act as a noop rather than an error. - return nil + // 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) + return os.NewSyscallError("WSAIoctl", err) } |