evdev-rs icon indicating copy to clipboard operation
evdev-rs copied to clipboard

Implement AsRawFd for Device

Open ryankurte opened this issue 4 years ago • 2 comments

provides compatibility with smol::Async for polling from async contexts:

// Setup async device wrapper (configures device file descriptor with `O_NONBLOCK`)
let a = smol::Async::new(d)?;

// Async poll for the next event
let (_status, event) = a.read_with(|d| d.next_event(ReadFlag::NORMAL) ).await?;

for convenience Device also really needs to be Sync, which it is not automatically due to the internal *mut raw::libevdev, however, i can't see from the evdev docs whether this is reasonable or not?

ryankurte avatar Nov 21 '21 00:11 ryankurte

I haven't used Sync myself before so I need to look into it a bit more. Other things look good to me.

ndesh26 avatar Nov 28 '21 14:11 ndesh26

having another look at this it appears y'all already have interior mutability with raw: *mut raw::libevdev so the borrow checker will allow multiple references which all can be (internally) mutated and adding Sync would let this occur across threads, which could expound any existing unsoundness.

i am however not sure how to mitigate this :-/

ryankurte avatar May 01 '22 00:05 ryankurte