}
return ln, nil
}
+
+// roundDurationUp rounds d to the next multiple of to.
+func roundDurationUp(d time.Duration, to time.Duration) time.Duration {
+ return (d + to - 1) / to
+}
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
// The kernel expects seconds so round to next highest second.
- d += (time.Second - time.Nanosecond)
- secs := int(d.Seconds())
+ secs := int(roundDurationUp(d, time.Second))
if err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, sysTCP_KEEPINTVL, secs); err != nil {
return wrapSyscallError("setsockopt", err)
}
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
// The kernel expects milliseconds so round to next highest
// millisecond.
- d += (time.Millisecond - time.Nanosecond)
- msecs := int(d / time.Millisecond)
+ msecs := int(roundDurationUp(d, time.Millisecond))
if err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, msecs); err != nil {
return wrapSyscallError("setsockopt", err)
}
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
// The kernel expects milliseconds so round to next highest
// millisecond.
- d += (time.Millisecond - time.Nanosecond)
- msecs := int(d / time.Millisecond)
+ msecs := int(roundDurationUp(d, time.Millisecond))
// Normally we'd do
// syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs)
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
// The kernel expects seconds so round to next highest second.
- d += (time.Second - time.Nanosecond)
- secs := int(d.Seconds())
+ secs := int(roundDurationUp(d, time.Second))
if err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, secs); err != nil {
return wrapSyscallError("setsockopt", err)
}
func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
// The kernel expects milliseconds so round to next highest
// millisecond.
- d += (time.Millisecond - time.Nanosecond)
- msecs := uint32(d / time.Millisecond)
+ msecs := uint32(roundDurationUp(d, time.Millisecond))
ka := syscall.TCPKeepalive{
OnOff: 1,
Time: msecs,