Skip to content

Commit

Permalink
select: add pselect syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
abbradar committed May 7, 2016
1 parent da53464 commit 7e7f16e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/sys/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<c_int> {
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)
}

0 comments on commit 7e7f16e

Please sign in to comment.