]> Sergey Matveev's repositories - btrtrc.git/commitdiff
added few helper functions: t.PieceBytesMissing, r.CurrentPos, r.SetNonResponsive
authorDenis Kuzmenok <denis.kuzmenok@gmail.com>
Fri, 2 Jun 2017 04:46:28 +0000 (07:46 +0300)
committerDenis Kuzmenok <denis.kuzmenok@gmail.com>
Fri, 2 Jun 2017 04:46:28 +0000 (07:46 +0300)
reader.go
t.go

index b73b8bad4aeb57865086189a67f76ca26bc82616..1c8bce797dc4d9b9450ca5a865cc039b5b0a64b0 100644 (file)
--- 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 ed810a5fd08d98d3d1f50babbc1063105d7c851e..3fe2ae79ad37afaa453ddf8c25fb5eae34cce6d3 100644 (file)
--- 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.