mirror of
https://github.com/dndx/phantun.git
synced 2025-01-31 12:19:30 +08:00
style(phantun) remove unnecessary tokio::select
call
This commit is contained in:
parent
2f4eaafccd
commit
74183071f1
@ -4,6 +4,7 @@ use fake_tcp::{Socket, Stack};
|
||||
use log::{debug, error, info};
|
||||
use phantun::utils::new_udp_reuseport;
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{Notify, RwLock};
|
||||
@ -14,7 +15,7 @@ use tokio_util::sync::CancellationToken;
|
||||
use phantun::UDP_TTL;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
async fn main() -> io::Result<()> {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let matches = Command::new("Phantun Client")
|
||||
@ -122,8 +123,7 @@ async fn main() {
|
||||
let mut buf_r = [0u8; MAX_PACKET_LEN];
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
Ok((size, addr)) = udp_sock.recv_from(&mut buf_r) => {
|
||||
let (size, addr) = udp_sock.recv_from(&mut buf_r).await?;
|
||||
// seen UDP packet to listening socket, this means:
|
||||
// 1. It is a new UDP connection, or
|
||||
// 2. It is some extra packets not filtered by more specific
|
||||
@ -147,7 +147,11 @@ async fn main() {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert!(connections.write().await.insert(addr, sock.clone()).is_none());
|
||||
assert!(connections
|
||||
.write()
|
||||
.await
|
||||
.insert(addr, sock.clone())
|
||||
.is_none());
|
||||
debug!("inserted fake TCP socket into connection table");
|
||||
|
||||
// spawn "fastpath" UDP socket and task, this will offload main task
|
||||
@ -231,10 +235,8 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tokio::join!(main_loop).0.unwrap();
|
||||
tokio::join!(main_loop).0.unwrap()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ use fake_tcp::packet::MAX_PACKET_LEN;
|
||||
use fake_tcp::Stack;
|
||||
use log::{debug, error, info};
|
||||
use phantun::utils::new_udp_reuseport;
|
||||
use std::io;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::UdpSocket;
|
||||
@ -14,7 +15,7 @@ use tokio_util::sync::CancellationToken;
|
||||
use phantun::UDP_TTL;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
async fn main() -> io::Result<()> {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let matches = Command::new("Phantun Server")
|
||||
@ -128,9 +129,8 @@ async fn main() {
|
||||
} else {
|
||||
"[::]:0"
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let local_addr = udp_sock.local_addr().unwrap();
|
||||
.await?;
|
||||
let local_addr = udp_sock.local_addr()?;
|
||||
drop(udp_sock);
|
||||
|
||||
for i in 0..num_cpus {
|
||||
@ -199,5 +199,5 @@ async fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
tokio::join!(main_loop).0.unwrap();
|
||||
tokio::join!(main_loop).0.unwrap()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user