mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 21:31:16 +08:00
Improve: Better handling of TCP connections
This commit is contained in:
parent
a5f2bd3152
commit
f4c51cdb0e
@ -36,7 +36,7 @@ func (d *Direct) Generator(addr *C.Addr) (adapter C.ProxyAdapter, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.(*net.TCPConn).SetKeepAlive(true)
|
||||
tcpKeepAlive(c)
|
||||
return &DirectAdapter{conn: c}, nil
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ func (ss *ShadowSocks) Generator(addr *C.Addr) (adapter C.ProxyAdapter, err erro
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s connect error", ss.server)
|
||||
}
|
||||
c.(*net.TCPConn).SetKeepAlive(true)
|
||||
tcpKeepAlive(c)
|
||||
c = ss.cipher.StreamConn(c)
|
||||
_, err = c.Write(serializesSocksAddr(addr))
|
||||
return &ShadowsocksAdapter{conn: c}, err
|
||||
|
@ -44,8 +44,7 @@ func (ss *Socks5) Generator(addr *C.Addr) (adapter C.ProxyAdapter, err error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s connect error", ss.addr)
|
||||
}
|
||||
c.(*net.TCPConn).SetKeepAlive(true)
|
||||
|
||||
tcpKeepAlive(c)
|
||||
if err := ss.sharkHand(addr, c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -84,3 +84,10 @@ func selectFast(in chan interface{}) chan interface{} {
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func tcpKeepAlive(c net.Conn) {
|
||||
if tcp, ok := c.(*net.TCPConn); ok {
|
||||
tcp.SetKeepAlive(true)
|
||||
tcp.SetKeepAlivePeriod(3 * time.Minute)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user