From: Matt Joiner Date: Wed, 16 Aug 2017 05:35:17 +0000 (+1000) Subject: Use DialContext instead of DialTimeout with utp X-Git-Tag: v1.0.0~448 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8317417910638b833c3440a96eb3f98b0beef5d4;p=btrtrc.git Use DialContext instead of DialTimeout with utp --- diff --git a/client.go b/client.go index 4e40197a..43db1e86 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package torrent import ( "bufio" "bytes" + "context" "crypto/rand" "encoding/hex" "errors" @@ -535,7 +536,9 @@ func (cl *Client) dialTCP(addr string, t *Torrent) (c net.Conn, err error) { } func (cl *Client) dialUTP(addr string, t *Torrent) (net.Conn, error) { - return cl.utpSock.DialTimeout(addr, cl.dialTimeout(t)) + ctx, cancel := context.WithTimeout(context.Background(), cl.dialTimeout(t)) + defer cancel() + return cl.utpSock.DialContext(ctx, addr) } // Returns a connection over UTP or TCP, whichever is first to connect. diff --git a/utp.go b/utp.go index ea9a6f73..1d395e80 100644 --- a/utp.go +++ b/utp.go @@ -1,6 +1,7 @@ package torrent import ( + "context" "net" "time" ) @@ -17,6 +18,6 @@ type utpSocket interface { SetWriteDeadline(time.Time) error SetReadDeadline(time.Time) error WriteTo([]byte, net.Addr) (int, error) - DialTimeout(string, time.Duration) (net.Conn, error) - Dial(string) (net.Conn, error) + DialContext(ctx context.Context, addr string) (net.Conn, error) + Dial(addr string) (net.Conn, error) }