Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TcpStream::set_linger and TcpStream::linger #88495

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up c::linger conversion
  • Loading branch information
ibraheemdev committed Aug 30, 2021
commit dafc14794f9d71b3ccc5fde0aeb47cd6bb25e83e
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl Socket {
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)
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl Socket {
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)
Expand Down