forked from nix-rust/nix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
@@ -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, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
abbradar
Author
Owner
|
||
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<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
There was a problem hiding this comment.
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.
this is already available in the libc crate, please use it from there instead.