netapp.rs: Set SO_REUSEPORT on listen_addr with TcpSocket.
This commit is contained in:
parent
e3b04e83d7
commit
a1f0985638
1 changed files with 23 additions and 2 deletions
|
@ -13,7 +13,7 @@ use sodiumoxide::crypto::sign::ed25519;
|
|||
|
||||
use futures::stream::futures_unordered::FuturesUnordered;
|
||||
use futures::stream::StreamExt;
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::net::{TcpSocket, TcpStream};
|
||||
use tokio::select;
|
||||
use tokio::sync::{mpsc, watch};
|
||||
|
||||
|
@ -195,7 +195,28 @@ impl NetApp {
|
|||
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);
|
||||
|
||||
let (conn_in, mut conn_out) = mpsc::unbounded_channel();
|
||||
|
|
Loading…
Reference in a new issue