From 4049ba217fd16b7e5c7b40c0f4631a4753744e42 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 14 Jan 2025 10:50:18 +0100 Subject: [PATCH] windows: remove support for unix socket listening --- src/api/generic_server.rs | 21 ++++++++++++++++----- src/web/web_server.rs | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/api/generic_server.rs b/src/api/generic_server.rs index 283abdd4..1bd62212 100644 --- a/src/api/generic_server.rs +++ b/src/api/generic_server.rs @@ -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 ApiServer { 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 ApiServer { 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() diff --git a/src/web/web_server.rs b/src/web/web_server.rs index 69939f65..4b2c60d7 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -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"); + } } }