Dominik Hassler 1 год назад
Родитель
Сommit
041a603173
2 измененных файлов с 12 добавлено и 9 удалено
  1. 8 6
      libs/hbb_common/src/tcp.rs
  2. 4 3
      libs/hbb_common/src/udp.rs

+ 8 - 6
libs/hbb_common/src/tcp.rs

@@ -62,10 +62,11 @@ fn new_socket(addr: std::net::SocketAddr, reuse: bool) -> Result<TcpSocket, std:
62 62
         std::net::SocketAddr::V6(..) => TcpSocket::new_v6()?,
63 63
     };
64 64
     if reuse {
65
-        // windows has no reuse_port, but it's reuse_address
65
+        // windows has no reuse_port, but its reuse_address
66 66
         // almost equals to unix's reuse_port + reuse_address,
67
-        // though may introduce nondeterministic behavior
68
-        #[cfg(unix)]
67
+        // though may introduce nondeterministic behavior.
68
+        // illumos has no support for SO_REUSEPORT
69
+        #[cfg(all(unix, not(target_os = "illumos")))]
69 70
         socket.set_reuseport(true)?;
70 71
         socket.set_reuseaddr(true)?;
71 72
     }
@@ -263,10 +264,11 @@ pub async fn new_listener<T: ToSocketAddrs>(addr: T, reuse: bool) -> ResultType<
263 264
 pub async fn listen_any(port: u16, reuse: bool) -> ResultType<TcpListener> {
264 265
     if let Ok(mut socket) = TcpSocket::new_v6() {
265 266
         if reuse {
266
-            // windows has no reuse_port, but it's reuse_address
267
+            // windows has no reuse_port, but its reuse_address
267 268
             // almost equals to unix's reuse_port + reuse_address,
268
-            // though may introduce nondeterministic behavior
269
-            #[cfg(unix)]
269
+            // though may introduce nondeterministic behavior.
270
+            // illumos has no support for SO_REUSEPORT
271
+            #[cfg(all(unix, not(target_os = "illumos")))]
270 272
             socket.set_reuseport(true).ok();
271 273
             socket.set_reuseaddr(true).ok();
272 274
         }

+ 4 - 3
libs/hbb_common/src/udp.rs

@@ -20,10 +20,11 @@ fn new_socket(addr: SocketAddr, reuse: bool, buf_size: usize) -> Result<Socket,
20 20
         SocketAddr::V6(..) => Socket::new(Domain::ipv6(), Type::dgram(), None),
21 21
     }?;
22 22
     if reuse {
23
-        // windows has no reuse_port, but it's reuse_address
23
+        // windows has no reuse_port, but its reuse_address
24 24
         // almost equals to unix's reuse_port + reuse_address,
25
-        // though may introduce nondeterministic behavior
26
-        #[cfg(unix)]
25
+        // though may introduce nondeterministic behavior.
26
+        // illumos has no support for SO_REUSEPORT
27
+        #[cfg(all(unix, not(target_os = "illumos")))]
27 28
         socket.set_reuse_port(true)?;
28 29
         socket.set_reuse_address(true)?;
29 30
     }