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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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?
11async fn main() {
12 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
13
14 let config = AddrIncomingConfig::new()
15 .tcp_nodelay(true)
16 .tcp_sleep_on_accept_errors(true)
17 .tcp_keepalive(Some(Duration::from_secs(32)))
18 .tcp_keepalive_interval(Some(Duration::from_secs(1)))
19 .tcp_keepalive_retries(Some(1))
20 .build();
21
22 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23 println!("listening on {}", addr);
24 hyper_server::bind(addr)
25 .addr_incoming_config(config)
26 .serve(app.into_make_service())
27 .await
28 .unwrap();
29}
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