提交 dafc1479 编写于 作者: I ibraheemdev

clean up `c::linger` conversion

上级 3b6777f1
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册