@@ -13,8 +13,6 @@ use crate::{backend, io};
1313#[ cfg( any( windows, target_os = "wasi" ) ) ]
1414use core:: mem:: align_of;
1515use core:: mem:: size_of;
16- #[ cfg( any( windows, target_os = "wasi" ) ) ]
17- use core:: slice;
1816
1917/// wasi-libc's `fd_set` type. The libc bindings for it have private fields, so
2018/// we redeclare it for ourselves so that we can access the fields. They're
@@ -32,12 +30,9 @@ struct FD_SET {
3230use windows_sys:: Win32 :: Networking :: WinSock :: FD_SET ;
3331
3432/// Storage element type for use with [`select`].
35- #[ cfg( any(
36- windows,
37- all(
38- target_pointer_width = "64" ,
39- any( target_os = "freebsd" , target_os = "dragonfly" )
40- )
33+ #[ cfg( all(
34+ target_pointer_width = "64" ,
35+ any( windows, target_os = "freebsd" , target_os = "dragonfly" )
4136) ) ]
4237#[ repr( transparent) ]
4338#[ derive( Copy , Clone , Default ) ]
@@ -52,11 +47,10 @@ pub struct FdSetElement(pub(crate) c::c_ulong);
5247/// Storage element type for use with [`select`].
5348#[ cfg( not( any(
5449 linux_like,
55- windows,
5650 target_os = "wasi" ,
5751 all(
5852 target_pointer_width = "64" ,
59- any( target_os = "freebsd" , target_os = "dragonfly" )
53+ any( windows , target_os = "freebsd" , target_os = "dragonfly" )
6054 )
6155) ) ) ]
6256#[ repr( transparent) ]
@@ -145,12 +139,10 @@ pub fn fd_set_insert(fds: &mut [FdSetElement], fd: RawFd) {
145139 {
146140 let set = unsafe { & mut * fds. as_mut_ptr ( ) . cast :: < FD_SET > ( ) } ;
147141 let fd_count = set. fd_count ;
148- let fd_array = unsafe { slice :: from_raw_parts ( set. fd_array . as_ptr ( ) , fd_count as usize ) } ;
142+ let fd_array = & set. fd_array [ .. fd_count as usize ] ;
149143
150- if !fd_array. iter ( ) . any ( |p| * p as RawFd == fd) {
151- let fd_array = unsafe {
152- slice:: from_raw_parts_mut ( set. fd_array . as_mut_ptr ( ) , fd_count as usize + 1 )
153- } ;
144+ if !fd_array. contains ( & ( fd as _ ) ) {
145+ let fd_array = & mut set. fd_array [ ..fd_count as usize + 1 ] ;
154146 set. fd_count = fd_count + 1 ;
155147 fd_array[ fd_count as usize ] = fd as _ ;
156148 }
@@ -171,7 +163,7 @@ pub fn fd_set_remove(fds: &mut [FdSetElement], fd: RawFd) {
171163 {
172164 let set = unsafe { & mut * fds. as_mut_ptr ( ) . cast :: < FD_SET > ( ) } ;
173165 let fd_count = set. fd_count ;
174- let fd_array = unsafe { slice :: from_raw_parts ( set. fd_array . as_ptr ( ) , fd_count as usize ) } ;
166+ let fd_array = & set. fd_array [ .. fd_count as usize ] ;
175167
176168 if let Some ( pos) = fd_array. iter ( ) . position ( |p| * p as RawFd == fd) {
177169 set. fd_count = fd_count - 1 ;
@@ -197,7 +189,7 @@ pub fn fd_set_bound(fds: &[FdSetElement]) -> RawFd {
197189 {
198190 let set = unsafe { & * fds. as_ptr ( ) . cast :: < FD_SET > ( ) } ;
199191 let fd_count = set. fd_count ;
200- let fd_array = unsafe { slice :: from_raw_parts ( set. fd_array . as_ptr ( ) , fd_count as usize ) } ;
192+ let fd_array = & set. fd_array [ .. fd_count as usize ] ;
201193 let mut max = 0 ;
202194 for fd in fd_array {
203195 if * fd >= max {
@@ -334,7 +326,7 @@ impl<'a> Iterator for FdSetIter<'a> {
334326
335327 let set = unsafe { & * self . fds . as_ptr ( ) . cast :: < FD_SET > ( ) } ;
336328 let fd_count = set. fd_count ;
337- let fd_array = unsafe { slice :: from_raw_parts ( set. fd_array . as_ptr ( ) , fd_count as usize ) } ;
329+ let fd_array = & set. fd_array [ .. fd_count as usize ] ;
338330
339331 if current == fd_count as usize {
340332 return None ;
0 commit comments