Struct 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

Source

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?
examples/configure_addr_incoming.rs (line 14)
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}
Source

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?
examples/configure_addr_incoming.rs (line 20)
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}
Source

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 is true.
§Returns

A mutable reference to the current AddrIncomingConfig.

Examples found in repository?
examples/configure_addr_incoming.rs (line 16)
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}
Source

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 to None disables keepalive probes. Default is None.
§Returns

A mutable reference to the current AddrIncomingConfig.

Examples found in repository?
examples/configure_addr_incoming.rs (line 17)
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}
Source

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?
examples/configure_addr_incoming.rs (line 18)
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}
Source

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?
examples/configure_addr_incoming.rs (line 19)
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}
Source

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 enable TCP_NODELAY. Default is false.
§Returns

A mutable reference to the current AddrIncomingConfig.

Examples found in repository?
examples/configure_addr_incoming.rs (line 15)
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

Source§

fn clone(&self) -> AddrIncomingConfig

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AddrIncomingConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AddrIncomingConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more