netapp.rs: Set SO_REUSEPORT on listen_addr with TcpSocket. #9

Closed
jpds wants to merge 11 commits from jpds/netapp:so-reuseport into main
Showing only changes of commit a1f0985638 - Show all commits

View file

@ -13,7 +13,7 @@ use sodiumoxide::crypto::sign::ed25519;
use futures::stream::futures_unordered::FuturesUnordered; use futures::stream::futures_unordered::FuturesUnordered;
use futures::stream::StreamExt; use futures::stream::StreamExt;
use tokio::net::{TcpListener, TcpStream}; use tokio::net::{TcpSocket, TcpStream};
use tokio::select; use tokio::select;
use tokio::sync::{mpsc, watch}; use tokio::sync::{mpsc, watch};
@ -195,7 +195,28 @@ impl NetApp {
error!("Trying to listen on NetApp but we're already listening!"); error!("Trying to listen on NetApp but we're already listening!");
} }
let listener = TcpListener::bind(listen_addr).await.unwrap(); let listen_addr_socket = match listen_addr {
SocketAddr::V4(_) => TcpSocket::new_v4(),
SocketAddr::V6(_) => TcpSocket::new_v6(),
}
.unwrap();
listen_addr_socket
.set_reuseaddr(true)
.expect("Unable to set SO_REUSEADDR on socket");
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
listen_addr_socket
.set_reuseport(true)
.expect("Unable to set SO_REUSEPORT on socket");
listen_addr_socket
.bind(listen_addr)
.expect("Unable to bind on listen_addr socket");
let listener = listen_addr_socket
.listen(1024)
.expect("Unable to listen on configured address");
info!("Listening on {}", listen_addr); info!("Listening on {}", listen_addr);
let (conn_in, mut conn_out) = mpsc::unbounded_channel(); let (conn_in, mut conn_out) = mpsc::unbounded_channel();