]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Made Torrent.GotInfo a function, to avoid use of zero-initialized channel
authorMatt Joiner <anacrolix@gmail.com>
Wed, 29 Apr 2015 14:30:19 +0000 (00:30 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 29 Apr 2015 14:30:19 +0000 (00:30 +1000)
client.go
cmd/magnet-metainfo/main.go
cmd/torrent/main.go
t.go

index 14205d8994fa35dc4151fd7417dc8d216cc641c2..64483a39c95c95b6cd0bbbdcc1ad042f5e3e554d 100644 (file)
--- a/client.go
+++ b/client.go
@@ -643,7 +643,7 @@ func (cl *Client) Torrent(ih InfoHash) (T Torrent, ok bool) {
        if !ok {
                return
        }
-       T = Torrent{cl, t, t.gotMetainfo}
+       T = Torrent{cl, t}
        return
 }
 
@@ -2612,7 +2612,7 @@ func (cl *Client) verifyPiece(t *torrent, index pp.Integer) {
 func (me *Client) Torrents() (ret []Torrent) {
        me.mu.Lock()
        for _, t := range me.torrents {
-               ret = append(ret, Torrent{me, t, t.gotMetainfo})
+               ret = append(ret, Torrent{me, t})
        }
        me.mu.Unlock()
        return
index da94532ebd383d45fc50b8b98a41874d69f19e6e..878fc7db9404c81445c57325b9a2ce16bde88982 100644 (file)
@@ -26,7 +26,7 @@ func main() {
                wg.Add(1)
                go func() {
                        defer wg.Done()
-                       <-t.GotInfo
+                       <-t.GotInfo()
                        mi := t.MetaInfo()
                        t.Drop()
                        f, err := os.Create(mi.Info.Name + ".torrent")
index dcb46914cc5a6c4705aadbf1b93c278823b84821..d81d219ed8ceb65cc13e0cf533c882b2146b9eb4 100644 (file)
@@ -128,7 +128,7 @@ func main() {
                        log.Fatal(err)
                }
                go func() {
-                       <-t.GotInfo
+                       <-t.GotInfo()
                        t.DownloadAll()
                }()
        }
diff --git a/t.go b/t.go
index a4cf064f115ba14f92c7592c32acb184d3cd8eb6..70e6f8dd42affed6990582404a9b24693eaf8e5a 100644 (file)
--- a/t.go
+++ b/t.go
@@ -10,10 +10,13 @@ import (
 type Torrent struct {
        cl *Client
        *torrent
-       // Closed when the info (.Info()) for the torrent has become available.
-       // Using features of Torrent that require the info before it is available
-       // will have undefined behaviour.
-       GotInfo <-chan struct{}
+}
+
+// Closed when the info (.Info()) for the torrent has become available. Using
+// features of Torrent that require the info before it is available will have
+// undefined behaviour.
+func (t *Torrent) GotInfo() <-chan struct{} {
+       return t.torrent.gotMetainfo
 }
 
 func (t *Torrent) Info() *metainfo.Info {