mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
add reader timeout for cache
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
|
|
||||||
@@ -21,8 +22,9 @@ type Reader struct {
|
|||||||
isClosed bool
|
isClosed bool
|
||||||
|
|
||||||
///Preload
|
///Preload
|
||||||
muPreload sync.Mutex
|
lastAccess int64
|
||||||
ranges Range
|
muPreload sync.Mutex
|
||||||
|
ranges Range
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReader(file *torrent.File, cache *Cache) *Reader {
|
func newReader(file *torrent.File, cache *Cache) *Reader {
|
||||||
@@ -53,6 +55,7 @@ func (r *Reader) Seek(offset int64, whence int) (n int64, err error) {
|
|||||||
}
|
}
|
||||||
n, err = r.Reader.Seek(offset, whence)
|
n, err = r.Reader.Seek(offset, whence)
|
||||||
r.offset = n
|
r.offset = n
|
||||||
|
r.lastAccess = time.Now().Unix()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +86,7 @@ func (r *Reader) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.offset += int64(n)
|
r.offset += int64(n)
|
||||||
|
r.lastAccess = time.Now().Unix()
|
||||||
} else {
|
} else {
|
||||||
log.TLogln("Torrent closed and readed")
|
log.TLogln("Torrent closed and readed")
|
||||||
}
|
}
|
||||||
@@ -130,6 +134,11 @@ func (r *Reader) getPieceNum(offset int64) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) getOffsetRange() (int64, int64) {
|
func (r *Reader) getOffsetRange() (int64, int64) {
|
||||||
|
|
||||||
|
if time.Now().Unix() > r.lastAccess+60 {
|
||||||
|
return r.file.Offset(), r.file.Offset()
|
||||||
|
}
|
||||||
|
|
||||||
prc := int64(settings.BTsets.ReaderReadAHead)
|
prc := int64(settings.BTsets.ReaderReadAHead)
|
||||||
readers := int64(len(r.cache.readers))
|
readers := int64(len(r.cache.readers))
|
||||||
if readers == 0 {
|
if readers == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user