@@ -233,25 +233,27 @@ pub(crate) trait ObjectInterface: Sync + Send + core::fmt::Debug {
233233
234234 /// `accept` a connection on a socket
235235 #[ cfg( any( feature = "net" , feature = "vsock" ) ) ]
236- async fn accept ( & self ) -> io:: Result < ( Arc < dyn ObjectInterface > , Endpoint ) > {
236+ async fn accept (
237+ & mut self ,
238+ ) -> io:: Result < ( Arc < async_lock:: RwLock < dyn ObjectInterface > > , Endpoint ) > {
237239 Err ( Errno :: Inval )
238240 }
239241
240242 /// initiate a connection on a socket
241243 #[ cfg( any( feature = "net" , feature = "vsock" ) ) ]
242- async fn connect ( & self , _endpoint : Endpoint ) -> io:: Result < ( ) > {
244+ async fn connect ( & mut self , _endpoint : Endpoint ) -> io:: Result < ( ) > {
243245 Err ( Errno :: Inval )
244246 }
245247
246248 /// `bind` a name to a socket
247249 #[ cfg( any( feature = "net" , feature = "vsock" ) ) ]
248- async fn bind ( & self , _name : ListenEndpoint ) -> io:: Result < ( ) > {
250+ async fn bind ( & mut self , _name : ListenEndpoint ) -> io:: Result < ( ) > {
249251 Err ( Errno :: Inval )
250252 }
251253
252254 /// `listen` for connections on a socket
253255 #[ cfg( any( feature = "net" , feature = "vsock" ) ) ]
254- async fn listen ( & self , _backlog : i32 ) -> io:: Result < ( ) > {
256+ async fn listen ( & mut self , _backlog : i32 ) -> io:: Result < ( ) > {
255257 Err ( Errno :: Inval )
256258 }
257259
@@ -310,7 +312,7 @@ pub(crate) trait ObjectInterface: Sync + Send + core::fmt::Debug {
310312 }
311313
312314 /// Sets the file status flags.
313- async fn set_status_flags ( & self , _status_flags : StatusFlags ) -> io:: Result < ( ) > {
315+ async fn set_status_flags ( & mut self , _status_flags : StatusFlags ) -> io:: Result < ( ) > {
314316 Err ( Errno :: Nosys )
315317 }
316318
@@ -337,19 +339,19 @@ pub(crate) fn read(fd: FileDescriptor, buf: &mut [u8]) -> io::Result<usize> {
337339 return Ok ( 0 ) ;
338340 }
339341
340- block_on ( obj. read ( buf) , None )
342+ block_on ( async { obj. read ( ) . await . read ( buf) . await } , None )
341343}
342344
343345pub ( crate ) fn lseek ( fd : FileDescriptor , offset : isize , whence : SeekWhence ) -> io:: Result < isize > {
344346 let obj = get_object ( fd) ?;
345347
346- block_on ( obj. lseek ( offset, whence) , None )
348+ block_on ( async { obj. read ( ) . await . lseek ( offset, whence) . await } , None )
347349}
348350
349351pub ( crate ) fn chmod ( fd : FileDescriptor , mode : AccessPermission ) -> io:: Result < ( ) > {
350352 let obj = get_object ( fd) ?;
351353
352- block_on ( obj. chmod ( mode) , None )
354+ block_on ( async { obj. read ( ) . await . chmod ( mode) . await } , None )
353355}
354356
355357pub ( crate ) fn write ( fd : FileDescriptor , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -359,12 +361,12 @@ pub(crate) fn write(fd: FileDescriptor, buf: &[u8]) -> io::Result<usize> {
359361 return Ok ( 0 ) ;
360362 }
361363
362- block_on ( obj. write ( buf) , None )
364+ block_on ( async { obj. read ( ) . await . write ( buf) . await } , None )
363365}
364366
365367pub ( crate ) fn truncate ( fd : FileDescriptor , length : usize ) -> io:: Result < ( ) > {
366368 let obj = get_object ( fd) ?;
367- block_on ( obj. truncate ( length) , None )
369+ block_on ( async { obj. read ( ) . await . truncate ( length) . await } , None )
368370}
369371
370372async fn poll_fds ( fds : & mut [ PollFd ] ) -> io:: Result < u64 > {
@@ -375,7 +377,7 @@ async fn poll_fds(fds: &mut [PollFd]) -> io::Result<u64> {
375377 let fd = i. fd ;
376378 i. revents = PollEvent :: empty ( ) ;
377379 if let Ok ( obj) = core_scheduler ( ) . get_object ( fd) {
378- let mut pinned = core:: pin:: pin!( obj. poll( i. events) ) ;
380+ let mut pinned = core:: pin:: pin!( async { obj. read ( ) . await . poll( i. events) . await } ) ;
379381 if let Ready ( Ok ( e) ) = pinned. as_mut ( ) . poll ( cx)
380382 && !e. is_empty ( )
381383 {
@@ -416,7 +418,7 @@ pub fn poll(fds: &mut [PollFd], timeout: Option<Duration>) -> io::Result<u64> {
416418
417419pub fn fstat ( fd : FileDescriptor ) -> io:: Result < FileAttr > {
418420 let obj = get_object ( fd) ?;
419- block_on ( obj. fstat ( ) , None )
421+ block_on ( async { obj. read ( ) . await . fstat ( ) . await } , None )
420422}
421423
422424/// Wait for some event on a file descriptor.
@@ -440,16 +442,20 @@ pub fn fstat(fd: FileDescriptor) -> io::Result<FileAttr> {
440442pub fn eventfd ( initval : u64 , flags : EventFlags ) -> io:: Result < FileDescriptor > {
441443 let obj = self :: eventfd:: EventFd :: new ( initval, flags) ;
442444
443- let fd = core_scheduler ( ) . insert_object ( Arc :: new ( obj) ) ?;
445+ let fd = core_scheduler ( ) . insert_object ( Arc :: new ( async_lock :: RwLock :: new ( obj) ) ) ?;
444446
445447 Ok ( fd)
446448}
447449
448- pub ( crate ) fn get_object ( fd : FileDescriptor ) -> io:: Result < Arc < dyn ObjectInterface > > {
450+ pub ( crate ) fn get_object (
451+ fd : FileDescriptor ,
452+ ) -> io:: Result < Arc < async_lock:: RwLock < dyn ObjectInterface > > > {
449453 core_scheduler ( ) . get_object ( fd)
450454}
451455
452- pub ( crate ) fn insert_object ( obj : Arc < dyn ObjectInterface > ) -> io:: Result < FileDescriptor > {
456+ pub ( crate ) fn insert_object (
457+ obj : Arc < async_lock:: RwLock < dyn ObjectInterface > > ,
458+ ) -> io:: Result < FileDescriptor > {
453459 core_scheduler ( ) . insert_object ( obj)
454460}
455461
@@ -465,11 +471,13 @@ pub(crate) fn dup_object2(fd1: FileDescriptor, fd2: FileDescriptor) -> io::Resul
465471 core_scheduler ( ) . dup_object2 ( fd1, fd2)
466472}
467473
468- pub ( crate ) fn remove_object ( fd : FileDescriptor ) -> io:: Result < Arc < dyn ObjectInterface > > {
474+ pub ( crate ) fn remove_object (
475+ fd : FileDescriptor ,
476+ ) -> io:: Result < Arc < async_lock:: RwLock < dyn ObjectInterface > > > {
469477 core_scheduler ( ) . remove_object ( fd)
470478}
471479
472480pub ( crate ) fn isatty ( fd : FileDescriptor ) -> io:: Result < bool > {
473481 let obj = get_object ( fd) ?;
474- block_on ( obj. isatty ( ) , None )
482+ block_on ( async { obj. read ( ) . await . isatty ( ) . await } , None )
475483}
0 commit comments