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"
|
|
|
|
"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 {
|
|
|
|
if err := fd.incref(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fd.decref()
|
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))
|
|
|
|
err := syscall.WSAIoctl(fd.sysfd, syscall.SIO_KEEPALIVE_VALS, (*byte)(unsafe.Pointer(&ka)), size, nil, 0, &ret, nil, 0)
|
2015-10-31 01:59:47 +01:00
|
|
|
return os.NewSyscallError("wsaioctl", err)
|
2013-11-06 20:49:01 +01:00
|
|
|
}
|