fix bugs
This commit is contained in:
parent
e1354e8a85
commit
12b3f12859
1 changed files with 8 additions and 5 deletions
|
|
@ -17,7 +17,10 @@ use futures::{stream::FuturesUnordered, StreamExt};
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use tokio::sync::{mpsc::Sender, Notify, Semaphore};
|
use tokio::{
|
||||||
|
sync::{mpsc::Sender, Notify, Semaphore},
|
||||||
|
task::JoinHandle,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
buffers::ByteString,
|
buffers::ByteString,
|
||||||
|
|
@ -237,10 +240,10 @@ fn spawn<N: Display + 'static + Send>(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn spawn_blocking<T: Send + Sync + 'static, N: Display + 'static + Send>(
|
fn spawn_blocking<T: Send + Sync + 'static, N: Display + 'static + Send>(
|
||||||
name: N,
|
name: N,
|
||||||
f: impl FnOnce() -> anyhow::Result<T> + Send + 'static,
|
f: impl FnOnce() -> anyhow::Result<T> + Send + 'static,
|
||||||
) -> anyhow::Result<T> {
|
) -> JoinHandle<anyhow::Result<T>> {
|
||||||
debug!("starting blocking task \"{}\"", name);
|
debug!("starting blocking task \"{}\"", name);
|
||||||
tokio::task::spawn_blocking(move || match f() {
|
tokio::task::spawn_blocking(move || match f() {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
|
|
@ -252,7 +255,6 @@ async fn spawn_blocking<T: Send + Sync + 'static, N: Display + 'static + Send>(
|
||||||
Err(e)
|
Err(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.await?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_lengths(torrent: &TorrentMetaV1Owned) -> anyhow::Result<Lengths> {
|
fn make_lengths(torrent: &TorrentMetaV1Owned) -> anyhow::Result<Lengths> {
|
||||||
|
|
@ -472,7 +474,7 @@ impl TorrentManager {
|
||||||
),
|
),
|
||||||
move || clone.read_chunk_blocking(peer_handle, chunk_info),
|
move || clone.read_chunk_blocking(peer_handle, chunk_info),
|
||||||
)
|
)
|
||||||
.await?;
|
.await??;
|
||||||
let tx = this
|
let tx = this
|
||||||
.inner
|
.inner
|
||||||
.locked
|
.locked
|
||||||
|
|
@ -490,6 +492,7 @@ impl TorrentManager {
|
||||||
chunk_info.offset,
|
chunk_info.offset,
|
||||||
chunk,
|
chunk,
|
||||||
));
|
));
|
||||||
|
info!("sending to {}: {:?}", peer_handle, &message);
|
||||||
Ok::<_, anyhow::Error>(tx.send(message).await?)
|
Ok::<_, anyhow::Error>(tx.send(message).await?)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue