22use std:: os:: fd:: OwnedFd ;
33use std:: {
44 io,
5+ ops:: Deref ,
56 os:: fd:: { AsFd , AsRawFd , BorrowedFd , RawFd } ,
67} ;
78
@@ -11,22 +12,18 @@ use mod_use::mod_use;
1112#[ cfg( feature = "tokio" ) ]
1213mod_use ! [ tokio] ;
1314
14- #[ cfg( feature = "futures" ) ]
15- mod_use ! [ futures] ;
16-
1715#[ cfg( feature = "smol" ) ]
1816mod_use ! [ smol] ;
1917
2018struct UnixAdapter {
21- driver : RawFd ,
19+ runtime : Runtime ,
2220 #[ cfg( target_os = "linux" ) ]
2321 efd : Option < OwnedFd > ,
2422}
2523
2624#[ cfg( target_os = "linux" ) ]
2725impl UnixAdapter {
28- fn new ( runtime : & Runtime ) -> io:: Result < Self > {
29- let driver = runtime. as_raw_fd ( ) ;
26+ fn new ( runtime : Runtime ) -> io:: Result < Self > {
3027 if runtime. driver_type ( ) . is_iouring ( ) {
3128 use rustix:: {
3229 event:: { EventfdFlags , eventfd} ,
@@ -37,18 +34,18 @@ impl UnixAdapter {
3734 let efd_raw = efd. as_raw_fd ( ) ;
3835 unsafe {
3936 io_uring_register (
40- BorrowedFd :: borrow_raw ( driver ) ,
37+ BorrowedFd :: borrow_raw ( runtime . as_raw_fd ( ) ) ,
4138 IoringRegisterOp :: RegisterEventfd ,
4239 ( & raw const efd_raw) . cast ( ) ,
4340 1 ,
4441 ) ?;
4542 }
4643 Ok ( Self {
47- driver ,
44+ runtime ,
4845 efd : Some ( efd) ,
4946 } )
5047 } else {
51- Ok ( Self { driver , efd : None } )
48+ Ok ( Self { runtime , efd : None } )
5249 }
5350 }
5451
@@ -80,11 +77,11 @@ impl AsRawFd for UnixAdapter {
8077 self . efd
8178 . as_ref ( )
8279 . map ( |f| f. as_raw_fd ( ) )
83- . unwrap_or ( self . driver )
80+ . unwrap_or_else ( || self . runtime . as_raw_fd ( ) )
8481 }
8582 #[ cfg( not( target_os = "linux" ) ) ]
8683 {
87- self . driver
84+ self . runtime . as_raw_fd ( )
8885 }
8986 }
9087}
@@ -94,3 +91,11 @@ impl AsFd for UnixAdapter {
9491 unsafe { BorrowedFd :: borrow_raw ( self . as_raw_fd ( ) ) }
9592 }
9693}
94+
95+ impl Deref for UnixAdapter {
96+ type Target = Runtime ;
97+
98+ fn deref ( & self ) -> & Self :: Target {
99+ & self . runtime
100+ }
101+ }
0 commit comments