cleanup client

This commit is contained in:
Lily Tsuru 2024-12-02 16:44:11 -05:00
parent 51af8d2f14
commit 0024f49df9
4 changed files with 15 additions and 7 deletions

View file

@ -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.

View file

@ -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<P: ?Sized + NixPath>(&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.

View file

@ -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();

View file

@ -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();