From 6c25ad931418dca83ec8f8d53daac0edff64854c Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 19 Feb 2016 17:32:21 +0300 Subject: [PATCH] select: add pselect syscall --- src/sys/select.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/sys/select.rs b/src/sys/select.rs index 48746e72fd..0ab75019de 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -1,8 +1,9 @@ -use std::ptr::null_mut; +use std::ptr::{null, null_mut}; use std::os::unix::io::RawFd; -use libc::c_int; -use {Errno, Result}; +use libc::{c_int, timespec}; +use {Error, Errno, Result}; use sys::time::TimeVal; +use sys::signal::sigset_t; pub const FD_SETSIZE: RawFd = 1024; @@ -54,8 +55,9 @@ impl FdSet { } mod ffi { - use libc::c_int; + use libc::{c_int, timespec}; use sys::time::TimeVal; + use sys::signal::sigset_t; use super::FdSet; extern { @@ -64,6 +66,13 @@ mod ffi { writefds: *mut FdSet, errorfds: *mut FdSet, timeout: *mut TimeVal) -> c_int; + + pub fn pselect(nfds: c_int, + readfds: *mut FdSet, + writefds: *mut FdSet, + errorfds: *mut FdSet, + timeout: *const timespec, + sigmask: *const sigset_t) -> c_int; } } @@ -83,3 +92,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<×pec>, + sigmask: Option<&sigset_t>) -> Result { + let readfds = readfds.map(|set| set as *mut FdSet).unwrap_or(null_mut()); + let writefds = writefds.map(|set| set as *mut FdSet).unwrap_or(null_mut()); + let errorfds = errorfds.map(|set| set as *mut FdSet).unwrap_or(null_mut()); + let timeout = timeout.map(|ts| ts as *const timespec).unwrap_or(null()); + let sigmask = sigmask.map(|sm| sm as *const sigset_t).unwrap_or(null()); + + let res = unsafe { + ffi::pselect(nfds, readfds, writefds, errorfds, timeout, sigmask) + }; + + Errno::result(res) +}