From 521280537ab5c76db9def53c035a0ec0801ff550 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Sun, 3 Mar 2024 09:45:52 +0800 Subject: [PATCH] =?UTF-8?q?[mio]=20=E5=85=BC=E5=AE=B9padavan=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=99=A8=E6=89=BE=E4=B8=8D=E5=88=B0=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=B7=AF=E5=BE=84=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt-cli/src/command/client.rs | 30 ++++++++++++++++-------------- vnt-cli/src/main.rs | 22 +++++++++++++++------- vnt/src/handle/recv_data/server.rs | 4 +++- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/vnt-cli/src/command/client.rs b/vnt-cli/src/command/client.rs index bee8cbb..0630c79 100644 --- a/vnt-cli/src/command/client.rs +++ b/vnt-cli/src/command/client.rs @@ -13,21 +13,10 @@ pub struct CommandClient { impl CommandClient { pub fn new() -> io::Result { - let path_buf = crate::app_home()?.join("command-port"); - let port = if path_buf.exists() { - let port = std::fs::read_to_string(path_buf)?; - match u16::from_str(&port) { - Ok(port) => port, - Err(_) => { - return Err(io::Error::new( - io::ErrorKind::Other, - "'command-port' file error", - )); - } - } - } else { + let port = read_command_port().unwrap_or_else(|e| { + log::warn!("read_command_port:{:?}", e); 39271 - }; + }); let udp = UdpSocket::bind("127.0.0.1:0")?; udp.set_read_timeout(Some(Duration::from_secs(5)))?; udp.connect(SocketAddr::V4(SocketAddrV4::new( @@ -40,6 +29,19 @@ impl CommandClient { }) } } +fn read_command_port() -> io::Result { + let path_buf = crate::app_home()?.join("command-port"); + let port = std::fs::read_to_string(path_buf)?; + match u16::from_str(&port) { + Ok(port) => Ok(port), + Err(_) => { + return Err(io::Error::new( + io::ErrorKind::Other, + "'command-port' file error", + )); + } + } +} impl CommandClient { pub fn list(&mut self) -> io::Result> { diff --git a/vnt-cli/src/main.rs b/vnt-cli/src/main.rs index 2a9565a..fba5f09 100644 --- a/vnt-cli/src/main.rs +++ b/vnt-cli/src/main.rs @@ -18,13 +18,21 @@ mod console_out; mod root_check; pub fn app_home() -> io::Result { - let path = std::env::current_exe()? - .parent() - .ok_or(io::Error::new( - io::ErrorKind::Other, - "current_exe parent error", - ))? - .join("env"); + let root_path = match std::env::current_exe() { + Ok(path) => { + if let Some(v) = path.as_path().parent() { + v.to_path_buf() + } else { + log::warn!("current_exe parent none:{:?}", path); + PathBuf::new() + } + } + Err(e) => { + log::warn!("current_exe err:{:?}", e); + PathBuf::new() + } + }; + let path = root_path.join("env"); if !path.exists() { std::fs::create_dir_all(&path)?; } diff --git a/vnt/src/handle/recv_data/server.rs b/vnt/src/handle/recv_data/server.rs index 58bd975..0300de2 100644 --- a/vnt/src/handle/recv_data/server.rs +++ b/vnt/src/handle/recv_data/server.rs @@ -89,7 +89,9 @@ impl PacketHandler for ServerPacketHandler { context: &Context, current_device: &CurrentDeviceInfo, ) -> io::Result<()> { - context.route_table.update_read_time(&net_packet.source(), &route_key); + context + .route_table + .update_read_time(&net_packet.source(), &route_key); if net_packet.protocol() == Protocol::Error && net_packet.transport_protocol() == crate::protocol::error_packet::Protocol::NoKey.into()