Fix: dial tcp with context to avoid margin of error

This commit is contained in:
Dreamacro
2019-10-12 23:55:39 +08:00
parent 0cdc40beb3
commit 7c4a359a2b
14 changed files with 47 additions and 30 deletions

View File

@ -1,6 +1,7 @@
package adapters
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
@ -57,8 +58,8 @@ type v2rayObfsOption struct {
Mux bool `obfs:"mux,omitempty"`
}
func (ss *ShadowSocks) Dial(metadata *C.Metadata) (C.Conn, error) {
c, err := dialTimeout("tcp", ss.server, tcpTimeout)
func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
c, err := dialContext(ctx, "tcp", ss.server)
if err != nil {
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
}