@@ -19,8 +19,9 @@ use std::time::Duration;
1919
2020cfg_if:: cfg_if! {
2121 if #[ cfg( all( target_os = "linux" , feature = "io_uring" ) ) ] {
22- use libc:: { epoll_event, iovec, msghdr, off_t, size_t, sockaddr, socklen_t, ssize_t } ;
22+ use libc:: { epoll_event, iovec, msghdr, off_t, size_t, sockaddr, socklen_t} ;
2323 use dashmap:: DashMap ;
24+ use std:: ffi:: c_longlong;
2425 }
2526}
2627
@@ -36,7 +37,7 @@ pub(crate) struct EventLoop<'e> {
3637 operator : crate :: net:: operator:: Operator < ' e > ,
3738 #[ allow( clippy:: type_complexity) ]
3839 #[ cfg( all( target_os = "linux" , feature = "io_uring" ) ) ]
39- syscall_wait_table : DashMap < usize , Arc < ( Mutex < Option < ssize_t > > , Condvar ) > > ,
40+ syscall_wait_table : DashMap < usize , Arc < ( Mutex < Option < c_longlong > > , Condvar ) > > ,
4041 selector : Poller ,
4142 pool : CoroutinePool < ' e > ,
4243 phantom_data : PhantomData < & ' e EventLoop < ' e > > ,
@@ -223,7 +224,27 @@ impl<'e> EventLoop<'e> {
223224 }
224225 }
225226
226- #[ cfg( all( target_os = "linux" , feature = "io_uring" ) ) ]
227+ cfg_if:: cfg_if! {
228+ if #[ cfg( all( target_os = "linux" , feature = "io_uring" ) ) ] {
229+ left_time = self . adapt_io_uring( left_time) ?;
230+ }
231+ }
232+
233+ // use epoll/kevent/iocp
234+ let mut events = Events :: with_capacity ( 1024 ) ;
235+ self . selector . select ( & mut events, left_time) ?;
236+ #[ allow( clippy:: explicit_iter_loop) ]
237+ for event in events. iter ( ) {
238+ let token = event. get_token ( ) ;
239+ if event. readable ( ) || event. writable ( ) {
240+ unsafe { self . resume ( token) } ;
241+ }
242+ }
243+ Ok ( ( ) )
244+ }
245+
246+ #[ cfg( all( target_os = "linux" , feature = "io_uring" ) ) ]
247+ fn adapt_io_uring ( & self , mut left_time : Option < Duration > ) -> std:: io:: Result < Option < Duration > > {
227248 if crate :: net:: operator:: support_io_uring ( ) {
228249 // use io_uring
229250 let ( count, mut cq, left) = self . operator . select ( left_time, 0 ) ?;
@@ -234,7 +255,7 @@ impl<'e> EventLoop<'e> {
234255 continue ;
235256 }
236257 // resolve completed read/write tasks
237- let result = cqe. result ( ) as ssize_t ;
258+ let result = cqe. result ( ) as c_longlong ;
238259 eprintln ! ( "io_uring finish {token} {result}" ) ;
239260 if let Some ( ( _, pair) ) = self . syscall_wait_table . remove ( & token) {
240261 let ( lock, cvar) = & * pair;
@@ -249,18 +270,7 @@ impl<'e> EventLoop<'e> {
249270 left_time = Some ( left. unwrap_or ( Duration :: ZERO ) ) ;
250271 }
251272 }
252-
253- // use epoll/kevent/iocp
254- let mut events = Events :: with_capacity ( 1024 ) ;
255- self . selector . select ( & mut events, left_time) ?;
256- #[ allow( clippy:: explicit_iter_loop) ]
257- for event in events. iter ( ) {
258- let token = event. get_token ( ) ;
259- if event. readable ( ) || event. writable ( ) {
260- unsafe { self . resume ( token) } ;
261- }
262- }
263- Ok ( ( ) )
273+ Ok ( left_time)
264274 }
265275
266276 #[ allow( clippy:: unused_self) ]
@@ -404,7 +414,7 @@ macro_rules! impl_io_uring {
404414 pub ( super ) fn $syscall(
405415 & self ,
406416 $( $arg: $arg_type) ,*
407- ) -> std:: io:: Result <Arc <( Mutex <Option <ssize_t >>, Condvar ) >> {
417+ ) -> std:: io:: Result <Arc <( Mutex <Option <c_longlong >>, Condvar ) >> {
408418 let token = EventLoop :: token( Syscall :: $syscall) ;
409419 self . operator. $syscall( token, $( $arg, ) * ) ?;
410420 let arc = Arc :: new( ( Mutex :: new( None ) , Condvar :: new( ) ) ) ;
0 commit comments