From fbc93f86672ec8ffede04394f8eb70bd5890d4d6 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Mon, 14 Oct 2024 07:57:14 +0000 Subject: windows: fixes for building pingora-core Includes-commit: 5b5f2aeecf459f633b5459fffba4ad66da495a0a Replicated-from: https://github.com/cloudflare/pingora/pull/429 --- .bleep | 2 +- pingora-core/src/listeners/mod.rs | 1 + pingora-core/src/protocols/digest.rs | 1 + pingora-core/src/protocols/l4/ext.rs | 24 ++++++++++++++++++------ pingora-core/src/protocols/l4/socket.rs | 1 - pingora-core/src/protocols/l4/stream.rs | 2 ++ pingora-core/src/server/mod.rs | 1 + 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.bleep b/.bleep index eccaf86..26298b0 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -0c3b05818a9e9be92d0861b1e72254dadcd978c5 \ No newline at end of file +78684dca2f7fe5d952d3b01faec526a1b1cbad8c \ No newline at end of file diff --git a/pingora-core/src/listeners/mod.rs b/pingora-core/src/listeners/mod.rs index 02a7b83..0c5d78e 100644 --- a/pingora-core/src/listeners/mod.rs +++ b/pingora-core/src/listeners/mod.rs @@ -71,6 +71,7 @@ pub(crate) struct TransportStack { l4: ListenerEndpoint, tls: Option>, // listeners sent from the old process for graceful upgrade + #[cfg(unix)] upgrade_listeners: Option, } diff --git a/pingora-core/src/protocols/digest.rs b/pingora-core/src/protocols/digest.rs index 19dc78d..046b4a1 100644 --- a/pingora-core/src/protocols/digest.rs +++ b/pingora-core/src/protocols/digest.rs @@ -91,6 +91,7 @@ impl SocketDigest { raw_sock, peer_addr: OnceCell::new(), local_addr: OnceCell::new(), + original_dst: OnceCell::new(), } } diff --git a/pingora-core/src/protocols/l4/ext.rs b/pingora-core/src/protocols/l4/ext.rs index b687cc4..706fc7b 100644 --- a/pingora-core/src/protocols/l4/ext.rs +++ b/pingora-core/src/protocols/l4/ext.rs @@ -203,11 +203,16 @@ fn ip_local_port_range(fd: RawFd, low: u16, high: u16) -> io::Result<()> { } } -#[cfg(not(target_os = "linux"))] +#[cfg(all(unix, not(target_os = "linux")))] fn ip_local_port_range(_fd: RawFd, _low: u16, _high: u16) -> io::Result<()> { Ok(()) } +#[cfg(windows)] +fn ip_local_port_range(_fd: RawSocket, _low: u16, _high: u16) -> io::Result<()> { + Ok(()) +} + #[cfg(target_os = "linux")] fn set_so_keepalive(fd: RawFd, val: bool) -> io::Result<()> { set_opt(fd, libc::SOL_SOCKET, libc::SO_KEEPALIVE, val as c_int) @@ -262,11 +267,16 @@ pub fn get_tcp_info(fd: RawFd) -> io::Result { get_opt_sized(fd, libc::IPPROTO_TCP, libc::TCP_INFO) } -#[cfg(not(target_os = "linux"))] +#[cfg(all(unix, not(target_os = "linux")))] pub fn get_tcp_info(_fd: RawFd) -> io::Result { Ok(unsafe { TCP_INFO::new() }) } +#[cfg(windows)] +pub fn get_tcp_info(_fd: RawSocket) -> io::Result { + Ok(unsafe { TCP_INFO::new() }) +} + /// Set the TCP receive buffer size. See SO_RCVBUF. #[cfg(target_os = "linux")] pub fn set_recv_buf(fd: RawFd, val: usize) -> Result<()> { @@ -490,10 +500,12 @@ async fn inner_connect_with Result<()>>( } #[cfg(windows)] - if let Some(baddr) = bind_to { - socket - .bind(*baddr) - .or_err_with(BindError, || format!("failed to bind to socket {}", *baddr))?; + if let Some(bind_to) = bind_to { + if let Some(baddr) = bind_to.addr { + socket + .bind(baddr) + .or_err_with(BindError, || format!("failed to bind to socket {}", baddr))?; + }; }; // TODO: add support for bind on other platforms diff --git a/pingora-core/src/protocols/l4/socket.rs b/pingora-core/src/protocols/l4/socket.rs index 64e0e07..c8413d8 100644 --- a/pingora-core/src/protocols/l4/socket.rs +++ b/pingora-core/src/protocols/l4/socket.rs @@ -246,7 +246,6 @@ impl std::net::ToSocketAddrs for SocketAddr { } } -#[cfg(unix)] impl From for SocketAddr { fn from(sockaddr: StdSockAddr) -> Self { SocketAddr::Inet(sockaddr) diff --git a/pingora-core/src/protocols/l4/stream.rs b/pingora-core/src/protocols/l4/stream.rs index 8ecb515..e561908 100644 --- a/pingora-core/src/protocols/l4/stream.rs +++ b/pingora-core/src/protocols/l4/stream.rs @@ -296,6 +296,7 @@ impl AsyncWrite for RawStreamWrapper { unsafe { match &mut Pin::get_unchecked_mut(self).stream { RawStream::Tcp(s) => Pin::new_unchecked(s).poll_shutdown(cx), + #[cfg(unix)] RawStream::Unix(s) => Pin::new_unchecked(s).poll_shutdown(cx), } } @@ -310,6 +311,7 @@ impl AsyncWrite for RawStreamWrapper { unsafe { match &mut Pin::get_unchecked_mut(self).stream { RawStream::Tcp(s) => Pin::new_unchecked(s).poll_write_vectored(cx, bufs), + #[cfg(unix)] RawStream::Unix(s) => Pin::new_unchecked(s).poll_write_vectored(cx, bufs), } } diff --git a/pingora-core/src/server/mod.rs b/pingora-core/src/server/mod.rs index c86c49e..9762dc8 100644 --- a/pingora-core/src/server/mod.rs +++ b/pingora-core/src/server/mod.rs @@ -246,6 +246,7 @@ impl Server { Ok(Server { services: vec![], + #[cfg(unix)] listen_fds: None, shutdown_watch: tx, shutdown_recv: rx, -- cgit v1.2.3