]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use DialContext instead of DialTimeout with utp
authorMatt Joiner <anacrolix@gmail.com>
Wed, 16 Aug 2017 05:35:17 +0000 (15:35 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 16 Aug 2017 05:35:17 +0000 (15:35 +1000)
client.go
utp.go

index 4e40197a1bb6f81ccd6cd23de2ac75af91ef47db..43db1e8642ce338abd3dd72958f383b1d3c0083c 100644 (file)
--- 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 ea9a6f7340b5b498efb7586ba70d3e53c576beb5..1d395e8068a719b03f980581b863f156135a2015 100644 (file)
--- 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)
 }