]> git.proxmox.com Git - pve-lxc-syscalld.git/commitdiff
use nix for set_nonblocking impl
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 30 Oct 2019 13:24:24 +0000 (14:24 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 30 Oct 2019 13:24:24 +0000 (14:24 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/tools.rs

index 3d88335526cc170daddfe3713eba3c9e807146d6..a3a345dc7855ef8d8d5a5271ba9e0c0603f485c9 100644 (file)
@@ -22,16 +22,12 @@ impl FromRawFd for Fd {
 }
 
 impl Fd {
-    pub fn set_nonblocking(&self, nb: bool) -> std::io::Result<()> {
-        let fd = self.as_raw_fd();
-        let flags = c_try!(unsafe { libc::fcntl(fd, libc::F_GETFL) });
-        let flags = if nb {
-            flags | libc::O_NONBLOCK
-        } else {
-            flags & !libc::O_NONBLOCK
-        };
-        c_try!(unsafe { libc::fcntl(fd, libc::F_SETFL, flags) });
-        Ok(())
+    pub fn set_nonblocking(&self, nb: bool) -> nix::Result<libc::c_int> {
+        use nix::fcntl;
+        let mut flags =
+            fcntl::OFlag::from_bits(fcntl::fcntl(self.0, fcntl::FcntlArg::F_GETFL)?).unwrap();
+        flags.set(fcntl::OFlag::O_NONBLOCK, nb);
+        fcntl::fcntl(self.0, fcntl::FcntlArg::F_SETFL(flags))
     }
 }