windows: remove support for unix socket listening

This commit is contained in:
Brian Picciano 2025-01-14 10:50:18 +01:00
parent ee4c19844b
commit 4049ba217f
2 changed files with 30 additions and 9 deletions

View file

@ -1,6 +1,4 @@
use std::convert::Infallible;
use std::fs::{self, Permissions};
use std::os::unix::fs::PermissionsExt;
use std::sync::Arc;
use std::time::Duration;
@ -18,7 +16,7 @@ use hyper::{HeaderMap, StatusCode};
use hyper_util::rt::TokioIo;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::{TcpListener, TcpStream, UnixListener, UnixStream};
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::watch;
use tokio::time::{sleep_until, Instant};
@ -119,7 +117,13 @@ impl<A: ApiHandler> ApiServer<A> {
let handler = move |request, socketaddr| self.clone().handler(request, socketaddr);
server_loop(server_name, listener, handler, must_exit).await
}
#[cfg(not(windows))]
UnixOrTCPSocketAddress::UnixSocket(ref path) => {
use std::fs::{self, Permissions};
use std::os::unix::fs::PermissionsExt;
use tokio::net::UnixListener;
if path.exists() {
fs::remove_file(path)?
}
@ -135,6 +139,11 @@ impl<A: ApiHandler> ApiServer<A> {
let handler = move |request, socketaddr| self.clone().handler(request, socketaddr);
server_loop(server_name, listener, handler, must_exit).await
}
#[cfg(windows)]
UnixOrTCPSocketAddress::UnixSocket(ref _path) => {
panic!("Unix domain sockets are not supported on windows yet: https://github.com/tokio-rs/tokio/issues/2201");
}
}
}
@ -264,11 +273,13 @@ impl Accept for TcpListener {
}
}
pub struct UnixListenerOn(pub UnixListener, pub String);
#[cfg(not(windows))]
pub struct UnixListenerOn(pub tokio::net::UnixListener, pub String);
#[cfg(not(windows))]
#[async_trait]
impl Accept for UnixListenerOn {
type Stream = UnixStream;
type Stream = tokio::net::UnixStream;
async fn accept(&self) -> std::io::Result<(Self::Stream, String)> {
self.0
.accept()

View file

@ -1,8 +1,6 @@
use std::fs::{self, Permissions};
use std::os::unix::prelude::PermissionsExt;
use std::{convert::Infallible, sync::Arc};
use tokio::net::{TcpListener, UnixListener};
use tokio::net::TcpListener;
use tokio::sync::watch;
use hyper::{
@ -20,7 +18,7 @@ use opentelemetry::{
use crate::error::*;
use garage_api::generic_server::{server_loop, UnixListenerOn};
use garage_api::generic_server::server_loop;
use garage_api::helpers::*;
use garage_api::s3::cors::{add_cors_headers, find_matching_cors_rule, handle_options_for_bucket};
use garage_api::s3::error::{
@ -96,7 +94,14 @@ impl WebServer {
move |stream, socketaddr| self.clone().handle_request(stream, socketaddr);
server_loop(server_name, listener, handler, must_exit).await
}
#[cfg(not(windows))]
UnixOrTCPSocketAddress::UnixSocket(ref path) => {
use std::fs::{self, Permissions};
use std::os::unix::prelude::PermissionsExt;
use tokio::net::UnixListener;
use garage_api::generic_server::UnixListenerOn;
if path.exists() {
fs::remove_file(path)?
}
@ -110,6 +115,11 @@ impl WebServer {
move |stream, socketaddr| self.clone().handle_request(stream, socketaddr);
server_loop(server_name, listener, handler, must_exit).await
}
#[cfg(windows)]
UnixOrTCPSocketAddress::UnixSocket(ref _path) => {
panic!("Unix domain sockets are not supported on windows yet: https://github.com/tokio-rs/tokio/issues/2201");
}
}
}