// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// TCP socket options for darwin
-
package net
import (
"time"
)
-// Set keep alive period.
+const sysTCP_KEEPINTVL = 0x101
+
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
if err := fd.incref(); err != nil {
return err
}
defer fd.decref()
-
// The kernel expects seconds so round to next highest second.
d += (time.Second - time.Nanosecond)
secs := int(d.Seconds())
-
+ switch err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, sysTCP_KEEPINTVL, secs); err {
+ case nil, syscall.ENOPROTOOPT: // OS X 10.7 and earlier don't support this option
+ default:
+ return os.NewSyscallError("setsockopt", err)
+ }
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE, secs))
}
"time"
)
-// Set keep alive period.
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
if err := fd.incref(); err != nil {
return err
}
defer fd.decref()
-
- // The kernel expects milliseconds so round to next highest millisecond.
+ // The kernel expects milliseconds so round to next highest
+ // millisecond.
d += (time.Millisecond - time.Nanosecond)
- msecs := int(time.Duration(d.Nanoseconds()) / time.Millisecond)
-
- err := os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, msecs))
- if err != nil {
- return err
+ msecs := int(d / time.Millisecond)
+ if err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, msecs); err != nil {
+ return os.NewSyscallError("setsockopt", err)
}
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, msecs))
}
+++ /dev/null
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// TCP socket options for solaris
-
-package net
-
-import (
- "os"
- "syscall"
- "time"
-)
-
-// Set keep alive period.
-func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
- if err := fd.incref(); err != nil {
- return err
- }
- defer fd.decref()
-
- // The kernel expects seconds so round to next highest second.
- d += (time.Second - time.Nanosecond)
- secs := int(d.Seconds())
-
- return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.SO_KEEPALIVE, secs))
-}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build nacl openbsd
+
package net
import (
)
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
- // OpenBSD has no user-settable per-socket TCP keepalive
- // options.
- return syscall.EPROTONOSUPPORT
+ // NaCl and OpenBSD have no user-settable per-socket TCP
+ // keepalive options.
+ return syscall.ENOPROTOOPT
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build freebsd linux nacl netbsd
+// +build freebsd linux netbsd solaris
package net
"time"
)
-// Set keep alive period.
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
if err := fd.incref(); err != nil {
return err
}
defer fd.decref()
-
// The kernel expects seconds so round to next highest second.
d += (time.Second - time.Nanosecond)
secs := int(d.Seconds())
-
- err := os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs))
- if err != nil {
- return err
+ if err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs); err != nil {
+ return os.NewSyscallError("setsockopt", err)
}
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, secs))
}
// 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 (
return err
}
defer fd.decref()
-
- // Windows expects milliseconds so round to next highest millisecond.
+ // The kernel expects milliseconds so round to next highest
+ // millisecond.
d += (time.Millisecond - time.Nanosecond)
- millis := uint32(d / time.Millisecond)
+ msecs := uint32(d / time.Millisecond)
ka := syscall.TCPKeepalive{
OnOff: 1,
- Time: millis,
- Interval: millis,
+ Time: msecs,
+ Interval: msecs,
}
ret := uint32(0)
size := uint32(unsafe.Sizeof(ka))