]> Cypherpunks repositories - gostls13.git/commitdiff
net: harmonize the time units used for TCP keep-alive on DragonFly and other UNIX...
authorAndy Pan <panjf2000@gmail.com>
Tue, 20 Feb 2024 08:17:06 +0000 (16:17 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 21 Feb 2024 00:55:03 +0000 (00:55 +0000)
Follows up CL 542275

Fixes #65809

Change-Id: Iba01efb4ff0fbb7a67840875322f0338337ebb78
Reviewed-on: https://go-review.googlesource.com/c/go/+/565315
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/net/tcpconn_keepalive_dragonfly_test.go [deleted file]
src/net/tcpconn_keepalive_unix_test.go
src/net/tcpsockopt_dragonfly.go [deleted file]
src/net/tcpsockopt_unix.go

diff --git a/src/net/tcpconn_keepalive_dragonfly_test.go b/src/net/tcpconn_keepalive_dragonfly_test.go
deleted file mode 100644 (file)
index 61b073b..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2023 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.
-
-//go:build dragonfly
-
-package net
-
-import (
-       "syscall"
-       "testing"
-       "time"
-)
-
-func getCurrentKeepAliveSettings(fd int) (cfg KeepAliveConfig, err error) {
-       tcpKeepAlive, err := syscall.GetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_KEEPALIVE)
-       if err != nil {
-               return
-       }
-       tcpKeepAliveIdle, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE)
-       if err != nil {
-               return
-       }
-       tcpKeepAliveInterval, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL)
-       if err != nil {
-               return
-       }
-       tcpKeepAliveCount, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT)
-       if err != nil {
-               return
-       }
-       cfg = KeepAliveConfig{
-               Enable:   tcpKeepAlive != 0,
-               Idle:     time.Duration(tcpKeepAliveIdle) * time.Millisecond,
-               Interval: time.Duration(tcpKeepAliveInterval) * time.Millisecond,
-               Count:    tcpKeepAliveCount,
-       }
-       return
-}
-
-func verifyKeepAliveSettings(t *testing.T, fd int, oldCfg, cfg KeepAliveConfig) {
-       if cfg.Idle == 0 {
-               cfg.Idle = defaultTCPKeepAliveIdle
-       }
-       if cfg.Interval == 0 {
-               cfg.Interval = defaultTCPKeepAliveInterval
-       }
-       if cfg.Count == 0 {
-               cfg.Count = defaultTCPKeepAliveCount
-       }
-       if cfg.Idle == -1 {
-               cfg.Idle = oldCfg.Idle
-       }
-       if cfg.Interval == -1 {
-               cfg.Interval = oldCfg.Interval
-       }
-       if cfg.Count == -1 {
-               cfg.Count = oldCfg.Count
-       }
-
-       tcpKeepAlive, err := syscall.GetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_KEEPALIVE)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if (tcpKeepAlive != 0) != cfg.Enable {
-               t.Fatalf("SO_KEEPALIVE: got %t; want %t", tcpKeepAlive != 0, cfg.Enable)
-       }
-
-       tcpKeepAliveIdle, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if time.Duration(tcpKeepAliveIdle)*time.Millisecond != cfg.Idle {
-               t.Fatalf("TCP_KEEPIDLE: got %dms; want %v", tcpKeepAliveIdle, cfg.Idle)
-       }
-
-       tcpKeepAliveInterval, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if time.Duration(tcpKeepAliveInterval)*time.Millisecond != cfg.Interval {
-               t.Fatalf("TCP_KEEPINTVL: got %dms; want %v", tcpKeepAliveInterval, cfg.Interval)
-       }
-
-       tcpKeepAliveCount, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if tcpKeepAliveCount != cfg.Count {
-               t.Fatalf("TCP_KEEPCNT: got %d; want %d", tcpKeepAliveCount, cfg.Count)
-       }
-}
index 8f74b6edaa5c3a9b07f5ef847027376cd048817e..74555c9c5b65bcb0d256be19bceb0074329b6918 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || freebsd || linux || netbsd
+//go:build aix || dragonfly || freebsd || linux || netbsd
 
 package net
 
diff --git a/src/net/tcpsockopt_dragonfly.go b/src/net/tcpsockopt_dragonfly.go
deleted file mode 100644 (file)
index 612baae..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2009 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.
-
-package net
-
-import (
-       "runtime"
-       "syscall"
-       "time"
-)
-
-func setKeepAliveIdle(fd *netFD, d time.Duration) error {
-       if d == 0 {
-               d = defaultTCPKeepAliveIdle
-       } else if d < 0 {
-               return nil
-       }
-
-       // The kernel expects milliseconds so round to next highest
-       // millisecond.
-       msecs := int(roundDurationUp(d, time.Millisecond))
-       err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, msecs)
-       runtime.KeepAlive(fd)
-       return wrapSyscallError("setsockopt", err)
-}
-
-func setKeepAliveInterval(fd *netFD, d time.Duration) error {
-       if d == 0 {
-               d = defaultTCPKeepAliveInterval
-       } else if d < 0 {
-               return nil
-       }
-
-       // The kernel expects milliseconds so round to next highest
-       // millisecond.
-       msecs := int(roundDurationUp(d, time.Millisecond))
-       err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, msecs)
-       runtime.KeepAlive(fd)
-       return wrapSyscallError("setsockopt", err)
-}
-
-func setKeepAliveCount(fd *netFD, n int) error {
-       if n == 0 {
-               n = defaultTCPKeepAliveCount
-       } else if n < 0 {
-               return nil
-       }
-
-       err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT, n)
-       runtime.KeepAlive(fd)
-       return wrapSyscallError("setsockopt", err)
-}
index eb01663c528be6f81b57c7d1602a99ec661684a1..f3526e4962181f9bb5e3562c631a26a2f5f2f60e 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || freebsd || linux || netbsd
+//go:build aix || dragonfly || freebsd || linux || netbsd
 
 package net