about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOokiineko <chiisaineko@protonmail.com>2024-03-04 18:34:47 +0800
committer王宇逸 <Strawberry_Str@hotmail.com>2025-03-10 21:23:31 +0800
commite3e98c84d3eb64181c25ff88f31aee432363ca12 (patch)
treef0a14e796c80366bf1a5b65cd8f2568e16a84ce7
parentc9ccec93fa5e87f1363f0ce6edc897340e8c3884 (diff)
downloadrust-e3e98c84d3eb64181c25ff88f31aee432363ca12.tar.gz
rust-e3e98c84d3eb64181c25ff88f31aee432363ca12.zip
Fix `std::sys::unix::set_linger` for Cygwin
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
-rw-r--r--library/std/src/sys/net/connection/socket/unix.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/library/std/src/sys/net/connection/socket/unix.rs b/library/std/src/sys/net/connection/socket/unix.rs
index 647058385a2..bbe1e038dcc 100644
--- a/library/std/src/sys/net/connection/socket/unix.rs
+++ b/library/std/src/sys/net/connection/socket/unix.rs
@@ -424,6 +424,7 @@ impl Socket {
         Ok(())
     }
 
+    #[cfg(not(target_os = "cygwin"))]
     pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
         let linger = libc::linger {
             l_onoff: linger.is_some() as libc::c_int,
@@ -433,6 +434,16 @@ impl Socket {
         setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)
     }
 
+    #[cfg(target_os = "cygwin")]
+    pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
+        let linger = libc::linger {
+            l_onoff: linger.is_some() as libc::c_ushort,
+            l_linger: linger.unwrap_or_default().as_secs() as libc::c_ushort,
+        };
+
+        setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)
+    }
+
     pub fn linger(&self) -> io::Result<Option<Duration>> {
         let val: libc::linger = getsockopt(self, libc::SOL_SOCKET, SO_LINGER)?;