use std::{cmp::min, ffi::c_int, time::Duration};
use crate::{IPPROTO_TCP, SockOptMarker, OptRMarker, OptWMarker, TCP_KEEPINTVL};
#[repr(transparent)]
#[derive(Debug, Clone, Copy)]
pub struct IpProtoKeepIntvl(c_int);
impl SockOptMarker for IpProtoKeepIntvl
{
const SO_LEVEL: c_int = IPPROTO_TCP;
const SO_OPTNAME: c_int = TCP_KEEPINTVL;
type DataType = Duration;
type InputType = c_int;
#[inline]
fn from(value: Self::InputType) -> Self
{
return Self(value);
}
#[inline]
fn get(self) -> Self::DataType
{
return Duration::from_secs(self.0 as u64);
}
#[inline]
fn from_user(sz: Self::DataType) -> Self where Self: Sized
{
return Self(min(sz.as_secs(), i32::MAX as u64) as Self::InputType);
}
}
impl OptRMarker for IpProtoKeepIntvl {}
impl OptWMarker for IpProtoKeepIntvl {}