diff --git a/README.md b/README.md index ee82391..74d86d4 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ This repository contains: - The agent. Written in C++20. - Shared headers and utility code, used between the agent and the client. Written in C++20, mostly so it can be shared between the agent and client. -- A simple client, written mostly in Rust (with some C++ glue), which displays the framebuffer (in a quick-and-dirty fashion.). Mostly test-only code. Some of it isn't though! +- A simple client, written mostly in Rust (with some C++ glue since I don't feel like rewriting structures and the shared code in Rust), which displays the framebuffer (in a quick-and-dirty fashion.). Mostly test-only code. Some of it isn't though, and will be turned into a standalone client crate. diff --git a/src/hzclient.rs b/src/hzclient.rs index dfc7607..b7dd89b 100644 --- a/src/hzclient.rs +++ b/src/hzclient.rs @@ -1,5 +1,5 @@ //! Hazelnut C++ client bindings. -use nix::{fcntl::OFlag, sys::stat::Mode}; +use nix::{fcntl::OFlag, sys::stat::Mode, NixPath}; pub(crate) mod sys { use std::ffi; @@ -13,6 +13,9 @@ pub(crate) mod sys { /// The frame has been changed. Changed, + /// The Hazelnut lock was contended, so we couldn't lock it ourselves. + LockContended, + /// A failure occured during the tick. Fail, } @@ -59,9 +62,9 @@ impl HazelnutClient { } /// Opens the given IVSHMEM shmem file. - pub fn open(&mut self, path: &String) -> anyhow::Result<()> { + pub fn open(&mut self, path: &P) -> anyhow::Result<()> { // NOTE: `fd` is owned by the hazelnut client once it is provided to it, so we do not close it ourselves. - let fd = nix::fcntl::open(path.as_str(), OFlag::O_RDWR, Mode::S_IRUSR | Mode::S_IWUSR)?; + let fd = nix::fcntl::open(path, OFlag::O_RDWR, Mode::S_IRUSR | Mode::S_IWUSR)?; // FIXME: this really should work by FD so we can just return io::Result<> or something, but bleh // for now it's "fine", also it's a path in the shared sources currently. diff --git a/src/main.rs b/src/main.rs index 690fbe1..2f89764 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ fn main() -> anyhow::Result<()> { let socket_path: String = "/dev/shm/lg-win7".into(); - client.open(&socket_path)?; + client.open(&socket_path[..])?; println!("Opened IVSHMEM device."); @@ -56,7 +56,12 @@ fn main() -> anyhow::Result<()> { .expect("Failed to update"); client.unlock(); + }, + + hzclient::sys::ResultCode::LockContended => { + // contended } + hzclient::ResultCode::Unchanged => match window.as_mut() { Some(window) => { client.unlock(); diff --git a/src/rust_wrapper.cpp b/src/rust_wrapper.cpp index c7e3e5e..7109825 100644 --- a/src/rust_wrapper.cpp +++ b/src/rust_wrapper.cpp @@ -2,7 +2,7 @@ #include "ivshmem_protocol.hpp" #include "Utils.hpp" -enum class ResultCode : u32 { Unchanged, Changed, Fail }; +enum class ResultCode : u32 { Unchanged, Changed, LockContended, Fail }; struct HazelnutIvshmemClient { bool Open(int fd) { @@ -29,7 +29,7 @@ struct HazelnutIvshmemClient { if(pHeader->lock.try_lock_manually()) { // failed to lock - return ResultCode::Unchanged; + return ResultCode::LockContended; } auto current = pFrameHeader->serial.load();