reuse port, and revert hbbr -k

This commit is contained in:
rustdesk
2024-05-24 18:37:11 +08:00
parent a22dacce0c
commit 5078a1f797
7 changed files with 20 additions and 8 deletions

View File

@@ -260,8 +260,16 @@ pub async fn new_listener<T: ToSocketAddrs>(addr: T, reuse: bool) -> ResultType<
}
}
pub async fn listen_any(port: u16) -> ResultType<TcpListener> {
pub async fn listen_any(port: u16, reuse: bool) -> ResultType<TcpListener> {
if let Ok(mut socket) = TcpSocket::new_v6() {
if reuse {
// windows has no reuse_port, but it's reuse_address
// almost equals to unix's reuse_port + reuse_address,
// though may introduce nondeterministic behavior
#[cfg(unix)]
socket.set_reuseport(true).ok();
socket.set_reuseaddr(true).ok();
}
#[cfg(unix)]
{
use std::os::unix::io::{FromRawFd, IntoRawFd};