netstack3_datagram/
settings.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use netstack3_base::{BufferSizeSettings, PositiveIsize};
6
7/// Settings common to datagram sockets.
8#[derive(Debug, Copy, Clone)]
9pub struct DatagramSettings {
10    /// Send buffer size configuration.
11    ///
12    /// Note that the datagram crate does *NOT* keep the receive buffers for the
13    /// socket, that is delegated to bindings.
14    pub send_buffer: BufferSizeSettings<PositiveIsize>,
15}
16
17/// Maximum send buffer size. Value taken from Linux defaults.
18const MAX_SEND_BUFFER_SIZE: PositiveIsize = PositiveIsize::new(4 * 1024 * 1024).unwrap();
19/// Default send buffer size. Value taken from Linux defaults.
20const DEFAULT_SEND_BUFFER_SIZE: PositiveIsize = PositiveIsize::new(208 * 1024).unwrap();
21/// Minimum send buffer size. Value taken from Linux defaults.
22const MIN_SEND_BUFFER_SIZE: PositiveIsize = PositiveIsize::new(4 * 1024).unwrap();
23
24impl Default for DatagramSettings {
25    fn default() -> Self {
26        Self {
27            send_buffer: BufferSizeSettings::new(
28                MIN_SEND_BUFFER_SIZE,
29                DEFAULT_SEND_BUFFER_SIZE,
30                MAX_SEND_BUFFER_SIZE,
31            )
32            .unwrap(),
33        }
34    }
35}
36
37#[cfg(any(test, feature = "testutils"))]
38impl AsRef<DatagramSettings> for DatagramSettings {
39    fn as_ref(&self) -> &DatagramSettings {
40        self
41    }
42}