-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
894: Add pselect syscall r=asomers a=antifuchs I saw that #276 was closed, and now I need `pselect`, so here it is! I copied the function body from @abbradar's work, updated the type signatures, added two tests and added a doc comment. Hope this works! Co-authored-by: Andreas Fuchs <[email protected]>
- Loading branch information
Showing
4 changed files
with
133 additions
and
2 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
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
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use nix::sys::select::*; | ||
use nix::unistd::{pipe, write}; | ||
use nix::sys::signal::SigSet; | ||
use nix::sys::time::{TimeSpec, TimeValLike}; | ||
use std::os::unix::io::RawFd; | ||
|
||
#[test] | ||
pub fn test_pselect() { | ||
let _mtx = ::SIGNAL_MTX | ||
.lock() | ||
.expect("Mutex got poisoned by another test"); | ||
|
||
let (r1, w1) = pipe().unwrap(); | ||
write(w1, b"hi!").unwrap(); | ||
let (r2, _w2) = pipe().unwrap(); | ||
|
||
let mut fd_set = FdSet::new(); | ||
fd_set.insert(r1); | ||
fd_set.insert(r2); | ||
|
||
let timeout = TimeSpec::seconds(10); | ||
let sigmask = SigSet::empty(); | ||
assert_eq!( | ||
1, | ||
pselect(None, &mut fd_set, None, None, &timeout, &sigmask).unwrap() | ||
); | ||
assert!(fd_set.contains(r1)); | ||
assert!(!fd_set.contains(r2)); | ||
} | ||
|
||
#[test] | ||
pub fn test_pselect_nfds2() { | ||
let (r1, w1) = pipe().unwrap(); | ||
write(w1, b"hi!").unwrap(); | ||
let (r2, _w2) = pipe().unwrap(); | ||
|
||
let mut fd_set = FdSet::new(); | ||
fd_set.insert(r1); | ||
fd_set.insert(r2); | ||
|
||
let timeout = TimeSpec::seconds(10); | ||
assert_eq!( | ||
1, | ||
pselect( | ||
::std::cmp::max(r1, r2) + 1, | ||
&mut fd_set, | ||
None, | ||
None, | ||
&timeout, | ||
None | ||
).unwrap() | ||
); | ||
assert!(fd_set.contains(r1)); | ||
assert!(!fd_set.contains(r2)); | ||
} |