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.
This commit is contained in:
parent
b77aefb76e
commit
dda5c97675
1 changed files with 8 additions and 0 deletions
|
@ -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))) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue