Use Errno as RPC error type
This commit is contained in:
parent
0a7a42c227
commit
8f229b6592
22
Cargo.lock
generated
22
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"
|
||||
@ -130,9 +130,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.158"
|
||||
version = "0.2.159"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
||||
|
||||
[[package]]
|
||||
name = "line_discipline"
|
||||
@ -233,9 +233,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.4"
|
||||
version = "0.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853"
|
||||
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
@ -264,8 +264,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",
|
||||
]
|
||||
@ -273,12 +271,10 @@ 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",
|
||||
"syn 2.0.77",
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -324,9 +320,9 @@ dependencies = [
|
||||
|
||||
[[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",
|
||||
|
@ -11,3 +11,7 @@ line_discipline = { version = "0.1.0", path = "../line_discipline" }
|
||||
parking_lot = "0.12.3"
|
||||
slab = "0.4.9"
|
||||
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }
|
||||
|
||||
[patch.crates-io]
|
||||
serde = { path = "../serde/serde" }
|
||||
serde_derive = { path = "../serde/serde_derive" }
|
||||
|
22
src/main.rs
22
src/main.rs
@ -1,7 +1,7 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
os::mikros::{ipc, syscalls},
|
||||
os::mikros::{ipc, syscalls, Errno},
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
@ -92,7 +92,7 @@ struct Serv {
|
||||
}
|
||||
|
||||
impl dev_driver_rpc::Server for Serv {
|
||||
fn open(&self, path: &Path) -> Result<u64, ()> {
|
||||
fn open(&self, path: &Path) -> Result<u64, Errno> {
|
||||
if path == Path::new("ptmx") {
|
||||
let pty = Pty::new();
|
||||
let idx = self.ptys.write().insert(pty);
|
||||
@ -108,13 +108,13 @@ impl dev_driver_rpc::Server for Serv {
|
||||
} else if let Some(&idx) = self.slave_map.read().get(path) {
|
||||
Ok((idx + usize::MAX / 2) as u64)
|
||||
} else {
|
||||
Err(())
|
||||
Err(Errno::ENOENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl file_rpc::Server for Serv {
|
||||
fn read(&self, fd: u64, len: usize) -> Result<Cow<'_, [u8]>, ()> {
|
||||
fn read(&self, fd: u64, len: usize) -> Result<Cow<'_, [u8]>, Errno> {
|
||||
if fd as usize >= usize::MAX / 2 {
|
||||
let ptys = self.ptys.read();
|
||||
let pty = &ptys[fd as usize - usize::MAX / 2];
|
||||
@ -126,7 +126,7 @@ impl file_rpc::Server for Serv {
|
||||
}
|
||||
}
|
||||
|
||||
fn write(&self, fd: u64, data: &[u8]) -> Result<(), ()> {
|
||||
fn write(&self, fd: u64, data: &[u8]) -> Result<(), Errno> {
|
||||
if fd as usize >= usize::MAX / 2 {
|
||||
let ptys = self.ptys.read();
|
||||
let pty = &ptys[fd as usize - usize::MAX / 2];
|
||||
@ -140,14 +140,14 @@ impl file_rpc::Server for Serv {
|
||||
}
|
||||
}
|
||||
|
||||
fn close(&self, _fd: u64) {}
|
||||
fn close(&self, _fd: u64) -> Result<(), Errno> { Ok(()) }
|
||||
|
||||
fn size(&self, _fd: u64) -> Option<u64> {
|
||||
None
|
||||
fn size(&self, _fd: u64) -> Result<u64, Errno> {
|
||||
Err(Errno::ENOSYS)
|
||||
}
|
||||
|
||||
fn dup(&self, fd: u64) -> Option<u64> {
|
||||
Some(fd)
|
||||
fn dup(&self, fd: u64) -> Result<u64, Errno> {
|
||||
Ok(fd)
|
||||
}
|
||||
|
||||
fn register_poll(&self, fd: u64, events: PollEvents) -> u64 {
|
||||
@ -188,7 +188,7 @@ impl file_rpc::Server for Serv {
|
||||
self.polls.lock().remove(poll_id as usize);
|
||||
}
|
||||
|
||||
fn seek(&self, _fd: u64, _pos: file_rpc::SeekFrom) -> u64 { 0 }
|
||||
fn seek(&self, _fd: u64, _pos: file_rpc::SeekFrom) -> Result<u64, Errno> { Err(Errno::ESPIPE) }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user