]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Reorder some code in dht announcer
authorMatt Joiner <anacrolix@gmail.com>
Tue, 22 Jan 2019 00:41:07 +0000 (01:41 +0100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 22 Jan 2019 00:41:07 +0000 (01:41 +0100)
torrent.go

index 9edfdc8f1e66e48573359fb4f9540cc01585ac7a..133918b261687106a5e907d15c6d61f29415fff9 100644 (file)
@@ -1355,20 +1355,17 @@ func (t *Torrent) dhtAnnouncer(s *dht.Server) {
        cl := t.cl
        for {
                select {
-               case <-t.wantPeersEvent.LockedChan(cl.locker()):
                case <-t.closed.LockedChan(cl.locker()):
                        return
+               case <-t.wantPeersEvent.LockedChan(cl.locker()):
                }
+               cl.lock()
+               t.numDHTAnnounces++
+               cl.unlock()
                err := t.announceToDht(true, s)
-               func() {
-                       cl.lock()
-                       defer cl.unlock()
-                       if err == nil {
-                               t.numDHTAnnounces++
-                       } else {
-                               t.logger.Printf("error announcing %q to DHT: %s", t, err)
-                       }
-               }()
+               if err != nil {
+                       t.logger.Printf("error announcing %q to DHT: %s", t, err)
+               }
        }
 }