Skip to content

Commit 8576c29

Browse files
OokiinekoBerrysoft
Ookiineko
authored andcommitted
Fix std::sys::unix::set_linger for Cygwin
Signed-off-by: Ookiineko <[email protected]>
1 parent 84b2d03 commit 8576c29

File tree

1 file changed

+11
-0
lines changed
  • library/std/src/sys/net/connection/socket

1 file changed

+11
-0
lines changed

library/std/src/sys/net/connection/socket/unix.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ impl Socket {
424424
Ok(())
425425
}
426426

427+
#[cfg(not(target_os = "cygwin"))]
427428
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
428429
let linger = libc::linger {
429430
l_onoff: linger.is_some() as libc::c_int,
@@ -433,6 +434,16 @@ impl Socket {
433434
setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)
434435
}
435436

437+
#[cfg(target_os = "cygwin")]
438+
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
439+
let linger = libc::linger {
440+
l_onoff: linger.is_some() as libc::c_ushort,
441+
l_linger: linger.unwrap_or_default().as_secs() as libc::c_ushort,
442+
};
443+
444+
setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)
445+
}
446+
436447
pub fn linger(&self) -> io::Result<Option<Duration>> {
437448
let val: libc::linger = getsockopt(self, libc::SOL_SOCKET, SO_LINGER)?;
438449

0 commit comments

Comments
 (0)