diff --git a/vnt/src/channel/channel.rs b/vnt/src/channel/channel.rs index 3a6365b..d2f090d 100644 --- a/vnt/src/channel/channel.rs +++ b/vnt/src/channel/channel.rs @@ -20,7 +20,7 @@ use crate::handle::CurrentDeviceInfo; pub struct ContextInner { //udp用于打洞、服务端通信(可选) - pub(crate) main_channel: Arc, + pub(crate) main_channel: StdUdpSocket, //在udp的基础上,可以选择使用tcp和服务端通信 pub(crate) main_tcp_channel: Option>, pub(crate) route_table: RwLock)>>>, @@ -39,7 +39,7 @@ pub struct Context { impl Context { pub fn new( - main_channel: Arc, + main_channel: StdUdpSocket, main_tcp_channel: Option, current_device: Arc>, _channel_num: usize, @@ -484,7 +484,7 @@ impl Channel { ) { let handler = self.handler.clone(); let context = self.context; - let main_channel = context.inner.main_channel.clone(); + let main_channel = context.inner.main_channel.try_clone().unwrap(); let buf_sender = if parallel > 1 { let (buf_sender, buf_receiver) = buf_channel_group(parallel); let mut num = 0; @@ -521,7 +521,7 @@ impl Channel { { let worker = worker.worker("main_channel_udp"); let context = context.clone(); - let main_channel = main_channel.clone(); + let main_channel = main_channel.try_clone().unwrap(); let handler = handler.clone(); let buf_sender = buf_sender.clone(); thread::Builder::new() @@ -546,6 +546,7 @@ impl Channel { } let mut cur_status = Status::Cone; let mut status_receiver = context.inner.status_receiver.clone(); + let channel_num = context.inner.channel_num; loop { tokio::select! { _=worker.stop_wait()=>{ @@ -564,7 +565,7 @@ impl Channel { continue; } cur_status = Status::Symmetric; - for _ in 0..symmetric_channel_num { + for _ in 0..symmetric_channel_num - channel_num { match UdpSocket::bind("0.0.0.0:0").await { Ok(udp) => { let udp = Arc::new(udp); @@ -595,7 +596,7 @@ impl Channel { worker: VntWorker, context: Context, id: usize, - udp: Arc, + udp: StdUdpSocket, handler: ChannelDataHandler, buf_sender: Option, head_reserve: usize, diff --git a/vnt/src/core/mod.rs b/vnt/src/core/mod.rs index e87e71d..c4b8988 100644 --- a/vnt/src/core/mod.rs +++ b/vnt/src/core/mod.rs @@ -242,7 +242,7 @@ impl VntUtil { (None, None) }; let context = Context::new( - Arc::new(self.main_channel), + self.main_channel, tcp_sender, current_device.clone(), 1,