alnyan/yggdrasil: add PollChannel for fd polling

This commit is contained in:
2023-12-22 11:30:42 +02:00
parent 7d4c743cf1
commit e7746a8445
3 changed files with 39 additions and 1 deletions
+4
View File
@@ -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")]
+34
View File
@@ -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)
}
}
+1 -1
View File
@@ -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,