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 Feb 19, 2016
1 parent 9876979 commit 6c25ad9
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/sys/select.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -64,6 +66,13 @@ mod ffi {
writefds: *mut FdSet,
errorfds: *mut FdSet,
timeout: *mut TimeVal) -> c_int;

pub fn pselect(nfds: c_int,

This comment has been minimized.

Copy link
@kamalmarhubi

kamalmarhubi Feb 19, 2016

this is already available in the libc crate, please use it from there instead.

This comment has been minimized.

Copy link
@abbradar

abbradar Feb 19, 2016

Author Owner

This would make it inconsistent with current select in that it would use FdSet from libc. How should I proceed?

This comment has been minimized.

Copy link
@kamalmarhubi

kamalmarhubi Feb 19, 2016

Hrm. I don't know right now! If you have feelings about API design and project directions, you could comment on nix-rust#190... ;-)

readfds: *mut FdSet,
writefds: *mut FdSet,
errorfds: *mut FdSet,
timeout: *const timespec,
sigmask: *const sigset_t) -> c_int;
}
}

Expand All @@ -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<&timespec>,
sigmask: Option<&sigset_t>) -> Result<c_int> {
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)
}

1 comment on commit 6c25ad9

@kamalmarhubi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine, modulo using the function from libc instead of writing our own extern decl for it.

Please sign in to comment.