Fist naive attempt to improve streaming

at leat inform executor about blocking call
This commit is contained in:
Ivan 2024-07-20 20:03:14 +02:00
parent 7820bcf053
commit 1c9aa8ca72
2 changed files with 12 additions and 9 deletions

View file

@ -12,7 +12,10 @@ use anyhow::Context;
use dashmap::DashMap;
use librqbit_core::lengths::{CurrentPiece, Lengths, ValidPieceIndex};
use tokio::io::{AsyncRead, AsyncSeek};
use tokio::{
io::{AsyncRead, AsyncSeek},
task::block_in_place,
};
use tracing::{debug, trace};
use crate::{file_info::FileInfo, storage::TorrentStorage, ManagedTorrent};
@ -211,13 +214,13 @@ impl AsyncRead for FileStream {
"will write bytes"
);
poll_try_io!(poll_try_io!(self.torrent.with_storage_and_file(
self.file_id,
|files, _fi| {
files.pread_exact(self.file_id, self.position, buf)?;
Ok::<_, anyhow::Error>(())
}
)));
poll_try_io!(poll_try_io!(block_in_place(|| {
self.torrent
.with_storage_and_file(self.file_id, |files, _fi| {
files.pread_exact(self.file_id, self.position, buf)?;
Ok::<_, anyhow::Error>(())
})
})));
self.as_mut().advance(bytes_to_read as u64);
tbuf.advance(bytes_to_read);