build unix socket support on unix platforms only

yes windows technically supports unix sockets,
but its not as good or the same as actual
nix platform unix sockets

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-09 16:18:56 -05:00 committed by June
parent 39aef8d1b9
commit d84378db18
2 changed files with 41 additions and 31 deletions

View file

@ -92,12 +92,6 @@ features = [
"util",
]
# unix socket support
[dependencies.hyperlocal]
git = "https://github.com/softprops/hyperlocal"
rev = "2ee4d149644600d326559af0d2b235c945b05c04"
features = ["server"]
[dependencies.hyper]
version = "0.14"
features = [
@ -306,6 +300,11 @@ tokio = { version = "1.36.0", features = [
"sync",
"signal",
] }
# unix socket support
[dependencies.hyperlocal]
git = "https://github.com/softprops/hyperlocal"
rev = "2ee4d149644600d326559af0d2b235c945b05c04"
features = ["server"]

View file

@ -35,9 +35,9 @@ use ruma::api::{
};
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use tikv_jemallocator::Jemalloc;
#[cfg(unix)]
use tokio::signal;
use tokio::{
net::UnixListener,
signal,
sync::{oneshot, oneshot::Sender},
task::JoinSet,
};
@ -163,7 +163,15 @@ async fn main() {
/* ad-hoc config validation/checks */
if config.address.is_loopback() {
if config.unix_socket_path.is_some() && !cfg!(unix) {
error!(
"UNIX socket support is only available on *nix platforms. Please remove \"unix_socket_path\" from your \
config."
);
return;
}
if config.address.is_loopback() && cfg!(unix) {
debug!(
"Found loopback listening address {}, running checks if we're in a container.",
config.address
@ -389,6 +397,8 @@ async fn run_server() -> io::Result<()> {
tokio::spawn(shutdown_signal(handle.clone(), tx));
if let Some(path) = &config.unix_socket_path {
#[cfg(unix)]
{
if path.exists() {
warn!(
"UNIX socket path {:#?} already exists (unclean shutdown?), attempting to remove it.",
@ -402,7 +412,7 @@ async fn run_server() -> io::Result<()> {
let socket_perms = config.unix_socket_perms.to_string();
let octal_perms = u32::from_str_radix(&socket_perms, 8).unwrap();
let listener = UnixListener::bind(path.clone())?;
let listener = tokio::net::UnixListener::bind(path.clone())?;
tokio::fs::set_permissions(path, Permissions::from_mode(octal_perms)).await.unwrap();
let socket = SocketIncoming::from_listener(listener);
@ -418,6 +428,7 @@ async fn run_server() -> io::Result<()> {
if let Err(e) = graceful.await {
error!("Server error: {:?}", e);
}
}
} else {
match &config.tls {
Some(tls) => {