mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_http: config: set poll timeout in microseconds, default to 10000
This commit is contained in:
parent
6471e4a8a9
commit
19ee41eb72
2 changed files with 22 additions and 16 deletions
|
|
@ -30,7 +30,7 @@ pub struct NetworkConfig {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub tls: TlsConfig,
|
pub tls: TlsConfig,
|
||||||
pub poll_event_capacity: usize,
|
pub poll_event_capacity: usize,
|
||||||
pub poll_timeout_milliseconds: u64,
|
pub poll_timeout_microseconds: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@ impl Default for NetworkConfig {
|
||||||
ipv6_only: false,
|
ipv6_only: false,
|
||||||
tls: TlsConfig::default(),
|
tls: TlsConfig::default(),
|
||||||
poll_event_capacity: 4096,
|
poll_event_capacity: 4096,
|
||||||
poll_timeout_milliseconds: 50,
|
poll_timeout_microseconds: 10_000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,8 @@ pub fn run_poll_loop(
|
||||||
listener: ::std::net::TcpListener,
|
listener: ::std::net::TcpListener,
|
||||||
opt_tls_acceptor: Option<TlsAcceptor>,
|
opt_tls_acceptor: Option<TlsAcceptor>,
|
||||||
){
|
){
|
||||||
let poll_timeout = Duration::from_millis(
|
let poll_timeout = Duration::from_micros(
|
||||||
config.network.poll_timeout_milliseconds
|
config.network.poll_timeout_microseconds
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut listener = TcpListener::from_std(listener);
|
let mut listener = TcpListener::from_std(listener);
|
||||||
|
|
@ -81,41 +81,43 @@ pub fn run_poll_loop(
|
||||||
loop {
|
loop {
|
||||||
poll.poll(&mut events, Some(poll_timeout))
|
poll.poll(&mut events, Some(poll_timeout))
|
||||||
.expect("failed polling");
|
.expect("failed polling");
|
||||||
|
|
||||||
let valid_until = ValidUntil::new(config.cleaning.max_connection_age);
|
|
||||||
|
|
||||||
for event in events.iter(){
|
for event in events.iter(){
|
||||||
let token = event.token();
|
let token = event.token();
|
||||||
|
|
||||||
if token.0 == 0 {
|
if token.0 == 0 {
|
||||||
accept_new_streams(
|
accept_new_streams(
|
||||||
|
&config,
|
||||||
&mut listener,
|
&mut listener,
|
||||||
&mut poll,
|
&mut poll,
|
||||||
&mut connections,
|
&mut connections,
|
||||||
valid_until,
|
|
||||||
&mut poll_token_counter,
|
&mut poll_token_counter,
|
||||||
&opt_tls_acceptor,
|
&opt_tls_acceptor,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
handle_connection_read_event(
|
handle_connection_read_event(
|
||||||
|
&config,
|
||||||
socket_worker_index,
|
socket_worker_index,
|
||||||
&request_channel_sender,
|
&request_channel_sender,
|
||||||
&mut local_responses,
|
&mut local_responses,
|
||||||
&mut connections,
|
&mut connections,
|
||||||
token,
|
token,
|
||||||
valid_until,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
send_responses(
|
let response_drain = response_channel_receiver.drain();
|
||||||
local_responses.drain(..),
|
|
||||||
response_channel_receiver.drain(),
|
if !(local_responses.is_empty() & (response_drain.len() == 0)) {
|
||||||
&mut connections
|
send_responses(
|
||||||
);
|
local_responses.drain(..),
|
||||||
|
response_drain,
|
||||||
|
&mut connections
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove inactive connections, but not every iteration
|
// Remove inactive connections, but not every iteration
|
||||||
if iter_counter % 128 == 0 {
|
if iter_counter % 32768 == 0 {
|
||||||
remove_inactive_connections(&mut connections);
|
remove_inactive_connections(&mut connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,13 +127,15 @@ pub fn run_poll_loop(
|
||||||
|
|
||||||
|
|
||||||
fn accept_new_streams(
|
fn accept_new_streams(
|
||||||
|
config: &Config,
|
||||||
listener: &mut TcpListener,
|
listener: &mut TcpListener,
|
||||||
poll: &mut Poll,
|
poll: &mut Poll,
|
||||||
connections: &mut ConnectionMap,
|
connections: &mut ConnectionMap,
|
||||||
valid_until: ValidUntil,
|
|
||||||
poll_token_counter: &mut Token,
|
poll_token_counter: &mut Token,
|
||||||
opt_tls_acceptor: &Option<Arc<TlsAcceptor>>,
|
opt_tls_acceptor: &Option<Arc<TlsAcceptor>>,
|
||||||
){
|
){
|
||||||
|
let valid_until = ValidUntil::new(config.cleaning.max_connection_age);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match listener.accept(){
|
match listener.accept(){
|
||||||
Ok((mut stream, _)) => {
|
Ok((mut stream, _)) => {
|
||||||
|
|
@ -173,13 +177,15 @@ fn accept_new_streams(
|
||||||
/// On the stream given by poll_token, get TLS up and running if requested,
|
/// On the stream given by poll_token, get TLS up and running if requested,
|
||||||
/// then read requests and pass on through channel.
|
/// then read requests and pass on through channel.
|
||||||
pub fn handle_connection_read_event(
|
pub fn handle_connection_read_event(
|
||||||
|
config: &Config,
|
||||||
socket_worker_index: usize,
|
socket_worker_index: usize,
|
||||||
request_channel_sender: &RequestChannelSender,
|
request_channel_sender: &RequestChannelSender,
|
||||||
local_responses: &mut Vec<(ConnectionMeta, Response)>,
|
local_responses: &mut Vec<(ConnectionMeta, Response)>,
|
||||||
connections: &mut ConnectionMap,
|
connections: &mut ConnectionMap,
|
||||||
poll_token: Token,
|
poll_token: Token,
|
||||||
valid_until: ValidUntil,
|
|
||||||
){
|
){
|
||||||
|
let valid_until = ValidUntil::new(config.cleaning.max_connection_age);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Get connection, updating valid_until
|
// Get connection, updating valid_until
|
||||||
let connection = if let Some(c) = connections.get_mut(&poll_token){
|
let connection = if let Some(c) = connections.get_mut(&poll_token){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue