Struct hyper_server::AddrIncomingConfig
source · pub struct AddrIncomingConfig { /* private fields */ }
Expand description
Configuration settings for the AddrIncoming
.
This configuration structure is designed to be used in conjunction with the
AddrIncoming
type from the Hyper crate.
It provides a mechanism to customize server settings like TCP keepalive probes,
error handling, and other TCP socket-level configurations.
Implementations§
source§impl AddrIncomingConfig
impl AddrIncomingConfig
sourcepub fn new() -> AddrIncomingConfig
pub fn new() -> AddrIncomingConfig
Creates a new AddrIncomingConfig
with default settings.
Default Settings
- Sleep on accept errors:
true
- TCP keepalive probes: Disabled (
None
) - Duration between keepalive retransmissions: None
- Number of keepalive retransmissions: None
TCP_NODELAY
option:false
Returns
A new AddrIncomingConfig
instance with default settings.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
sourcepub fn build(&mut self) -> Self
pub fn build(&mut self) -> Self
Creates a cloned copy of the current configuration.
This method can be useful when you want to preserve the original settings and create a modified configuration based on the current one.
Returns
A cloned AddrIncomingConfig
.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
sourcepub fn tcp_sleep_on_accept_errors(&mut self, val: bool) -> &mut Self
pub fn tcp_sleep_on_accept_errors(&mut self, val: bool) -> &mut Self
Specifies whether to pause (sleep) when an error occurs while accepting a connection.
This can be useful to prevent rapidly exhausting file descriptors in scenarios where errors might be transient or frequent.
Parameters
val
: Whether to sleep on accept errors. Default istrue
.
Returns
A mutable reference to the current AddrIncomingConfig
.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
sourcepub fn tcp_keepalive(&mut self, val: Option<Duration>) -> &mut Self
pub fn tcp_keepalive(&mut self, val: Option<Duration>) -> &mut Self
Configures the frequency of TCP keepalive probes.
TCP keepalive probes are used to detect whether a peer is still connected.
Parameters
val
: Duration between keepalive probes. Setting toNone
disables keepalive probes. Default isNone
.
Returns
A mutable reference to the current AddrIncomingConfig
.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
sourcepub fn tcp_keepalive_interval(&mut self, val: Option<Duration>) -> &mut Self
pub fn tcp_keepalive_interval(&mut self, val: Option<Duration>) -> &mut Self
Configures the duration between two successive TCP keepalive retransmissions.
If an acknowledgment to a previous keepalive probe isn’t received within this duration, a new probe will be sent.
Parameters
val
: Duration between keepalive retransmissions. Default is no interval (None
).
Returns
A mutable reference to the current AddrIncomingConfig
.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
sourcepub fn tcp_keepalive_retries(&mut self, val: Option<u32>) -> &mut Self
pub fn tcp_keepalive_retries(&mut self, val: Option<u32>) -> &mut Self
Configures the number of times to retransmit a TCP keepalive probe if no acknowledgment is received.
After the specified number of retransmissions, the remote end is considered unavailable.
Parameters
val
: Number of retransmissions before considering the remote end unavailable. Default is no retry (None
).
Returns
A mutable reference to the current AddrIncomingConfig
.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
sourcepub fn tcp_nodelay(&mut self, val: bool) -> &mut Self
pub fn tcp_nodelay(&mut self, val: bool) -> &mut Self
Configures the TCP_NODELAY
option for accepted connections.
When enabled, this option disables Nagle’s algorithm, which can reduce latencies for small packets.
Parameters
val
: Whether to enableTCP_NODELAY
. Default isfalse
.
Returns
A mutable reference to the current AddrIncomingConfig
.
Examples found in repository?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_server::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
Trait Implementations§
source§impl Clone for AddrIncomingConfig
impl Clone for AddrIncomingConfig
source§fn clone(&self) -> AddrIncomingConfig
fn clone(&self) -> AddrIncomingConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more