client.go | 5 ++++- utp.go | 5 +++-- diff --git a/client.go b/client.go index 4e40197a1bb6f81ccd6cd23de2ac75af91ef47db..43db1e8642ce338abd3dd72958f383b1d3c0083c 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ import ( "bufio" "bytes" + "context" "crypto/rand" "encoding/hex" "errors" @@ -535,7 +536,9 @@ return } 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 ea9a6f7340b5b498efb7586ba70d3e53c576beb5..1d395e8068a719b03f980581b863f156135a2015 100644 --- a/utp.go +++ b/utp.go @@ -1,6 +1,7 @@ package torrent import ( + "context" "net" "time" ) @@ -17,6 +18,6 @@ SetDeadline(time.Time) error 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) }