Chore: adjust dial tcp timeout
This commit is contained in:
parent
4895bcefca
commit
082d3bbf04
5 changed files with 8 additions and 4 deletions
|
@ -32,7 +32,7 @@ func (d *Direct) Type() C.AdapterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Direct) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
func (d *Direct) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
||||||
c, err := net.Dial("tcp", net.JoinHostPort(metadata.String(), metadata.Port))
|
c, err := net.DialTimeout("tcp", net.JoinHostPort(metadata.String(), metadata.Port), tcpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (ss *ShadowSocks) Type() C.AdapterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *ShadowSocks) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
func (ss *ShadowSocks) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
||||||
c, err := net.Dial("tcp", ss.server)
|
c, err := net.DialTimeout("tcp", ss.server, tcpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error", ss.server)
|
return nil, fmt.Errorf("%s connect error", ss.server)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (ss *Socks5) Type() C.AdapterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *Socks5) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
func (ss *Socks5) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
||||||
c, err := net.Dial("tcp", ss.addr)
|
c, err := net.DialTimeout("tcp", ss.addr, tcpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error", ss.addr)
|
return nil, fmt.Errorf("%s connect error", ss.addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,10 @@ import (
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
tcpTimeout = 5 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// DelayTest get the delay for the specified URL
|
// DelayTest get the delay for the specified URL
|
||||||
func DelayTest(proxy C.Proxy, url string) (t int16, err error) {
|
func DelayTest(proxy C.Proxy, url string) (t int16, err error) {
|
||||||
addr, err := urlToMetadata(url)
|
addr, err := urlToMetadata(url)
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (ss *Vmess) Type() C.AdapterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *Vmess) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
func (ss *Vmess) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
||||||
c, err := net.Dial("tcp", ss.server)
|
c, err := net.DialTimeout("tcp", ss.server, tcpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error", ss.server)
|
return nil, fmt.Errorf("%s connect error", ss.server)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue