alnyan/yggdrasil: add PollChannel for fd polling
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
mod net;
|
||||
pub mod owned;
|
||||
mod poll;
|
||||
pub(crate) mod raw;
|
||||
|
||||
use crate::io::StdinLock;
|
||||
@@ -28,6 +29,9 @@ pub use owned::*;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use raw::*;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use poll::PollChannel;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub trait FdDeviceRequest {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use crate::io;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, OwnedFd, RawFd};
|
||||
use crate::sys::cvt_io;
|
||||
use crate::time::Duration;
|
||||
|
||||
use yggdrasil_rt::io::PollControl;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub struct PollChannel(OwnedFd);
|
||||
|
||||
impl PollChannel {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn new() -> io::Result<Self> {
|
||||
let raw_fd = cvt_io(unsafe { yggdrasil_rt::sys::create_poll_channel() })?;
|
||||
let fd = unsafe { OwnedFd::from_raw_fd(raw_fd) };
|
||||
Ok(Self(fd))
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn add(&mut self, fd: RawFd) -> io::Result<()> {
|
||||
cvt_io(unsafe {
|
||||
yggdrasil_rt::sys::poll_channel_control(self.0.as_raw_fd(), PollControl::AddFd, fd)
|
||||
})
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub fn wait(&mut self, timeout: Option<Duration>) -> io::Result<Option<RawFd>> {
|
||||
let mut output = None;
|
||||
cvt_io(unsafe {
|
||||
yggdrasil_rt::sys::poll_channel_wait(self.0.as_raw_fd(), &timeout, &mut output)
|
||||
})?;
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
||||
Ok(OsError::WouldBlock) => ErrorKind::WouldBlock,
|
||||
Ok(OsError::ReadOnly) => ErrorKind::ReadOnlyFilesystem,
|
||||
Ok(OsError::PermissionDenied) => ErrorKind::PermissionDenied,
|
||||
Ok(OsError::UnrecognizedExecutable) => ErrorKind::InvalidData,
|
||||
Ok(OsError::UnrecognizedExecutable) | Ok(OsError::MissingData) => ErrorKind::InvalidData,
|
||||
|
||||
// Memory and general
|
||||
Ok(OsError::OutOfMemory) => ErrorKind::OutOfMemory,
|
||||
|
||||
Reference in New Issue
Block a user