update
parent
2dae1f600c
commit
18a87198ff
10
src/args.rs
10
src/args.rs
|
@ -462,6 +462,7 @@ impl Args {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum BindAddr {
|
pub enum BindAddr {
|
||||||
IpAddr(IpAddr),
|
IpAddr(IpAddr),
|
||||||
|
#[cfg(unix)]
|
||||||
SocketPath(String),
|
SocketPath(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,11 +476,10 @@ impl BindAddr {
|
||||||
bind_addrs.push(BindAddr::IpAddr(v));
|
bind_addrs.push(BindAddr::IpAddr(v));
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
if cfg!(unix) {
|
#[cfg(unix)]
|
||||||
bind_addrs.push(BindAddr::SocketPath(addr.to_string()));
|
bind_addrs.push(BindAddr::SocketPath(addr.to_string()));
|
||||||
} else {
|
#[cfg(not(unix))]
|
||||||
invalid_addrs.push(*addr);
|
invalid_addrs.push(*addr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -140,6 +140,7 @@ fn serve(args: Args, running: Arc<AtomicBool>) -> Result<Vec<JoinHandle<()>>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
BindAddr::SocketPath(path) => {
|
BindAddr::SocketPath(path) => {
|
||||||
let socket_path = if path.starts_with("@")
|
let socket_path = if path.starts_with("@")
|
||||||
&& cfg!(any(target_os = "linux", target_os = "android"))
|
&& cfg!(any(target_os = "linux", target_os = "android"))
|
||||||
|
@ -152,22 +153,19 @@ fn serve(args: Args, running: Arc<AtomicBool>) -> Result<Vec<JoinHandle<()>>> {
|
||||||
let _ = std::fs::remove_file(path);
|
let _ = std::fs::remove_file(path);
|
||||||
path.into()
|
path.into()
|
||||||
};
|
};
|
||||||
#[cfg(unix)]
|
let listener = tokio::net::UnixListener::bind(socket_path)
|
||||||
{
|
.with_context(|| format!("Failed to bind `{}`", path))?;
|
||||||
let listener = tokio::net::UnixListener::bind(socket_path)
|
let handle = tokio::spawn(async move {
|
||||||
.with_context(|| format!("Failed to bind `{}`", path))?;
|
loop {
|
||||||
let handle = tokio::spawn(async move {
|
let Ok((stream, _addr)) = listener.accept().await else {
|
||||||
loop {
|
continue;
|
||||||
let Ok((stream, _addr)) = listener.accept().await else {
|
};
|
||||||
continue;
|
let stream = TokioIo::new(stream);
|
||||||
};
|
tokio::spawn(handle_stream(server_handle.clone(), stream, None));
|
||||||
let stream = TokioIo::new(stream);
|
}
|
||||||
tokio::spawn(handle_stream(server_handle.clone(), stream, None));
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
handles.push(handle);
|
handles.push(handle);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +235,7 @@ fn check_addrs(args: &Args) -> Result<(Vec<BindAddr>, Vec<BindAddr>)> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
#[cfg(unix)]
|
||||||
_ => {
|
_ => {
|
||||||
new_addrs.push(bind_addr.clone());
|
new_addrs.push(bind_addr.clone());
|
||||||
print_addrs.push(bind_addr.clone())
|
print_addrs.push(bind_addr.clone())
|
||||||
|
@ -280,6 +279,7 @@ fn print_listening(args: &Args, print_addrs: &[BindAddr]) -> Result<String> {
|
||||||
};
|
};
|
||||||
format!("{}://{}{}", protocol, addr, args.uri_prefix)
|
format!("{}://{}{}", protocol, addr, args.uri_prefix)
|
||||||
}
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
BindAddr::SocketPath(path) => path.to_string(),
|
BindAddr::SocketPath(path) => path.to_string(),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
Loading…
Reference in New Issue