fix: download panic

This commit is contained in:
liwei committed 2020-03-01 23:35:51 +08:00
1 parent b0bd2a776a
commit 753830accf
9 files changed
+181 -67

No files matched your search

+14 -1
View File
@@ -1,8 +1,9 @@
package torrent
import (
"github.com/RoaringBitmap/roaring"
"sync"
"github.com/RoaringBitmap/roaring"
)
type state int
@@ -62,6 +63,18 @@ func (ps *pieces) getReady() int {
return -1
}
func (ps *pieces) getLeft() int {
ps.rw.RLock()
defer ps.rw.RUnlock()
count := 0
for _, s := range ps.arr {
if s.state != stateFinished {
count++
}
}
return count
}
func (ps *pieces) size() int {
return len(ps.arr)
}