uvc: use blocking event reads by default
This commit is contained in:
parent
e35af4a46d
commit
fb8573d806
@ -108,6 +108,8 @@ fn main() -> Result<()> {
|
||||
let debug = env::var("LESAVKA_UVC_DEBUG").is_ok();
|
||||
let mut setup_seen: u64 = 0;
|
||||
let mut data_seen: u64 = 0;
|
||||
let mut dq_err_seen: u64 = 0;
|
||||
let mut dq_err_last: Option<i32> = None;
|
||||
|
||||
loop {
|
||||
let file = open_with_retry(&dev)?;
|
||||
@ -133,6 +135,14 @@ fn main() -> Result<()> {
|
||||
let err = std::io::Error::last_os_error();
|
||||
match err.raw_os_error() {
|
||||
Some(libc::EAGAIN) | Some(libc::EINTR) | Some(libc::ENOENT) => {
|
||||
if debug {
|
||||
let code = err.raw_os_error();
|
||||
if dq_err_seen < 10 || code != dq_err_last {
|
||||
eprintln!("[lesavka-uvc] dqevent idle: {err}");
|
||||
dq_err_seen += 1;
|
||||
dq_err_last = code;
|
||||
}
|
||||
}
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
continue;
|
||||
}
|
||||
@ -188,7 +198,11 @@ fn main() -> Result<()> {
|
||||
}
|
||||
handle_data(fd, uvc_send_response, &mut state, &mut pending, data);
|
||||
}
|
||||
_ => {}
|
||||
_ => {
|
||||
if debug {
|
||||
eprintln!("[lesavka-uvc] event type=0x{:08x}", ev.type_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,12 +269,12 @@ impl UvcState {
|
||||
|
||||
fn open_with_retry(path: &str) -> Result<std::fs::File> {
|
||||
for attempt in 1..=200 {
|
||||
match OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.custom_flags(libc::O_NONBLOCK)
|
||||
.open(path)
|
||||
{
|
||||
let mut opts = OpenOptions::new();
|
||||
opts.read(true).write(true);
|
||||
if env::var("LESAVKA_UVC_NONBLOCK").is_ok() {
|
||||
opts.custom_flags(libc::O_NONBLOCK);
|
||||
}
|
||||
match opts.open(path) {
|
||||
Ok(f) => {
|
||||
eprintln!("[lesavka-uvc] opened {path} (attempt {attempt})");
|
||||
return Ok(f);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user