reader.go | 23 +++++++++++++---------- diff --git a/reader.go b/reader.go index a5a865710f7256703fb3099652aca500e0b78d67..31ac7b07937f2c389af59f06bb895b61d4bef911 100644 --- a/reader.go +++ b/reader.go @@ -30,26 +30,29 @@ begin, end pieceIndex } type reader struct { - t *Torrent - responsive bool + t *Torrent // Adjust the read/seek window to handle Readers locked to File extents and the like. offset, length int64 - - // Required when modifying pos and readahead, or reading them without opMu. - mu sync.Locker - pos int64 - // Reads have been initiated since the last seek. This is used to prevent readahead occuring - // after a seek or with a new reader at the starting position. - reading bool - readahead int64 + // Function to dynamically calculate readahead. If nil, readahead is static. readaheadFunc func() int64 + + // Required when modifying pos and readahead. + mu sync.Locker + + readahead, pos int64 // Position that reads have continued contiguously from. contiguousReadStartPos int64 // The cached piece range this reader wants downloaded. The zero value corresponds to nothing. // We cache this so that changes can be detected, and bubbled up to the Torrent only as // required. pieces pieceRange + + // Reads have been initiated since the last seek. This is used to prevent readaheads occurring + // after a seek or with a new reader at the starting position. + reading bool + responsive bool + } var _ io.ReadSeekCloser = (*reader)(nil)