From 7e7f16e77806799e2da0c65a830908d40392d7f0 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 20 Feb 2016 02:16:05 +0300 Subject: [PATCH] select: add pselect syscall --- src/sys/select.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/sys/select.rs b/src/sys/select.rs index 9132ee1ab8..56d7873461 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -2,9 +2,9 @@ use std::ptr::{null, null_mut}; use std::os::unix::io::RawFd; use std::mem; use libc; -use libc::{fd_set, c_int, timeval}; +use libc::{fd_set, c_int, timespec, timeval, sigset_t}; use {Errno, Result}; -use sys::time::TimeVal; +use sys::time::{TimeVal, TimeSpec}; use sys::signal::SigSet; pub struct FdSet { @@ -74,3 +74,22 @@ pub fn select(nfds: c_int, Errno::result(res) } + +pub fn pselect(nfds: c_int, + readfds: Option<&mut FdSet>, + writefds: Option<&mut FdSet>, + errorfds: Option<&mut FdSet>, + timeout: Option<&TimeSpec>, + sigmask: Option<&SigSet>) -> Result { + let readfds = readfds.map(|set| &mut set.set as *mut fd_set).unwrap_or(null_mut()); + let writefds = writefds.map(|set| &mut set.set as *mut fd_set).unwrap_or(null_mut()); + let errorfds = errorfds.map(|set| &mut set.set as *mut fd_set).unwrap_or(null_mut()); + let timeout = timeout.map(|ts| ts.as_ref() as *const timespec).unwrap_or(null()); + let sigmask = sigmask.map(|sm| sm.as_ref() as *const sigset_t).unwrap_or(null()); + + let res = unsafe { + libc::pselect(nfds, readfds, writefds, errorfds, timeout, sigmask) + }; + + Errno::result(res) +}