Fix async problem

remove timeouts
This commit is contained in:
Jett Chen 2023-12-03 01:27:06 +08:00
parent d012ca144c
commit 7d0c0250c5
3 changed files with 6 additions and 14 deletions

View file

@ -47,7 +47,7 @@ pub async fn daemon_main() -> Result<()> {
let mut _tun = tun::TunInterface::new()?; let mut _tun = tun::TunInterface::new()?;
_tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10]))?; _tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10]))?;
_tun.set_timeout(Some(std::time::Duration::from_millis(10)))?; _tun.set_nonblocking(true)?;
let tun = tun::tokio::TunInterface::new(_tun)?; let tun = tun::tokio::TunInterface::new(_tun)?;
let private_key = parse_secret_key("GNqIAOCRxjl/cicZyvkvpTklgQuUmGUIEkH7IXF/sEE=")?; let private_key = parse_secret_key("GNqIAOCRxjl/cicZyvkvpTklgQuUmGUIEkH7IXF/sEE=")?;

View file

@ -74,20 +74,12 @@ impl PeerPcb {
}; };
let mut res_buf = [0;1500]; let mut res_buf = [0;1500];
// log::debug!("{} : waiting for readability on {:?}", rid, socket); // log::debug!("{} : waiting for readability on {:?}", rid, socket);
match timeout(Duration::from_millis(10), socket.readable()).await { let len = match socket.recv(&mut res_buf).await {
Ok(l) => {l}
Err(e) => { Err(e) => {
// log::debug!("{}: timeout waiting for readability on {:?}", rid, e); log::error!("{}: error reading from socket: {:?}", rid, e);
continue continue
} }
Ok(Err(e)) => {
log::debug!("{}: error waiting for readability on {:?}", rid, e);
continue
}
Ok(Ok(_)) => {}
};
log::debug!("{}: readable!", rid);
let Ok(len) = socket.try_recv(&mut res_buf) else {
continue
}; };
let mut res_dat = &res_buf[..len]; let mut res_dat = &res_buf[..len];
tracing::debug!("{}: Decapsulating {} bytes", rid, len); tracing::debug!("{}: Decapsulating {} bytes", rid, len);

View file

@ -53,8 +53,8 @@ impl TunInterface {
#[throws] #[throws]
#[instrument] #[instrument]
pub fn set_timeout(&self, timeout: Option<std::time::Duration>) { pub fn set_nonblocking(&mut self, nb: bool) {
self.socket.set_read_timeout(timeout)?; self.socket.set_nonblocking(nb)?;
} }
} }