// Returns a Reader bound to the torrent's data. All read calls block until the data requested is
// actually available. Note that you probably want to ensure the Torrent Info is available first.
func (t *Torrent) NewReader() Reader {
- return t.newReader(0, *t.length)
+ return t.newReader(0, t.length())
}
func (t *Torrent) newReader(offset, length int64) Reader {
// Get missing bytes count for specific piece.
func (t *Torrent) PieceBytesMissing(piece int) int64 {
- t.cl.lock()
- defer t.cl.unlock()
+ t.cl.rLock()
+ defer t.cl.rUnlock()
return int64(t.pieces[piece].bytesLeft())
}
// Returns true if the torrent is currently being seeded. This occurs when the
// client is willing to upload without wanting anything in return.
func (t *Torrent) Seeding() (ret bool) {
- t.cl.lock()
+ t.cl.rLock()
ret = t.seeding()
- t.cl.unlock()
+ t.cl.rUnlock()
return
}
// The completed length of all the torrent data, in all its files. This is
// derived from the torrent info, when it is available.
func (t *Torrent) Length() int64 {
- return *t.length
+ return t._length.Value
}
// Returns a run-time generated metainfo for the torrent that includes the
// info bytes and announce-list as currently known to the client.
func (t *Torrent) Metainfo() metainfo.MetaInfo {
- t.cl.lock()
- defer t.cl.unlock()
+ t.cl.rLock()
+ defer t.cl.rUnlock()
return t.newMetaInfo()
}