add illumos support

This commit is contained in:
Dominik Hassler 2025-02-22 19:16:00 +00:00
parent 16900b9b06
commit 073bae1e73
2 changed files with 8 additions and 4 deletions

View File

@ -68,10 +68,11 @@ pub(crate) fn new_socket(addr: std::net::SocketAddr, reuse: bool) -> Result<TcpS
std::net::SocketAddr::V6(..) => TcpSocket::new_v6()?, std::net::SocketAddr::V6(..) => TcpSocket::new_v6()?,
}; };
if reuse { if reuse {
// windows has no reuse_port, but it's reuse_address // windows has no reuse_port, but its reuse_address
// almost equals to unix's reuse_port + reuse_address, // almost equals to unix's reuse_port + reuse_address,
// though may introduce nondeterministic behavior // though may introduce nondeterministic behavior
#[cfg(unix)] // illumos has no support for SO_REUSEPORT
#[cfg(all(unix, not(target_os = "illumos")))]
socket.set_reuseport(true).ok(); socket.set_reuseport(true).ok();
socket.set_reuseaddr(true).ok(); socket.set_reuseaddr(true).ok();
} }
@ -226,6 +227,8 @@ pub async fn listen_any(port: u16) -> ResultType<TcpListener> {
if let Ok(mut socket) = TcpSocket::new_v6() { if let Ok(mut socket) = TcpSocket::new_v6() {
#[cfg(unix)] #[cfg(unix)]
{ {
// illumos has no support for SO_REUSEPORT
#[cfg(not(target_os = "illumos"))]
socket.set_reuseport(true).ok(); socket.set_reuseport(true).ok();
socket.set_reuseaddr(true).ok(); socket.set_reuseaddr(true).ok();
use std::os::unix::io::{FromRawFd, IntoRawFd}; use std::os::unix::io::{FromRawFd, IntoRawFd};

View File

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