change pieces prior set

This commit is contained in:
YouROK
2021-02-19 00:21:23 +03:00
parent c9de021f0a
commit 2b1e66cf59
3 changed files with 17 additions and 7 deletions

View File

@@ -165,7 +165,7 @@ func (c *Cache) cleanPieces() {
remPieces := c.getRemPieces()
if c.filled > c.capacity {
rems := (c.filled - c.capacity) / c.pieceLength
rems := (c.filled-c.capacity)/c.pieceLength + 1
for _, p := range remPieces {
c.removePiece(p)
rems--
@@ -192,19 +192,23 @@ func (c *Cache) getRemPieces() []*Piece {
if p.Size > 0 {
fill += p.Size
}
piece := c.torrent.Piece(id)
state := piece.State()
if len(ranges) > 0 {
if !inRanges(ranges, id) {
piece := c.torrent.Piece(id)
if piece.State().Priority != torrent.PiecePriorityNone {
if state.Priority != torrent.PiecePriorityNone {
piece.SetPriority(torrent.PiecePriorityNone)
}
if p.Size > 0 {
piecesRemove = append(piecesRemove, p)
}
} else {
if state.Priority != torrent.PiecePriorityNow && state.Priority != torrent.PiecePriorityReadahead && state.Priority != torrent.PiecePriorityNormal {
piece.SetPriority(torrent.PiecePriorityNormal)
}
}
} else {
piece := c.torrent.Piece(id)
if piece.State().Priority != torrent.PiecePriorityNone {
if state.Priority != torrent.PiecePriorityNone {
piece.SetPriority(torrent.PiecePriorityNone)
}
}

View File

@@ -19,6 +19,7 @@ type Reader struct {
///Preload
muPreload sync.Mutex
ranges Range
}
func newReader(file *torrent.File, cache *Cache) *Reader {
@@ -60,7 +61,7 @@ func (r *Reader) Read(p []byte) (n int, err error) {
if r.file.Torrent() != nil && r.file.Torrent().Info() != nil {
n, err = r.Reader.Read(p)
r.offset += int64(n)
go r.preload()
//go r.preload()
} else {
log.TLogln("Torrent closed and readed")
}

View File

@@ -40,8 +40,13 @@ func (r *Reader) getOffsetRange() (int64, int64) {
}
func (r *Reader) preload() {
torr := r.file.Torrent()
rrange := r.getPiecesRange()
if rrange.Start == r.ranges.Start && rrange.End == r.ranges.End {
return
}
torr := r.file.Torrent()
r.ranges = rrange
rahPiece := int(r.readahead / torr.Info().PieceLength)
readerPiece := r.getReaderPiece()