#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub enum RetriesOrphan
{
Special,
Retries(NonZeroU8),
}
impl ParseNumber for RetriesOrphan
{
#[inline(always)]
fn parse_number(bytes: &[u8], radix: Radix, parse_byte: impl Fn(Radix, u8) -> Result<u8, ParseNumberError>) -> Result<Self, ParseNumberError>
{
use self::RetriesOrphan::*;
let value = u8::parse_number(bytes, radix, parse_byte)?;
Ok
(
if likely!(value == 0)
{
Special
}
else
{
Retries(new_non_zero_u8(value))
}
)
}
}
impl Default for RetriesOrphan
{
#[inline(always)]
fn default() -> Self
{
Self::UsualGlobalDefault
}
}
impl RetriesOrphan
{
pub const UsualGlobalDefault: Self = RetriesOrphan::Special;
#[inline(always)]
pub fn global_default(proc_path: &ProcPath) -> Self
{
Self::sys_net_ipv4_tcp_orphan_retries_file_path(proc_path).read_value().unwrap()
}
#[inline(always)]
pub fn set_global_default(self, proc_path: &ProcPath) -> io::Result<()>
{
assert_effective_user_id_is_root("write to /proc/sys/net/ipv4/tcp_orphan_retries");
let file_path = Self::sys_net_ipv4_tcp_orphan_retries_file_path(proc_path);
if file_path.exists()
{
use self::RetriesOrphan::*;
let value = match self
{
Special => 0u8,
Retries(value) => value.get(),
};
file_path.write_value(UnpaddedDecimalInteger(value))
}
else
{
Ok(())
}
}
#[inline(always)]
fn sys_net_ipv4_tcp_orphan_retries_file_path(proc_path: &ProcPath) -> PathBuf
{
proc_path.sys_net_ipv4_file_path("tcp_orphan_retries")
}
}