@@ -8,7 +8,7 @@ use libc::{c_int, c_long, intptr_t, time_t, timespec, uintptr_t};
88use libc:: { c_long, intptr_t, size_t, time_t, timespec, uintptr_t} ;
99use std:: convert:: TryInto ;
1010use std:: mem;
11- use std:: os:: unix:: io:: RawFd ;
11+ use std:: os:: unix:: io:: { AsFd , AsRawFd , FromRawFd , OwnedFd } ;
1212use std:: ptr;
1313
1414// Redefine kevent in terms of programmer-friendly enums and bitfields.
@@ -207,10 +207,10 @@ libc_bitflags!(
207207 }
208208) ;
209209
210- pub fn kqueue ( ) -> Result < RawFd > {
210+ pub fn kqueue ( ) -> Result < OwnedFd > {
211211 let res = unsafe { libc:: kqueue ( ) } ;
212212
213- Errno :: result ( res)
213+ Errno :: result ( res) . map ( |fd| unsafe { OwnedFd :: from_raw_fd ( fd ) } )
214214}
215215
216216// KEvent can't derive Send because on some operating systems, udata is defined
@@ -267,8 +267,8 @@ impl KEvent {
267267 }
268268}
269269
270- pub fn kevent (
271- kq : RawFd ,
270+ pub fn kevent < Fd : AsFd > (
271+ kq : Fd ,
272272 changelist : & [ KEvent ] ,
273273 eventlist : & mut [ KEvent ] ,
274274 timeout_ms : usize ,
@@ -293,15 +293,15 @@ type type_of_nchanges = c_int;
293293#[ cfg( target_os = "netbsd" ) ]
294294type type_of_nchanges = size_t ;
295295
296- pub fn kevent_ts (
297- kq : RawFd ,
296+ pub fn kevent_ts < Fd : AsFd > (
297+ kq : Fd ,
298298 changelist : & [ KEvent ] ,
299299 eventlist : & mut [ KEvent ] ,
300300 timeout_opt : Option < timespec > ,
301301) -> Result < usize > {
302302 let res = unsafe {
303303 libc:: kevent (
304- kq,
304+ kq. as_fd ( ) . as_raw_fd ( ) ,
305305 changelist. as_ptr ( ) as * const libc:: kevent ,
306306 changelist. len ( ) as type_of_nchanges ,
307307 eventlist. as_mut_ptr ( ) as * mut libc:: kevent ,
0 commit comments