1
0
Fork 0
forked from koniifer/ableos

implementing socket related IPC

This commit is contained in:
able 2022-07-28 20:15:02 -05:00
parent f6d0c71a24
commit 3f4c9fdb5a
8 changed files with 88 additions and 26 deletions

14
Cargo.lock generated
View file

@ -38,6 +38,7 @@ dependencies = [
"genfs",
"hashbrown 0.7.2",
"kernel",
"lazy_static",
"libwasm",
"linked_list_allocator",
"lliw",
@ -54,7 +55,7 @@ dependencies = [
"rkyv",
"serde",
"shadeable",
"spin",
"spin 0.9.2",
"toml",
"uart_16550",
"unicode-width",
@ -310,7 +311,7 @@ dependencies = [
"bitflags",
"genfs",
"rlibc",
"spin",
"spin 0.9.2",
]
[[package]]
@ -439,6 +440,9 @@ name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
dependencies = [
"spin 0.5.2",
]
[[package]]
name = "libc"
@ -896,6 +900,12 @@ dependencies = [
"version_check",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.2"

View file

@ -42,6 +42,8 @@ test-args = [
]
[dependencies]
lazy_static = { version = "*", features = ["spin_no_std"] }
linked_list_allocator = "0.9.0"
lliw = "0.2.0"
spin = "0.9"
@ -57,8 +59,6 @@ axel = { git = "https://git.ablecorp.us/able/aos_userland" }
versioning = { git = "https://git.ablecorp.us/able/aos_userland" }
embedded-graphics = "*"
pc-keyboard = "0.5"
[dependencies.logos]
version = "0.12"
default-features = false

View file

@ -11,15 +11,14 @@ pub struct BinaryData {
data: Vec<u8>,
}
#[derive(Debug)]
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub enum HandleResource {
Channel(Channel),
// Device
/// Used for things like files or images or the like
BinaryData(BinaryData),
Channel,
Socket,
BinaryData,
}
#[derive(Debug)]
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub struct Handle {
inner: u128,
res: HandleResource,
@ -29,8 +28,9 @@ impl Display for Handle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Handle-{:032x}", self.inner)?;
match &self.res {
HandleResource::Channel(_) => write!(f, "-Channel")?,
HandleResource::BinaryData(data) => write!(f, "-Binary-{}", &data.name)?,
HandleResource::Channel => write!(f, "-Channel")?,
HandleResource::BinaryData => write!(f, "-Binary")?,
Socket => write!(f, "-Socket")?,
}
Ok(())
@ -39,10 +39,10 @@ impl Display for Handle {
use crate::handle::HandleResource::*;
impl Handle {
pub fn from_channel(channel: Channel) -> Self {
pub fn new(htype: HandleResource) -> Self {
Self {
inner: generate_process_pass(),
res: Channel(channel),
res: htype,
}
}
}

View file

@ -1,16 +1,46 @@
use self::{channel::Channel, socket::Socket};
use hashbrown::HashMap;
use crate::handle::Handle;
use self::{
channel::Channel,
socket::{Socket, SocketError},
};
pub mod channel;
pub mod socket;
pub static IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
sockets: vec![],
channels: vec![],
lazy_static::lazy_static! {
pub static ref IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
sockets: HashMap::new(),
channels: HashMap::new(),
});
}
pub struct IPCService {
pub sockets: Vec<Socket>,
pub channels: Vec<Channel>,
pub sockets: HashMap<Handle, Socket>,
pub channels: HashMap<Handle, Socket>,
// TODO: Add a public board of each down below which use some method of pointing to the above
}
impl IPCService {}
// Socket Related Impl
impl IPCService {
pub fn create_socket(&mut self) -> Handle {
let handle = Handle::new(crate::handle::HandleResource::Socket);
let sock = Socket::new();
self.sockets.insert(handle.clone(), sock);
handle
}
pub fn send_socket(&mut self, handle: Handle, data: String) -> Result<(), SocketError> {
let sock = self.sockets.get_mut(&handle);
match sock {
Some(socket) => {
return socket.write(data);
}
None => return Err(SocketError::NonexistantSocket),
}
}
}

View file

@ -1,16 +1,21 @@
// SEEALSO: https://git.ablecorp.us/able/ableos/src/branch/master/ableos/src/relib/network/socket.rs
pub enum SocketError {
NonexistantSocket,
EmptySocket,
}
#[derive(Debug)]
pub struct Socket {
name: Option<String>,
stream: Vec<u8>,
}
impl Socket {
pub fn new() -> Self {
Self { stream: vec![] }
Self {
name: None,
stream: vec![],
}
}
pub fn write(&mut self, data: String) -> Result<(), SocketError> {
for c in data.chars() {
@ -28,4 +33,8 @@ impl Socket {
}
return Err(SocketError::EmptySocket);
}
pub fn name(&mut self, name: String) {
self.name = Some(name);
}
}

View file

@ -1,14 +1,18 @@
#![allow(clippy::empty_loop)]
use core::sync::atomic::Ordering;
use crate::arch::drivers::sysinfo::master;
use crate::ipc::{self, IPC};
use crate::scheduler::SCHEDULER;
use crate::time::fetch_time;
use crate::{
arch::{init, sloop},
relib::network::socket::{SimpleSock, Socket},
scratchpad,
};
use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};
use kernel::KERNEL_VERSION;
use kernel::{KERNEL_VERSION, TICK};
use spin::Lazy;
// TODO: Change this structure to allow for multiple cores loaded
@ -25,6 +29,13 @@ pub fn kernel_main() -> ! {
log::set_max_level(log::LevelFilter::Off);
}
let mut ipc_service = IPC.lock();
// create some channels or whatever here then drop it
let handle = ipc_service.create_socket();
ipc_service.send_socket(handle, "nerd".to_string());
drop(ipc_service);
x86_64::instructions::interrupts::without_interrupts(|| {
SCHEDULER.lock().enqueue_spawn(scratchpad);
});

View file

@ -217,6 +217,7 @@ fn engine_construction() -> Engine {
engine.register_fn("poke", poke_memory);
engine.register_fn("sloop", sloop);
engine.register_fn("log_dump", log_dump);
// engine.register_fn("ls", ls);
engine
}

View file

@ -7,6 +7,7 @@ use crate::channels::{Channel, ChannelPermission};
use crate::devices::pci;
use crate::filesystem::FILE_SYSTEM;
use crate::handle::Handle;
use crate::ipc::IPC;
use crate::rhai_shell::shell;
use crate::rhai_shell::KEYBUFF;
use crate::wasm_jumploader::run_program;