clean up c::linger conversion

This commit is contained in:
ibraheemdev 2021-08-30 14:00:21 -04:00
parent 3b6777f1ab
commit dafc14794f
2 changed files with 2 additions and 2 deletions

View File

@ -387,7 +387,7 @@ pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
let linger = libc::linger {
l_onoff: linger.is_some() as libc::c_int,
l_linger: linger.map(|dur| dur.as_secs() as libc::c_int).unwrap_or_default(),
l_linger: linger.unwrap_or_default().as_secs() as libc::c_int,
};
setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)

View File

@ -449,7 +449,7 @@ pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
let linger = c::linger {
l_onoff: linger.is_some() as c_ushort,
l_linger: linger.map(|dur| dur.as_secs() as c_ushort).unwrap_or_default(),
l_linger: linger.unwrap_or_default().as_secs() as c_ushort,
};
net::setsockopt(self, c::SOL_SOCKET, c::SO_LINGER, linger)