Skip to content

Commit

Permalink
Add a conditional check on udp reuse address setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjjo committed Dec 19, 2024
1 parent 81ccd9d commit ba5be63
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/virtual-net/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl VirtualNetworking for LocalNetworking {
async fn bind_udp(
&self,
addr: SocketAddr,
_reuse_port: bool,
reuse_port: bool,
reuse_addr: bool,
) -> Result<Box<dyn VirtualUdpSocket + Sync>> {
use socket2::{Socket, Domain, Type};
Expand All @@ -116,12 +116,15 @@ impl VirtualNetworking for LocalNetworking {
}

let std_sock = Socket::new(Domain::IPV4, Type::DGRAM, None).map_err(io_err_into_net_error)?;
std_sock.set_reuse_address(reuse_addr).map_err(io_err_into_net_error)?;
//std_sock.set_reuse_port(reuse_port).map_err(io_err_into_net_error)?;

std_sock.bind(&addr.into()).map_err(io_err_into_net_error)?;

let socket = mio::net::UdpSocket::from_std(std_sock.into());
#[cfg(not(windows))]
let socket = {
std_sock.set_reuse_address(reuse_addr).map_err(io_err_into_net_error)?;
std_sock.set_reuse_port(reuse_port).map_err(io_err_into_net_error)?;
std_sock.bind(&addr.into()).map_err(io_err_into_net_error)?;
mio::net::UdpSocket::from_std(std_sock.into())
};
#[cfg(windows)]
let socket = mio::net::UdpSocket::bind(addr).map_err(io_err_into_net_error)?;

#[allow(unused_mut)]
let mut ret = LocalUdpSocket {
Expand Down

0 comments on commit ba5be63

Please sign in to comment.