Fix typos and add utils

This commit is contained in:
Jianfeng Jiang
2023-05-31 10:46:51 +08:00
committed by Tate, Hongliang Tian
parent b2f2c55c9b
commit d96fe31e36
26 changed files with 388 additions and 71 deletions

View File

@ -2,6 +2,7 @@
use crate::events::Observer;
use crate::fs::utils::{AccessMode, IoEvents, IoctlCmd, Metadata, Poller, SeekFrom, StatusFlags};
use crate::net::socket::Socket;
use crate::prelude::*;
use core::any::Any;
@ -67,6 +68,10 @@ pub trait FileLike: Send + Sync + Any {
) -> Result<Weak<dyn Observer<IoEvents>>> {
return_errno_with_message!(Errno::EINVAL, "unregister_observer is not supported")
}
fn as_socket(&self) -> Option<&dyn Socket> {
None
}
}
impl dyn FileLike {

View File

@ -1,4 +1,5 @@
use crate::events::{Events, Observer, Subject};
use crate::net::socket::Socket;
use crate::prelude::*;
use core::cell::Cell;
@ -101,6 +102,12 @@ impl FileTable {
.ok_or(Error::with_message(Errno::EBADF, "fd not exits"))
}
pub fn get_socket(&self, sockfd: FileDescripter) -> Result<&dyn Socket> {
self.get_file(sockfd)?
.as_socket()
.ok_or_else(|| Error::with_message(Errno::ENOTSOCK, "the fd is not a socket"))
}
pub fn get_entry(&self, fd: FileDescripter) -> Result<&FileTableEntry> {
self.table
.get(fd as usize)

View File

@ -8,6 +8,7 @@ use keyable_arc::KeyableWeak;
/// A pollee maintains a set of active events, which can be polled with
/// pollers or be monitored with observers.
#[derive(Clone)]
pub struct Pollee {
inner: Arc<PolleeInner>,
}