Skip to content

Commit 614b0cb

Browse files
committed
Auto merge of #272 - abbradar:select-fixes, r=kamalmarhubi
select(2) fixes Part of #270, fixed according to @kamalmarhubi's comments.
2 parents 7fa7206 + dbce477 commit 614b0cb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/sys/select.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const BITS: usize = 32;
1717

1818
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
1919
#[repr(C)]
20+
#[derive(Clone)]
2021
pub struct FdSet {
2122
bits: [u64; FD_SETSIZE as usize / 64]
2223
}
@@ -71,11 +72,11 @@ pub fn select(nfds: c_int,
7172
readfds: Option<&mut FdSet>,
7273
writefds: Option<&mut FdSet>,
7374
errorfds: Option<&mut FdSet>,
74-
timeout: &mut TimeVal) -> Result<c_int> {
75+
timeout: Option<&mut TimeVal>) -> Result<c_int> {
7576
let readfds = readfds.map(|set| set as *mut FdSet).unwrap_or(null_mut());
7677
let writefds = writefds.map(|set| set as *mut FdSet).unwrap_or(null_mut());
7778
let errorfds = errorfds.map(|set| set as *mut FdSet).unwrap_or(null_mut());
78-
let timeout = timeout as *mut TimeVal;
79+
let timeout = timeout.map(|tv| tv as *mut TimeVal).unwrap_or(null_mut());
7980

8081
let res = unsafe {
8182
ffi::select(nfds, readfds, writefds, errorfds, timeout)

test/sys/test_select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn test_select() {
4646
Some(&mut fd_set),
4747
None,
4848
None,
49-
&mut timeout).unwrap());
49+
Some(&mut timeout)).unwrap());
5050
assert!(fd_set.contains(r1));
5151
assert!(!fd_set.contains(r2));
5252
}

0 commit comments

Comments
 (0)