From 1c307d668c505b098771d41ec4afd1c41a3bf540 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sat, 21 Aug 2021 10:40:22 +0300 Subject: [PATCH] fix read a head on not readed reader --- server/torr/storage/torrstor/reader.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/torr/storage/torrstor/reader.go b/server/torr/storage/torrstor/reader.go index c3113b3..ce191c1 100644 --- a/server/torr/storage/torrstor/reader.go +++ b/server/torr/storage/torrstor/reader.go @@ -94,6 +94,12 @@ func (r *Reader) Read(p []byte) (n int, err error) { } func (r *Reader) SetReadahead(length int64) { + if time.Now().Unix() > r.lastAccess+60 && r.cache != nil && len(r.cache.readers) > 1 { + //fix read a head on not readed reader + r.Reader.SetReadahead(0) + r.readahead = 0 + return + } if r.cache != nil && length > r.cache.capacity { length = r.cache.capacity } @@ -114,7 +120,7 @@ func (r *Reader) Close() { // this struct close in cache r.isClosed = true if len(r.file.Torrent().Files()) > 0 { - r.Reader.Close() + r.Reader.Close() } go r.cache.getRemPieces() }