Skip to content

Commit dda5c97

Browse files
committed
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.
1 parent b77aefb commit dda5c97

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libstd/sys/unix/net.rs

+8
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,19 @@ impl Socket {
322322
Ok(raw != 0)
323323
}
324324

325+
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
325326
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
326327
let mut nonblocking = nonblocking as libc::c_int;
327328
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop)
328329
}
329330

331+
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
332+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
333+
// FIONBIO is inadequate for sockets on illumos/Solaris, so use the
334+
// fcntl(F_[GS]ETFL)-based method provided by FileDesc instead.
335+
self.0.set_nonblocking(nonblocking)
336+
}
337+
330338
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
331339
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
332340
if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) }

0 commit comments

Comments
 (0)