diff options
author | rustdesk <[email protected]> | 2024-05-24 18:37:11 +0800 |
---|---|---|
committer | rustdesk <[email protected]> | 2024-05-24 18:37:11 +0800 |
commit | 5078a1f7971f4b5a507bd7164f1eb960e5195369 (patch) | |
tree | 4ec095d45c39892d1be5b0d21d3f9ce6d99e2b57 /libs | |
parent | a22dacce0c9a0444bdffc5529d8645a599b07374 (diff) | |
download | rustdesk-server-5078a1f7971f4b5a507bd7164f1eb960e5195369.tar.gz rustdesk-server-5078a1f7971f4b5a507bd7164f1eb960e5195369.zip |
reuse port, and revert hbbr `-k`1.1.11-1
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hbb_common/src/tcp.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libs/hbb_common/src/tcp.rs b/libs/hbb_common/src/tcp.rs index f574e83..046d901 100644 --- a/libs/hbb_common/src/tcp.rs +++ b/libs/hbb_common/src/tcp.rs @@ -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}; |