Skip to content

Commit

Permalink
Address the platform compiling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanYuYuan committed Mar 1, 2024
1 parent 101468a commit 6a19387
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions commons/zenoh-util/src/std_only/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,22 +423,24 @@ pub fn get_ipv6_ipaddrs(interface: Option<&str>) -> Vec<IpAddr> {
.collect()
}

#[cfg(target_os = "linux")]
pub fn set_bind_to_device_tcp_socket(socket: &TcpSocket, iface: Option<&str>) -> ZResult<()> {
#[cfg(any(target_os = "macos", target_os = "windows"))]
bail!("Binding the socket {socket:?} to the interface {iface:?} is not supported on macOS and Windows");

#[cfg(target_os = "linux")]
socket.bind_device(iface.map(|x| x.as_bytes()))?;

Ok(())
}

#[cfg(target_os = "linux")]
pub fn set_bind_to_device_udp_socket(socket: &UdpSocket, iface: Option<&str>) -> ZResult<()> {
#[cfg(any(target_os = "macos", target_os = "windows"))]
bail!("Binding the socket {socket:?} to the interface {iface:?} is not supported on macOS and Windows");

#[cfg(target_os = "linux")]
socket.bind_device(iface.map(|x| x.as_bytes()))?;

Ok(())
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
pub fn set_bind_to_device_tcp_socket(socket: &TcpSocket, iface: Option<&str>) -> ZResult<()> {
bail!("Binding the socket {socket:?} to the interface {iface:?} is not supported on macOS and Windows");
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
pub fn set_bind_to_device_udp_socket(socket: &UdpSocket, iface: Option<&str>) -> ZResult<()> {
bail!("Binding the socket {socket:?} to the interface {iface:?} is not supported on macOS and Windows");
}

0 comments on commit 6a19387

Please sign in to comment.