mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 00:50:06 +08:00
chore: decrease direct using *net.TCPConn
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 1s
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 1s
This commit is contained in:
parent
dbb5b7db1c
commit
8085c68b6d
@ -59,7 +59,7 @@ func SetNetListenConfig(lc *net.ListenConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TCPKeepAlive(c net.Conn) {
|
func TCPKeepAlive(c net.Conn) {
|
||||||
if tcp, ok := c.(*net.TCPConn); ok && tcp != nil {
|
if tcp, ok := c.(TCPConn); ok && tcp != nil {
|
||||||
tcpKeepAlive(tcp)
|
tcpKeepAlive(tcp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,18 @@
|
|||||||
|
|
||||||
package keepalive
|
package keepalive
|
||||||
|
|
||||||
import "net"
|
import (
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
func tcpKeepAlive(tcp *net.TCPConn) {
|
type TCPConn interface {
|
||||||
|
net.Conn
|
||||||
|
SetKeepAlive(keepalive bool) error
|
||||||
|
SetKeepAlivePeriod(d time.Duration) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func tcpKeepAlive(tcp TCPConn) {
|
||||||
if DisableKeepAlive() {
|
if DisableKeepAlive() {
|
||||||
_ = tcp.SetKeepAlive(false)
|
_ = tcp.SetKeepAlive(false)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -4,6 +4,12 @@ package keepalive
|
|||||||
|
|
||||||
import "net"
|
import "net"
|
||||||
|
|
||||||
|
type TCPConn interface {
|
||||||
|
net.Conn
|
||||||
|
SetKeepAlive(keepalive bool) error
|
||||||
|
SetKeepAliveConfig(config net.KeepAliveConfig) error
|
||||||
|
}
|
||||||
|
|
||||||
func keepAliveConfig() net.KeepAliveConfig {
|
func keepAliveConfig() net.KeepAliveConfig {
|
||||||
config := net.KeepAliveConfig{
|
config := net.KeepAliveConfig{
|
||||||
Enable: true,
|
Enable: true,
|
||||||
@ -18,7 +24,7 @@ func keepAliveConfig() net.KeepAliveConfig {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func tcpKeepAlive(tcp *net.TCPConn) {
|
func tcpKeepAlive(tcp TCPConn) {
|
||||||
if DisableKeepAlive() {
|
if DisableKeepAlive() {
|
||||||
_ = tcp.SetKeepAlive(false)
|
_ = tcp.SetKeepAlive(false)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user