From db22a823f497bf1ad74188f4ead66cfd751b3019 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 19 Feb 2016 17:25:46 +0300 Subject: [PATCH 1/2] select: allow infinite timeout --- src/sys/select.rs | 4 ++-- test/sys/test_select.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sys/select.rs b/src/sys/select.rs index 9d7c41f8b8..48746e72fd 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -71,11 +71,11 @@ pub fn select(nfds: c_int, readfds: Option<&mut FdSet>, writefds: Option<&mut FdSet>, errorfds: Option<&mut FdSet>, - timeout: &mut TimeVal) -> Result { + timeout: Option<&mut TimeVal>) -> 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 as *mut TimeVal; + let timeout = timeout.map(|tv| tv as *mut TimeVal).unwrap_or(null_mut()); let res = unsafe { ffi::select(nfds, readfds, writefds, errorfds, timeout) diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs index 74b390f903..689086700f 100644 --- a/test/sys/test_select.rs +++ b/test/sys/test_select.rs @@ -46,7 +46,7 @@ fn test_select() { Some(&mut fd_set), None, None, - &mut timeout).unwrap()); + Some(&mut timeout)).unwrap()); assert!(fd_set.contains(r1)); assert!(!fd_set.contains(r2)); } From dbce477ae0b385a7e4405d7c2a1a872844d94b47 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 19 Feb 2016 17:32:29 +0300 Subject: [PATCH 2/2] select: make FdSet Cloneable --- src/sys/select.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sys/select.rs b/src/sys/select.rs index 48746e72fd..1b47d759a9 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -17,6 +17,7 @@ const BITS: usize = 32; #[cfg(not(any(target_os = "macos", target_os = "ios")))] #[repr(C)] +#[derive(Clone)] pub struct FdSet { bits: [u64; FD_SETSIZE as usize / 64] }