Skip to content

Commit

Permalink
windows: fixes for building pingora-core
Browse files Browse the repository at this point in the history
Includes-commit: 5b5f2ae
Replicated-from: #429
  • Loading branch information
fredr authored and drcaramelsyrup committed Oct 18, 2024
1 parent 2c6190c commit fbc93f8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0c3b05818a9e9be92d0861b1e72254dadcd978c5
78684dca2f7fe5d952d3b01faec526a1b1cbad8c
1 change: 1 addition & 0 deletions pingora-core/src/listeners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub(crate) struct TransportStack {
l4: ListenerEndpoint,
tls: Option<Arc<Acceptor>>,
// listeners sent from the old process for graceful upgrade
#[cfg(unix)]
upgrade_listeners: Option<ListenFds>,
}

Expand Down
1 change: 1 addition & 0 deletions pingora-core/src/protocols/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl SocketDigest {
raw_sock,
peer_addr: OnceCell::new(),
local_addr: OnceCell::new(),
original_dst: OnceCell::new(),
}
}

Expand Down
24 changes: 18 additions & 6 deletions pingora-core/src/protocols/l4/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -262,11 +267,16 @@ pub fn get_tcp_info(fd: RawFd) -> io::Result<TCP_INFO> {
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<TCP_INFO> {
Ok(unsafe { TCP_INFO::new() })
}

#[cfg(windows)]
pub fn get_tcp_info(_fd: RawSocket) -> io::Result<TCP_INFO> {
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<()> {
Expand Down Expand Up @@ -490,10 +500,12 @@ async fn inner_connect_with<F: FnOnce(&TcpSocket) -> 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

Expand Down
1 change: 0 additions & 1 deletion pingora-core/src/protocols/l4/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ impl std::net::ToSocketAddrs for SocketAddr {
}
}

#[cfg(unix)]
impl From<StdSockAddr> for SocketAddr {
fn from(sockaddr: StdSockAddr) -> Self {
SocketAddr::Inet(sockaddr)
Expand Down
2 changes: 2 additions & 0 deletions pingora-core/src/protocols/l4/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand All @@ -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),
}
}
Expand Down
1 change: 1 addition & 0 deletions pingora-core/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl Server {

Ok(Server {
services: vec![],
#[cfg(unix)]
listen_fds: None,
shutdown_watch: tx,
shutdown_recv: rx,
Expand Down

0 comments on commit fbc93f8

Please sign in to comment.