@@ -32,7 +32,7 @@ use crate::fs::inode::{DirEntry, FileType, INodeInterface, Metadata, PollFlags,
32
32
use crate :: fs:: { FileSystemError , Path } ;
33
33
34
34
use crate :: mem:: paging:: VirtAddr ;
35
- use crate :: utils:: sync:: { Mutex , WaitQueue } ;
35
+ use crate :: utils:: sync:: { Mutex , WaitQueue , WaitQueueFlags } ;
36
36
37
37
use super :: SocketAddrRef ;
38
38
@@ -243,14 +243,11 @@ impl INodeInterface for UnixSocket {
243
243
_offset : usize ,
244
244
user_buffer : & mut [ u8 ] ,
245
245
) -> fs:: Result < usize > {
246
- if self . buffer . lock_irq ( ) . is_empty ( ) && flags. is_nonblock ( ) {
247
- return Err ( FileSystemError :: WouldBlock ) ;
248
- }
249
-
250
- let mut buffer = self . wq . block_on ( & self . buffer , |e| !e. is_empty ( ) ) ?;
246
+ let mut buf = self
247
+ . wq
248
+ . wait ( flags. into ( ) , & self . buffer , |e| !e. is_empty ( ) ) ?;
251
249
252
- let read = buffer. read ( user_buffer) ;
253
- Ok ( read)
250
+ Ok ( buf. read ( user_buffer) )
254
251
}
255
252
256
253
fn write_at ( & self , _offset : usize , buffer : & [ u8 ] ) -> fs:: Result < usize > {
@@ -325,12 +322,16 @@ impl INodeInterface for UnixSocket {
325
322
target. wq . notify_all ( ) ;
326
323
core:: mem:: drop ( itarget) ; // release the lock
327
324
328
- let _ = self . wq . block_on ( & self . inner , |e| e. state . is_connected ( ) ) ?;
325
+ // FIXME: connect() should pass fd.
326
+ let _ = self . wq . wait ( WaitQueueFlags :: empty ( ) , & self . inner , |e| {
327
+ e. state . is_connected ( )
328
+ } ) ?;
329
329
Ok ( ( ) )
330
330
}
331
331
332
332
fn accept ( & self , address : Option < ( VirtAddr , & mut u32 ) > ) -> fs:: Result < Arc < UnixSocket > > {
333
- let mut inner = self . wq . block_on ( & self . inner , |e| {
333
+ // TODO: accept
334
+ let mut inner = self . wq . wait ( WaitQueueFlags :: empty ( ) , & self . inner , |e| {
334
335
e. state . queue ( ) . is_some_and ( |x| !x. is_empty ( ) )
335
336
} ) ?;
336
337
@@ -387,11 +388,9 @@ impl INodeInterface for UnixSocket {
387
388
_ => return Err ( FileSystemError :: NotConnected ) ,
388
389
} ;
389
390
390
- if self . buffer . lock_irq ( ) . is_empty ( ) && fd_flags. is_nonblock ( ) {
391
- return Err ( FileSystemError :: WouldBlock ) ;
392
- }
393
-
394
- let mut buffer = self . wq . block_on ( & self . buffer , |e| !e. is_empty ( ) ) ?;
391
+ let mut buffer = self
392
+ . wq
393
+ . wait ( fd_flags. into ( ) , & self . buffer , |e| !e. is_empty ( ) ) ?;
395
394
396
395
if let Some ( addr) = header. name_mut :: < SocketAddrUnix > ( ) {
397
396
* addr = peer. inner . lock_irq ( ) . address . as_ref ( ) . cloned ( ) . unwrap ( ) ;
0 commit comments