From 5dcda4d088fd8ddebd9b868d7337e05cccb14a24 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Thu, 30 Mar 2023 12:09:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E7=A8=8B=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- switch-desktop/src/unix/mod.rs | 4 ++-- switch/src/handle/heartbeat_handler.rs | 8 ++++---- switch/src/handle/punch_handler.rs | 12 ++++++------ switch/src/handle/recv_handler.rs | 4 ++-- switch/src/handle/tun_handler.rs | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/switch-desktop/src/unix/mod.rs b/switch-desktop/src/unix/mod.rs index f94a764..62c8dbd 100644 --- a/switch-desktop/src/unix/mod.rs +++ b/switch-desktop/src/unix/mod.rs @@ -76,11 +76,11 @@ pub fn main0(base_args: BaseArgs) { log::error!("{:?}", e); } let switch1 = switch.clone(); - let handle = std::thread::spawn(move || { + let handle = std::thread::Builder::new().name("cmd-server".into()).spawn(move || { if let Err(e) = command_server.start(switch1) { log::error!("{:?}", e); } - }); + }).unwrap(); crate::console_listen(&switch); if let Err(e) = handle.join() { log::error!("后台任务异常{:?}",e); diff --git a/switch/src/handle/heartbeat_handler.rs b/switch/src/handle/heartbeat_handler.rs index b65f2d9..6134e31 100644 --- a/switch/src/handle/heartbeat_handler.rs +++ b/switch/src/handle/heartbeat_handler.rs @@ -17,11 +17,11 @@ use crate::protocol::{control_packet, MAX_TTL, NetPacket, Protocol, Version}; use crate::protocol::control_packet::PingPacket; pub fn start_idle(idle: Idle, sender: Sender) { - thread::spawn(move || { + thread::Builder::new().name("idle".into()).spawn(move || { if let Err(e) = start_idle_(idle, sender) { log::info!("空闲检测线程停止:{:?}",e); } - }); + }).unwrap(); } fn start_idle_(idle: Idle, sender: Sender) -> io::Result<()> { @@ -35,11 +35,11 @@ fn start_idle_(idle: Idle, sender: Sender) -> io::Result<()> } pub fn start_heartbeat(sender: Sender, device_list: Arc)>>, current_device: Arc>) { - thread::spawn(move || { + thread::Builder::new().name("heartbeat".into()).spawn(move || { if let Err(e) = start_heartbeat_(sender, device_list, current_device) { log::info!("空闲检测线程停止:{:?}",e); } - }); + }).unwrap(); } fn set_now_time(packet: &mut NetPacket<[u8; 16]>) -> io::Result<()> { diff --git a/switch/src/handle/punch_handler.rs b/switch/src/handle/punch_handler.rs index f060249..2901af2 100644 --- a/switch/src/handle/punch_handler.rs +++ b/switch/src/handle/punch_handler.rs @@ -14,19 +14,19 @@ use crate::proto::message::{PunchInfo, PunchNatType}; use crate::protocol::{control_packet, MAX_TTL, NetPacket, Protocol, turn_packet, Version}; pub fn start_cone(punch: Punch, current_device: Arc>) { - thread::spawn(move || { + thread::Builder::new().name("punch-cone".into()).spawn(move || { if let Err(e) = start_(true, punch, current_device) { log::warn!("锥形网络打洞处理线程停止 {:?}",e); } - }); + }).unwrap(); } pub fn start_symmetric(punch: Punch, current_device: Arc>) { - thread::spawn(move || { + thread::Builder::new().name("punch-symmetric".into()).spawn(move || { if let Err(e) = start_(false, punch, current_device) { log::warn!("对称网络打洞处理线程停止 {:?}",e); } - }); + }).unwrap(); } fn start_(is_cone: bool, mut punch: Punch, current_device: Arc>) -> io::Result<()> { @@ -57,11 +57,11 @@ fn start_(is_cone: bool, mut punch: Punch, current_device: Arc)>>, sender: Sender, current_device: Arc>) { - thread::spawn(move || { + thread::Builder::new().name("punch-send-request".into()).spawn(move || { if let Err(e) = start_punch_(nat_test, device_list, sender, current_device) { log::warn!("对称网络打洞处理线程停止 {:?}",e); } - }); + }).unwrap(); } fn start_punch_(nat_test: NatTest, device_list: Arc)>>, sender: Sender, current_device: Arc>) -> crate::Result<()> { diff --git a/switch/src/handle/recv_handler.rs b/switch/src/handle/recv_handler.rs index 2741750..0f3961e 100644 --- a/switch/src/handle/recv_handler.rs +++ b/switch/src/handle/recv_handler.rs @@ -26,7 +26,7 @@ use crate::protocol::error_packet::InErrorPacket; use crate::tun_device::TunWriter; pub fn start(mut handler: RecvHandler) { - thread::spawn(move || { + thread::Builder::new().name("udp-recv-handler".into()).spawn(move || { let mut buf = [0; 4096]; loop { match handler.channel.recv_from(&mut buf, None) { @@ -48,7 +48,7 @@ pub fn start(mut handler: RecvHandler) { } } } - }); + }).unwrap(); } pub struct RecvHandler { diff --git a/switch/src/handle/tun_handler.rs b/switch/src/handle/tun_handler.rs index ca2ae07..da837f1 100644 --- a/switch/src/handle/tun_handler.rs +++ b/switch/src/handle/tun_handler.rs @@ -69,11 +69,11 @@ pub fn start(sender: Sender, tun_reader: TunReader, tun_writer: TunWriter, current_device: Arc>, ) { - thread::spawn(move || { + thread::Builder::new().name("tun-handler".into()).spawn(move || { if let Err(e) = start_(sender, tun_reader, tun_writer, current_device) { log::warn!("{:?}",e); } - }); + }).unwrap(); } #[cfg(target_os = "windows")]