diff --git a/src/tunnel/io.rs b/src/tunnel/io.rs index 8259f52..abf5bca 100644 --- a/src/tunnel/io.rs +++ b/src/tunnel/io.rs @@ -38,8 +38,8 @@ pub(super) async fn propagate_read( }; let read_len = match read_len { - Ok(read_len) if read_len > 0 => read_len, - Ok(_) => break, + Ok(0) => break, + Ok(read_len) => read_len, Err(err) => { warn!( "error while reading incoming bytes from local tx tunnel {}", diff --git a/src/tunnel/server.rs b/src/tunnel/server.rs index 275f4c2..6376f7f 100644 --- a/src/tunnel/server.rs +++ b/src/tunnel/server.rs @@ -11,6 +11,7 @@ use hyper::server::conn::Http; use hyper::service::service_fn; use hyper::{http, Body, Request, Response, StatusCode}; use jsonwebtoken::TokenData; + use tokio::io::{AsyncRead, AsyncWrite}; use tokio::net::{TcpListener, UdpSocket}; use tokio::sync::oneshot; diff --git a/src/udp.rs b/src/udp.rs index 7e67f5c..364b71c 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -150,8 +150,8 @@ pub async fn run_server( let udp_server = UdpServer::new(Arc::new(listener), timeout); let stream = stream::unfold(udp_server, |mut server| async { + server.clean_dead_keys(); loop { - server.clean_dead_keys(); let peer_addr = match server.listener.peek_sender().await { Ok(ret) => ret, Err(err) => { @@ -183,7 +183,7 @@ pub async fn run_server( } Entry::Vacant(peer) => { let mut buf = BytesMut::with_capacity(DEFAULT_UDP_BUFFER_SIZE); - let len = match server.listener.recv_buf(&mut buf).await { + let len = match server.listener.try_recv_buf(&mut buf) { Ok(0) | Err(_) => { continue; }