mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
Implement poll for pipes
This commit is contained in:
parent
64b383b69c
commit
feae733bb9
@ -57,7 +57,6 @@ impl Pipe {
|
||||
// TODO: better way to provide default impl?
|
||||
macro_rules! impl_inode {
|
||||
() => {
|
||||
fn poll(&self) -> Result<PollStatus> { Err(FsError::NotSupported) }
|
||||
fn metadata(&self) -> Result<Metadata> { Err(FsError::NotSupported) }
|
||||
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
|
||||
fn sync_all(&self) -> Result<()> { Ok(()) }
|
||||
@ -104,5 +103,41 @@ impl INode for Pipe {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
fn poll(&self) -> Result<PollStatus> {
|
||||
let data = self.data.lock();
|
||||
match self.direction {
|
||||
PipeEnd::Read => {
|
||||
if data.buf.len() > 0 {
|
||||
Ok(PollStatus {
|
||||
read: true,
|
||||
write: false,
|
||||
error: false,
|
||||
})
|
||||
} else {
|
||||
Ok(PollStatus {
|
||||
read: false,
|
||||
write: false,
|
||||
error: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
PipeEnd::Write => {
|
||||
if data.buf.len() > 0 {
|
||||
Ok(PollStatus {
|
||||
read: false,
|
||||
write: true,
|
||||
error: false,
|
||||
})
|
||||
} else {
|
||||
Ok(PollStatus {
|
||||
read: false,
|
||||
write: false,
|
||||
error: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl_inode!();
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
|
||||
write: false,
|
||||
append: false,
|
||||
},
|
||||
String::from(":pipe_r:"),
|
||||
String::from("pipe_r:[]"),
|
||||
)));
|
||||
|
||||
let write_fd = proc.add_file(FileLike::File(FileHandle::new(
|
||||
@ -662,7 +662,7 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
|
||||
write: true,
|
||||
append: false,
|
||||
},
|
||||
String::from(":pipe_w:"),
|
||||
String::from("pipe_w:[]"),
|
||||
)));
|
||||
|
||||
fds[0] = read_fd as u32;
|
||||
|
Loading…
Reference in New Issue
Block a user