From: Denis Kuzmenok Date: Fri, 2 Jun 2017 04:46:28 +0000 (+0300) Subject: added few helper functions: t.PieceBytesMissing, r.CurrentPos, r.SetNonResponsive X-Git-Tag: v1.0.0~463^2 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8cae95652816c126ffb76b5ba77a981acc9060fc;p=btrtrc.git added few helper functions: t.PieceBytesMissing, r.CurrentPos, r.SetNonResponsive --- diff --git a/reader.go b/reader.go index b73b8bad..1c8bce79 100644 --- a/reader.go +++ b/reader.go @@ -44,6 +44,11 @@ func (r *Reader) SetResponsive() { r.responsive = true } +// Disable responsive mode. +func (r *Reader) SetNonResponsive() { + r.responsive = false +} + // Configure the number of bytes ahead of a read that should also be // prioritized in preparation for further reads. func (r *Reader) SetReadahead(readahead int64) { @@ -55,6 +60,11 @@ func (r *Reader) SetReadahead(readahead int64) { r.posChanged() } +// Return reader's current position. +func (r *Reader) CurrentPos() int64 { + return r.pos +} + func (r *Reader) readable(off int64) (ret bool) { if r.t.closed.IsSet() { return true diff --git a/t.go b/t.go index ed810a5f..3fe2ae79 100644 --- a/t.go +++ b/t.go @@ -61,6 +61,14 @@ func (t *Torrent) NumPieces() int { return t.numPieces() } +// Get missing bytes count for specific piece. +func (t *Torrent) PieceBytesMissing(piece int) int64 { + t.cl.mu.Lock() + defer t.cl.mu.Unlock() + + return int64(t.pieces[piece].bytesLeft()) +} + // Drop the torrent from the client, and close it. It's always safe to do // this. No data corruption can, or should occur to either the torrent's data, // or connected peers.