Kaynağa Gözat

Refactor socksopts per functionality, not per build flag

tags/v2.2.8^2^2
9seconds 4 hafta önce
ebeveyn
işleme
437dacfaab

+ 20
- 0
network/v2/sockopts_congestion.go Dosyayı Görüntüle

@@ -0,0 +1,20 @@
1
+//go:build linux
2
+
3
+package network
4
+
5
+import (
6
+	"syscall"
7
+
8
+	"golang.org/x/sys/unix"
9
+)
10
+
11
+// setCongestionControl sets BBR as the TCP congestion control algorithm.
12
+// BBR provides better throughput over lossy and high-latency links compared
13
+// to the default cubic, which is especially beneficial for mobile and
14
+// home internet clients. This is best-effort: silently ignored if the
15
+// kernel does not have tcp_bbr available.
16
+func setCongestionControl(conn syscall.RawConn) {
17
+	conn.Control(func(fd uintptr) { //nolint: errcheck
18
+		unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
19
+	})
20
+}

+ 7
- 0
network/v2/sockopts_congestion_stub.go Dosyayı Görüntüle

@@ -0,0 +1,7 @@
1
+//go:build !linux
2
+
3
+package network
4
+
5
+import "syscall"
6
+
7
+func setCongestionControl(conn syscall.RawConn) {}

network/v2/sockopts_unix.go → network/v2/sockopts_reuseaddr.go Dosyayı Görüntüle

@@ -1,5 +1,4 @@
1 1
 //go:build !windows
2
-// +build !windows
3 2
 
4 3
 package network
5 4
 

network/v2/sockopts_windows.go → network/v2/sockopts_reuseaddr_stub.go Dosyayı Görüntüle

@@ -1,5 +1,4 @@
1 1
 //go:build windows
2
-// +build windows
3 2
 
4 3
 package network
5 4
 

network/v2/sockopts_linux.go → network/v2/sockopts_usertimeout.go Dosyayı Görüntüle

@@ -46,13 +46,3 @@ func setTCPUserTimeout(conn syscall.RawConn, cfg net.KeepAliveConfig) {
46 46
 		unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout.Milliseconds())) //nolint: errcheck
47 47
 	})
48 48
 }
49
-
50
-func setCongestionControl(conn syscall.RawConn) {
51
-	conn.Control(func(fd uintptr) { //nolint: errcheck
52
-		// BBR provides better throughput over lossy and high-latency links compared
53
-		// to the default cubic, which is especially beneficial for mobile and
54
-		// home internet clients. This is best-effort: silently ignored if the
55
-		// kernel does not have tcp_bbr available.
56
-		unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
57
-	})
58
-}

network/v2/sockopts_nolinux.go → network/v2/sockopts_usertimeout_stub.go Dosyayı Görüntüle

@@ -7,5 +7,4 @@ import (
7 7
 	"syscall"
8 8
 )
9 9
 
10
-func setCongestionControl(conn syscall.RawConn)                       {}
11 10
 func setTCPUserTimeout(conn syscall.RawConn, cfg net.KeepAliveConfig) {}

Loading…
İptal
Kaydet