mirror of https://github.com/ospab/ostp.git
fix(client): bind SOCKS5 UDP socket to IPv6 properly, and fix 100% CPU spin in Android TUN reader
This commit is contained in:
parent
3fd53686f8
commit
f3f2cf1c17
|
|
@ -329,8 +329,8 @@ pub async fn run_native_tunnel_from_fd(
|
||||||
}) {
|
}) {
|
||||||
Ok(Ok(n)) if n > 0 => n as usize,
|
Ok(Ok(n)) if n > 0 => n as usize,
|
||||||
Ok(Ok(n)) if n == 0 => break, // EOF
|
Ok(Ok(n)) if n == 0 => break, // EOF
|
||||||
Ok(Ok(_n)) => continue, // Error reading packet, skip to next
|
Ok(Ok(_n)) => break, // Fatal error reading TUN, must break to prevent 100% CPU spin
|
||||||
Ok(Err(_)) => continue, // Should not happen with try_io
|
Ok(Err(_)) => break,
|
||||||
Err(_would_block) => continue,
|
Err(_would_block) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,10 @@ async fn start_udp_session(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let udp = UdpSocket::bind("127.0.0.1:0").await?;
|
let udp = match relay_addr {
|
||||||
|
SocketAddr::V4(_) => UdpSocket::bind("127.0.0.1:0").await?,
|
||||||
|
SocketAddr::V6(_) => UdpSocket::bind("[::1]:0").await.or_else(|_| UdpSocket::bind("[::]:0").await)?,
|
||||||
|
};
|
||||||
|
|
||||||
let mut buf = vec![0u8; 65536];
|
let mut buf = vec![0u8; 65536];
|
||||||
|
|
||||||
|
|
@ -115,7 +118,7 @@ async fn start_udp_session(
|
||||||
}
|
}
|
||||||
packet.extend_from_slice(&dst.port().to_be_bytes());
|
packet.extend_from_slice(&dst.port().to_be_bytes());
|
||||||
packet.extend_from_slice(&payload);
|
packet.extend_from_slice(&payload);
|
||||||
udp.send_to(&packet, relay_addr).await?;
|
let _ = udp.send_to(&packet, relay_addr).await;
|
||||||
}
|
}
|
||||||
Ok(None) => break,
|
Ok(None) => break,
|
||||||
Err(_) => break, // timeout
|
Err(_) => break, // timeout
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue