nix usage

This commit is contained in:
ssrlive 2024-10-20 16:38:14 +08:00
parent b21d7a6c2c
commit 060474fcc7
3 changed files with 7 additions and 7 deletions

View file

@ -42,11 +42,6 @@ url = "2"
[target.'cfg(target_os="linux")'.dependencies]
serde = { version = "1", features = ["derive"] }
bincode = "1"
nix = { version = "0.29", default-features = false, features = [
"fs",
"socket",
"uio",
] }
[target.'cfg(target_os="android")'.dependencies]
android_logger = "0.14"
@ -54,6 +49,11 @@ jni = { version = "0.21", default-features = false }
[target.'cfg(unix)'.dependencies]
daemonize = "0.5"
nix = { version = "0.29", default-features = false, features = [
"fs",
"socket",
"uio",
] }
[target.'cfg(target_os = "windows")'.dependencies]
windows-service = "0.7"

View file

@ -180,7 +180,7 @@ pub fn parse_udp(udp_mtu: u16, data_len: usize, data: &[u8]) -> Result<(&[u8], u
async fn process_udp(addr: SocketAddr, udp_timeout: u64, tx: Sender<Vec<u8>>, con: &mut UdpRequest) -> Result<()> {
let std_sock = std::net::UdpSocket::bind("0.0.0.0:0")?;
std_sock.set_nonblocking(true)?;
#[cfg(target_os = "linux")]
#[cfg(unix)]
nix::sys::socket::setsockopt(&std_sock, nix::sys::socket::sockopt::ReuseAddr, &true)?;
let socket = UdpSocket::from_std(std_sock)?;
socket.send_to(&con.data, &con.server_addr).await?;

View file

@ -6,7 +6,7 @@ pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),
#[cfg(target_os = "linux")]
#[cfg(unix)]
#[error("nix::errno::Errno {0:?}")]
NixErrno(#[from] nix::errno::Errno),