disable bound first, go with simple check
This commit is contained in:
parent
ca4da15a4b
commit
ce833c42a6
@ -52,7 +52,7 @@ pub fn new_bound_shared_udp_socket(local_address: SocketAddr) -> Result<Socket,
|
||||
)
|
||||
})?;
|
||||
|
||||
log_net!("created shared udp socket on {:?}", &local_address);
|
||||
log_net!("created bound shared udp socket on {:?}", &local_address);
|
||||
|
||||
Ok(socket)
|
||||
}
|
||||
@ -83,15 +83,15 @@ pub fn new_bound_first_udp_socket(local_address: SocketAddr) -> Result<Socket, S
|
||||
|
||||
// Set 'reuse address' so future binds to this port will succeed
|
||||
// This does not work on Windows, where reuse options can not be set after the bind
|
||||
cfg_if! {
|
||||
if #[cfg(unix)] {
|
||||
socket
|
||||
.set_reuse_address(true)
|
||||
.map_err(|e| format!("Couldn't set reuse address: {}", e))?;
|
||||
socket.set_reuse_port(true).map_err(|e| format!("Couldn't set reuse port: {}", e))?;
|
||||
}
|
||||
}
|
||||
log_net!("created shared udp socket on {:?}", &local_address);
|
||||
// cfg_if! {
|
||||
// if #[cfg(unix)] {
|
||||
// socket
|
||||
// .set_reuse_address(true)
|
||||
// .map_err(|e| format!("Couldn't set reuse address: {}", e))?;
|
||||
// socket.set_reuse_port(true).map_err(|e| format!("Couldn't set reuse port: {}", e))?;
|
||||
// }
|
||||
// }
|
||||
log_net!("created bound first udp socket on {:?}", &local_address);
|
||||
|
||||
Ok(socket)
|
||||
}
|
||||
@ -119,6 +119,7 @@ pub fn new_unbound_shared_tcp_socket(domain: Domain) -> Result<Socket, String> {
|
||||
socket.set_reuse_port(true).map_err(|e| format!("Couldn't set reuse port: {}", e))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
@ -132,6 +133,8 @@ pub fn new_bound_shared_tcp_socket(local_address: SocketAddr) -> Result<Socket,
|
||||
.bind(&socket2_addr)
|
||||
.map_err(|e| format!("failed to bind TCP socket: {}", e))?;
|
||||
|
||||
log_net!("created bound shared tcp socket on {:?}", &local_address);
|
||||
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
@ -167,15 +170,17 @@ pub fn new_bound_first_tcp_socket(local_address: SocketAddr) -> Result<Socket, S
|
||||
.bind(&socket2_addr)
|
||||
.map_err(|e| format!("failed to bind TCP socket: {}", e))?;
|
||||
|
||||
// Set 'reuse address' so future binds to this port will succeed
|
||||
// This does not work on Windows, where reuse options can not be set after the bind
|
||||
cfg_if! {
|
||||
if #[cfg(unix)] {
|
||||
socket
|
||||
.set_reuse_address(true)
|
||||
.map_err(|e| format!("Couldn't set reuse address: {}", e))?;
|
||||
socket.set_reuse_port(true).map_err(|e| format!("Couldn't set reuse port: {}", e))?;
|
||||
}
|
||||
}
|
||||
// // Set 'reuse address' so future binds to this port will succeed
|
||||
// // This does not work on Windows, where reuse options can not be set after the bind
|
||||
// cfg_if! {
|
||||
// if #[cfg(unix)] {
|
||||
// socket
|
||||
// .set_reuse_address(true)
|
||||
// .map_err(|e| format!("Couldn't set reuse address: {}", e))?;
|
||||
// socket.set_reuse_port(true).map_err(|e| format!("Couldn't set reuse port: {}", e))?;
|
||||
// }
|
||||
// }
|
||||
log_net!("created bound first tcp socket on {:?}", &local_address);
|
||||
|
||||
Ok(socket)
|
||||
}
|
||||
|
@ -100,18 +100,18 @@ impl Network {
|
||||
}
|
||||
}
|
||||
if let (Some(bfs4), Some(bfs6)) = (bound_first_socket_v4, bound_first_socket_v6) {
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
//cfg_if! {
|
||||
//if #[cfg(windows)] {
|
||||
// On windows, drop the socket. This is a race condition, but there's
|
||||
// no way around it. This isn't for security anyway, it's to prevent multiple copies of the
|
||||
// app from binding on the same port.
|
||||
drop(bfs4);
|
||||
drop(bfs6);
|
||||
inner.bound_first_udp.insert(udp_port, None);
|
||||
} else {
|
||||
inner.bound_first_udp.insert(udp_port, Some((bfs4, bfs6)));
|
||||
}
|
||||
}
|
||||
//} else {
|
||||
// inner.bound_first_udp.insert(udp_port, Some((bfs4, bfs6)));
|
||||
//}
|
||||
//}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -138,18 +138,18 @@ impl Network {
|
||||
}
|
||||
}
|
||||
if let (Some(bfs4), Some(bfs6)) = (bound_first_socket_v4, bound_first_socket_v6) {
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
//cfg_if! {
|
||||
//if #[cfg(windows)] {
|
||||
// On windows, drop the socket. This is a race condition, but there's
|
||||
// no way around it. This isn't for security anyway, it's to prevent multiple copies of the
|
||||
// app from binding on the same port.
|
||||
drop(bfs4);
|
||||
drop(bfs6);
|
||||
inner.bound_first_tcp.insert(tcp_port, None);
|
||||
} else {
|
||||
inner.bound_first_tcp.insert(tcp_port, Some((bfs4, bfs6)));
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// inner.bound_first_tcp.insert(tcp_port, Some((bfs4, bfs6)));
|
||||
// }
|
||||
//}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user