Use Errno as RPC error type
This commit is contained in:
parent
cee8b9e969
commit
4f556140c8
5
.cargo/config.toml
Normal file
5
.cargo/config.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[build]
|
||||
target = "x86_64-unknown-mikros"
|
||||
|
||||
[install]
|
||||
root = "../os_build/sysroot"
|
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -13,9 +13,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.3.0"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
@ -162,9 +162,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.6"
|
||||
version = "0.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b"
|
||||
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
@ -193,8 +193,6 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.210"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
@ -202,8 +200,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.210"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -233,9 +229,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.77"
|
||||
version = "2.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
|
||||
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -6,3 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
parking_lot = "0.12.3"
|
||||
postcard = { version = "1.0.10", features = ["use-std"] }
|
||||
|
||||
[patch.crates-io]
|
||||
serde = { path = "../serde/serde" }
|
||||
serde_derive = { path = "../serde/serde_derive" }
|
||||
|
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "dev-x86_64-unknown-mikros"
|
19
src/lib.rs
19
src/lib.rs
@ -1,16 +1,19 @@
|
||||
#![allow(clippy::result_unit_err)]
|
||||
|
||||
use std::os::mikros::ipc::rpc::{self, IncomingCall};
|
||||
use std::os::mikros::{
|
||||
ipc::rpc::{self, IncomingCall},
|
||||
Errno,
|
||||
};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
static SERVER: RwLock<Option<Box<dyn Server>>> = RwLock::new(None);
|
||||
|
||||
const PROTO: u16 = 0;
|
||||
const PROTO: u16 = 7;
|
||||
|
||||
pub trait Server: Send + Sync {
|
||||
fn next_entry(&self, fd: u64) -> Result<Option<String>, ()>;
|
||||
fn close(&self, fd: u64) ;
|
||||
fn next_entry(&self, fd: u64) -> Result<Option<String>, Errno>;
|
||||
fn close(&self, fd: u64) -> Result<(), Errno>;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -21,14 +24,14 @@ impl Client {
|
||||
Self(pid)
|
||||
}
|
||||
|
||||
pub fn next_entry(self, fd: u64) -> Result<Option<String>, ()> {
|
||||
pub fn next_entry(self, fd: u64) -> Result<Option<String>, Errno> {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(self.0, PROTO, 0, &postcard::to_stdvec(&fd).unwrap()).get_return(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn close(self, fd: u64) {
|
||||
pub fn close(self, fd: u64) -> Result<(), Errno> {
|
||||
postcard::from_bytes(
|
||||
&rpc::send_call(self.0, PROTO, 1, &postcard::to_stdvec(&fd).unwrap()).get_return(),
|
||||
)
|
||||
@ -55,7 +58,7 @@ fn callback(call: IncomingCall) {
|
||||
call.send_return(&ret);
|
||||
} else if call.func == 1 {
|
||||
let fd = postcard::from_bytes(call.args()).unwrap();
|
||||
server.close(fd);
|
||||
call.send_return(&[]);
|
||||
let ret = postcard::to_stdvec(&server.close(fd)).unwrap();
|
||||
call.send_return(&ret);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user