Implement poll for pipes

master
Jiajie Chen 6 years ago
parent 64b383b69c
commit feae733bb9

@ -57,7 +57,6 @@ impl Pipe {
// TODO: better way to provide default impl? // TODO: better way to provide default impl?
macro_rules! impl_inode { macro_rules! impl_inode {
() => { () => {
fn poll(&self) -> Result<PollStatus> { Err(FsError::NotSupported) }
fn metadata(&self) -> Result<Metadata> { Err(FsError::NotSupported) } fn metadata(&self) -> Result<Metadata> { Err(FsError::NotSupported) }
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) } fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_all(&self) -> Result<()> { Ok(()) }
@ -104,5 +103,41 @@ impl INode for Pipe {
Ok(0) 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!(); impl_inode!();
} }

@ -652,7 +652,7 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
write: false, write: false,
append: false, append: false,
}, },
String::from(":pipe_r:"), String::from("pipe_r:[]"),
))); )));
let write_fd = proc.add_file(FileLike::File(FileHandle::new( let write_fd = proc.add_file(FileLike::File(FileHandle::new(
@ -662,7 +662,7 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
write: true, write: true,
append: false, append: false,
}, },
String::from(":pipe_w:"), String::from("pipe_w:[]"),
))); )));
fds[0] = read_fd as u32; fds[0] = read_fd as u32;

Loading…
Cancel
Save