From 1ee5755ed1e38a5edbce17aa01862424936faa6a Mon Sep 17 00:00:00 2001 From: Michel de Graaf Date: Mon, 10 Nov 2025 17:36:44 +0100 Subject: [PATCH] feat: only for download peer spawn a thread --- src/peer/listen.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/peer/listen.rs b/src/peer/listen.rs index 1b922be..5f90be5 100644 --- a/src/peer/listen.rs +++ b/src/peer/listen.rs @@ -228,15 +228,23 @@ fn handle_incoming_connection(stream: TcpStream, context: ConnectionContext) { ConnectionType::P => handle_peer_connection( peer, stream, reader, &context, &peer_ip, peer_port, ), - ConnectionType::F => handle_file_connection( - peer, - stream, - reader, - init_data.token, - &context, - &peer_ip, - peer_port, - ), + + ConnectionType::F => { + thread::spawn(move || { + trace!( + "[listener:{peer_ip}:{peer_port}] handling file connection in thread" + ); + handle_file_connection( + peer, + stream, + reader, + init_data.token, + &context, + &peer_ip, + peer_port, + ) + }); + } ConnectionType::D => { debug!("[listener:{peer_ip}:{peer_port}] connection type is D, not supported yet, closing connection. "); } @@ -273,7 +281,7 @@ impl Listen { }; let context = context.clone(); - thread::spawn(move || handle_incoming_connection(stream, context)); + handle_incoming_connection(stream, context); } } }