Tighten responsive download strategy partial piece request filling

This commit is contained in:
Matt Joiner 2014-09-11 14:22:29 +10:00
parent 2b360b641c
commit 5d35e10706
1 changed files with 8 additions and 7 deletions

View File

@ -219,21 +219,22 @@ func (me *requestFiller) completePartial() bool {
th := me.s.requestHeat[t]
for e := t.IncompletePiecesByBytesLeft.Front(); e != nil; e = e.Next() {
p := e.Value.(int)
// Stop when we reach pieces that aren't partial and aren't smaller
// than usual.
if !t.PiecePartiallyDownloaded(p) && int(t.PieceLength(pp.Integer(p))) == t.UsualPieceSize() {
break
}
if lastReadOffset, ok := me.s.lastReadOffset[t]; ok {
if p >= int(lastReadOffset/int64(t.UsualPieceSize())) {
if int64(p+1)*int64(t.UsualPieceSize()) < lastReadOffset+me.s.Readahead {
continue
}
}
}
for chunkSpec := range t.Pieces[p].PendingChunkSpecs {
r := request{pp.Integer(p), chunkSpec}
if th[r] >= 1 {
continue
}
if lastReadOffset, ok := me.s.lastReadOffset[t]; ok {
off := me.t.requestOffset(r)
if off >= lastReadOffset && off < lastReadOffset+me.s.Readahead {
continue
}
}
if !me.conservativelyRequest(r) {
return false
}