spawn_peer_adder: Option<PeerStream> -> PeerStream

This commit is contained in:
Igor Katson 2024-12-05 22:05:04 +00:00
parent b796a8767b
commit e440f03970
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -269,7 +269,7 @@ impl ManagedTorrent {
);
};
fn spawn_peer_adder(live: &Arc<TorrentStateLive>, peer_rx: Option<PeerStream>) {
fn spawn_peer_adder(live: &Arc<TorrentStateLive>, mut peer_rx: PeerStream) {
live.spawn(
error_span!(parent: live.torrent().span.clone(), "external_peer_adder"),
{
@ -281,12 +281,6 @@ impl ManagedTorrent {
weak
};
let mut peer_rx = if let Some(peer_rx) = peer_rx {
peer_rx
} else {
return Ok(());
};
loop {
match timeout(Duration::from_secs(5), peer_rx.next()).await {
Ok(Some(peer)) => {
@ -359,7 +353,9 @@ impl ManagedTorrent {
t.state_change_notify.notify_waiters();
spawn_fatal_errors_receiver(&t, rx, token);
spawn_peer_adder(&live, peer_rx);
if let Some(peer_rx) = peer_rx {
spawn_peer_adder(&live, peer_rx);
}
Ok(())
}
@ -382,7 +378,9 @@ impl ManagedTorrent {
drop(g);
spawn_fatal_errors_receiver(self, rx, cancellation_token);
spawn_peer_adder(&live, peer_rx);
if let Some(peer_rx) = peer_rx {
spawn_peer_adder(&live, peer_rx);
}
Ok(())
}
ManagedTorrentState::Error(_) => {