From 8317417910638b833c3440a96eb3f98b0beef5d4 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 16 Aug 2017 15:35:17 +1000 Subject: [PATCH] Use DialContext instead of DialTimeout with utp --- client.go | 5 ++++- utp.go | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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) } -- 2.48.1