about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorPatrick Mooney <pmooney@oxide.computer>2020-04-15 00:44:06 +0000
committerPatrick Mooney <pmooney@oxide.computer>2020-04-15 01:10:22 +0000
commitdda5c97675b4f5b1f6fdab64606c8a1f21021b0a (patch)
tree2396ef0dfdac984da711877f038106bd2f6603b6 /src/libstd/sys
parentb77aefb76ebb9e73cf5a26885c131674495f434d (diff)
downloadrust-dda5c97675b4f5b1f6fdab64606c8a1f21021b0a.tar.gz
rust-dda5c97675b4f5b1f6fdab64606c8a1f21021b0a.zip
Use fcntl() to set nonblock for solarish sockets
The ioctl(FIONBIO) method of setting a file descriptor to be
non-blocking does not notify the underlying resource in the same way
that fcntl(F_SETFL, O_NONBLOCK) does on illumos and Solaris.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/net.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index b37675e0a0a..d18c22b0573 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -322,11 +322,19 @@ impl Socket {
         Ok(raw != 0)
     }
 
+    #[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
     pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
         let mut nonblocking = nonblocking as libc::c_int;
         cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop)
     }
 
+    #[cfg(any(target_os = "solaris", target_os = "illumos"))]
+    pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
+        // FIONBIO is inadequate for sockets on illumos/Solaris, so use the
+        // fcntl(F_[GS]ETFL)-based method provided by FileDesc instead.
+        self.0.set_nonblocking(nonblocking)
+    }
+
     pub fn take_error(&self) -> io::Result<Option<io::Error>> {
         let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
         if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) }