summaryrefslogtreecommitdiff
path: root/test/sys/test_select.rs
diff options
context:
space:
mode:
authorUtkarsh Kukreti <utkarshkukreti@gmail.com>2015-09-14 21:00:35 +0530
committerCarl Lerche <me@carllerche.com>2015-09-28 10:58:05 -0700
commitee9affe12fa216c84eb11cc3169673b55af1bb56 (patch)
treecebc05fad8069bcf60c5a160603e760af2c2aba5 /test/sys/test_select.rs
parent6e27e16d633a8dbb632bf3cbd6c7d542cd547033 (diff)
downloadnix-ee9affe12fa216c84eb11cc3169673b55af1bb56.zip
Add sys::select::FdSet and sys::select::select.
Diffstat (limited to 'test/sys/test_select.rs')
-rw-r--r--test/sys/test_select.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs
new file mode 100644
index 00000000..c9331886
--- /dev/null
+++ b/test/sys/test_select.rs
@@ -0,0 +1,42 @@
+use nix::sys::select::{FdSet, FD_SETSIZE, select};
+use nix::sys::time::TimeVal;
+use nix::unistd::{read, write, pipe};
+
+#[test]
+fn test_fdset() {
+ let mut fd_set = FdSet::new();
+
+ for i in 0..FD_SETSIZE {
+ assert!(!fd_set.contains(i));
+ }
+
+ fd_set.insert(7);
+
+ assert!(fd_set.contains(7));
+
+ fd_set.remove(7);
+
+ for i in 0..FD_SETSIZE {
+ assert!(!fd_set.contains(i));
+ }
+}
+
+#[test]
+fn test_select() {
+ 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 mut timeout = TimeVal::seconds(1);
+ assert_eq!(1, select(r2 + 1,
+ Some(&mut fd_set),
+ None,
+ None,
+ &mut timeout).unwrap());
+ assert!(fd_set.contains(r1));
+ assert!(!fd_set.contains(r2));
+}