mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_ws: set so_reuseport on socket, with new create_listener fn
This commit is contained in:
parent
21048727db
commit
e4bdfd06fb
3 changed files with 36 additions and 25 deletions
|
|
@ -5,6 +5,7 @@ use std::io::ErrorKind;
|
|||
use tungstenite::WebSocket;
|
||||
use tungstenite::handshake::{MidHandshake, HandshakeError, server::{ServerHandshake, NoCallback}};
|
||||
use hashbrown::HashMap;
|
||||
use net2::{TcpBuilder, unix::UnixTcpBuilderExt};
|
||||
|
||||
use mio::{Events, Poll, Interest, Token};
|
||||
use mio::net::{TcpListener, TcpStream};
|
||||
|
|
@ -100,6 +101,31 @@ pub fn remove_inactive_connections(
|
|||
}
|
||||
|
||||
|
||||
fn create_listener(config: &Config) -> ::std::net::TcpListener {
|
||||
let mut builder = &{
|
||||
if config.network.address.is_ipv4(){
|
||||
TcpBuilder::new_v4().expect("socket: build")
|
||||
} else {
|
||||
TcpBuilder::new_v6().expect("socket: build")
|
||||
}
|
||||
};
|
||||
|
||||
builder = builder.reuse_port(true)
|
||||
.expect("socket: set reuse port");
|
||||
|
||||
builder = builder.bind(&config.network.address)
|
||||
.expect(&format!("socket: bind to {}", &config.network.address));
|
||||
|
||||
let listener = builder.listen(128)
|
||||
.expect("tcpbuilder to tcp listener");
|
||||
|
||||
listener.set_nonblocking(true)
|
||||
.expect("socket: set nonblocking");
|
||||
|
||||
listener
|
||||
}
|
||||
|
||||
|
||||
pub fn run_socket_worker(
|
||||
config: Config,
|
||||
socket_worker_index: usize,
|
||||
|
|
@ -110,7 +136,7 @@ pub fn run_socket_worker(
|
|||
config.network.poll_timeout_milliseconds
|
||||
);
|
||||
|
||||
let mut listener = TcpListener::bind(config.network.address).unwrap();
|
||||
let mut listener = TcpListener::from_std(create_listener(&config));
|
||||
let mut poll = Poll::new().expect("create poll");
|
||||
let mut events = Events::with_capacity(config.network.poll_event_capacity);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue