mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 20:34:02 +03:00
Refactor socksopts per functionality, not per build flag
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
// setCongestionControl sets BBR as the TCP congestion control algorithm.
|
||||||
|
// BBR provides better throughput over lossy and high-latency links compared
|
||||||
|
// to the default cubic, which is especially beneficial for mobile and
|
||||||
|
// home internet clients. This is best-effort: silently ignored if the
|
||||||
|
// kernel does not have tcp_bbr available.
|
||||||
|
func setCongestionControl(conn syscall.RawConn) {
|
||||||
|
conn.Control(func(fd uintptr) { //nolint: errcheck
|
||||||
|
unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package network
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func setCongestionControl(conn syscall.RawConn) {}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !windows
|
//go:build !windows
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package network
|
package network
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build windows
|
//go:build windows
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package network
|
package network
|
||||||
|
|
||||||
@@ -46,13 +46,3 @@ func setTCPUserTimeout(conn syscall.RawConn, cfg net.KeepAliveConfig) {
|
|||||||
unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout.Milliseconds())) //nolint: errcheck
|
unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout.Milliseconds())) //nolint: errcheck
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCongestionControl(conn syscall.RawConn) {
|
|
||||||
conn.Control(func(fd uintptr) { //nolint: errcheck
|
|
||||||
// BBR provides better throughput over lossy and high-latency links compared
|
|
||||||
// to the default cubic, which is especially beneficial for mobile and
|
|
||||||
// home internet clients. This is best-effort: silently ignored if the
|
|
||||||
// kernel does not have tcp_bbr available.
|
|
||||||
unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -7,5 +7,4 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setCongestionControl(conn syscall.RawConn) {}
|
|
||||||
func setTCPUserTimeout(conn syscall.RawConn, cfg net.KeepAliveConfig) {}
|
func setTCPUserTimeout(conn syscall.RawConn, cfg net.KeepAliveConfig) {}
|
||||||
Reference in New Issue
Block a user