Wrap reading files into block_in_place
This commit is contained in:
parent
f845eafca4
commit
bca55891c1
5 changed files with 40 additions and 15 deletions
|
|
@ -17,8 +17,11 @@ use peer_binary_protocol::{
|
|||
use sha1w::{ISha1, Sha1};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use crate::peer_connection::{
|
||||
PeerConnection, PeerConnectionHandler, PeerConnectionOptions, WriterRequest,
|
||||
use crate::{
|
||||
peer_connection::{
|
||||
PeerConnection, PeerConnectionHandler, PeerConnectionOptions, WriterRequest,
|
||||
},
|
||||
spawn_utils::BlockingSpawner,
|
||||
};
|
||||
|
||||
pub async fn read_metainfo_from_peer(
|
||||
|
|
@ -26,6 +29,7 @@ pub async fn read_metainfo_from_peer(
|
|||
peer_id: Id20,
|
||||
info_hash: Id20,
|
||||
peer_connection_options: Option<PeerConnectionOptions>,
|
||||
spawner: BlockingSpawner,
|
||||
) -> anyhow::Result<TorrentMetaV1Info<ByteString>> {
|
||||
let (result_tx, result_rx) =
|
||||
tokio::sync::oneshot::channel::<anyhow::Result<TorrentMetaV1Info<ByteString>>>();
|
||||
|
|
@ -37,8 +41,14 @@ pub async fn read_metainfo_from_peer(
|
|||
result_tx: Mutex::new(Some(result_tx)),
|
||||
locked: RwLock::new(None),
|
||||
};
|
||||
let connection =
|
||||
PeerConnection::new(addr, info_hash, peer_id, handler, peer_connection_options);
|
||||
let connection = PeerConnection::new(
|
||||
addr,
|
||||
info_hash,
|
||||
peer_id,
|
||||
handler,
|
||||
peer_connection_options,
|
||||
spawner,
|
||||
);
|
||||
|
||||
let result_reader = async move { result_rx.await? };
|
||||
let connection_runner = async move { connection.manage_peer(writer_rx).await };
|
||||
|
|
@ -219,6 +229,8 @@ mod tests {
|
|||
use librqbit_core::id20::Id20;
|
||||
use librqbit_core::peer_id::generate_peer_id;
|
||||
|
||||
use crate::spawn_utils::BlockingSpawner;
|
||||
|
||||
use super::read_metainfo_from_peer;
|
||||
|
||||
static LOG_INIT: Once = std::sync::Once::new();
|
||||
|
|
@ -234,8 +246,10 @@ mod tests {
|
|||
let addr = SocketAddr::from_str("127.0.0.1:27311").unwrap();
|
||||
let peer_id = generate_peer_id();
|
||||
let info_hash = Id20::from_str("9905f844e5d8787ecd5e08fb46b2eb0a42c131d7").unwrap();
|
||||
dbg!(read_metainfo_from_peer(addr, peer_id, info_hash, None)
|
||||
.await
|
||||
.unwrap());
|
||||
dbg!(
|
||||
read_metainfo_from_peer(addr, peer_id, info_hash, None, BlockingSpawner::new(true))
|
||||
.await
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue