忽略io interrupted

This commit is contained in:
lbl8603
2024-06-06 21:42:14 +08:00
parent 13ba7cf0b8
commit 5363558118
5 changed files with 37 additions and 8 deletions
+8 -2
View File
@@ -89,7 +89,10 @@ where
HashMap::with_capacity(32);
let mut extend = [0; BUFFER_SIZE];
loop {
poll.poll(&mut events, None)?;
if let Err(e) = poll.poll(&mut events, None) {
crate::ignore_io_interrupted(e)?;
continue;
}
for event in events.iter() {
match event.token() {
SERVER => loop {
@@ -208,7 +211,10 @@ fn tcp_writable_listen(
),
> = HashMap::with_capacity(32);
loop {
poll.poll(&mut events, None)?;
if let Err(e) = poll.poll(&mut events, None) {
crate::ignore_io_interrupted(e)?;
continue;
}
for event in events.iter() {
match event.token() {
NOTIFY => {
+8 -2
View File
@@ -73,7 +73,10 @@ where
let mut extend = [0; BUFFER_SIZE];
let mut read_map: HashMap<Token, UdpSocket> = HashMap::with_capacity(32);
loop {
poll.poll(&mut events, None)?;
if let Err(e) = poll.poll(&mut events, None) {
crate::ignore_io_interrupted(e)?;
continue;
}
for event in events.iter() {
match event.token() {
NOTIFY => {
@@ -256,7 +259,10 @@ where
let mut events = Events::with_capacity(udps.len());
let mut extend = [0; BUFFER_SIZE];
loop {
poll.poll(&mut events, None)?;
if let Err(e) = poll.poll(&mut events, None) {
crate::ignore_io_interrupted(e)?;
continue;
}
for x in events.iter() {
let index = match x.token() {
NOTIFY => return Ok(()),
+6 -3
View File
@@ -79,14 +79,17 @@ fn start_simple0(
let fd = device.as_tun_fd();
fd.set_nonblock()?;
SourceFd(&fd.as_raw_fd()).register(poll.registry(), FD, Interest::READABLE)?;
let mut evnets = Events::with_capacity(4);
let mut events = Events::with_capacity(4);
#[cfg(not(target_os = "macos"))]
let start = 12;
#[cfg(target_os = "macos")]
let start = 12 - 4;
loop {
poll.poll(&mut evnets, None)?;
for event in evnets.iter() {
if let Err(e) = poll.poll(&mut events, None) {
crate::ignore_io_interrupted(e)?;
continue;
}
for event in events.iter() {
if event.token() == STOP {
return Ok(());
}
+10
View File
@@ -16,4 +16,14 @@ pub mod tun_tap_device;
pub mod util;
pub use handle::callback::*;
pub mod compression;
pub(crate) fn ignore_io_interrupted(e: std::io::Error) -> std::io::Result<()> {
if e.kind() == std::io::ErrorKind::Interrupted {
log::warn!("ignore_io_interrupted");
Ok(())
} else {
Err(e)
}
}
+5 -1
View File
@@ -6,7 +6,11 @@ pub async fn tcp_mapping(bind_addr: SocketAddr, destination: String) -> anyhow::
let tcp_listener = TcpListener::bind(bind_addr)
.await
.with_context(|| format!("TCP binding {:?} failed", bind_addr))?;
tokio::spawn(tcp_mapping_(bind_addr, tcp_listener, destination));
tokio::spawn(async move {
if let Err(e) = tcp_mapping_(bind_addr, tcp_listener, destination).await {
log::warn!("tcp_mapping {:?}", e);
}
});
Ok(())
}