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 debug = env::var("LESAVKA_UVC_DEBUG").is_ok();
|
||||||
let mut setup_seen: u64 = 0;
|
let mut setup_seen: u64 = 0;
|
||||||
let mut data_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 {
|
loop {
|
||||||
let file = open_with_retry(&dev)?;
|
let file = open_with_retry(&dev)?;
|
||||||
@ -133,6 +135,14 @@ fn main() -> Result<()> {
|
|||||||
let err = std::io::Error::last_os_error();
|
let err = std::io::Error::last_os_error();
|
||||||
match err.raw_os_error() {
|
match err.raw_os_error() {
|
||||||
Some(libc::EAGAIN) | Some(libc::EINTR) | Some(libc::ENOENT) => {
|
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));
|
thread::sleep(Duration::from_millis(10));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -188,7 +198,11 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
handle_data(fd, uvc_send_response, &mut state, &mut pending, data);
|
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> {
|
fn open_with_retry(path: &str) -> Result<std::fs::File> {
|
||||||
for attempt in 1..=200 {
|
for attempt in 1..=200 {
|
||||||
match OpenOptions::new()
|
let mut opts = OpenOptions::new();
|
||||||
.read(true)
|
opts.read(true).write(true);
|
||||||
.write(true)
|
if env::var("LESAVKA_UVC_NONBLOCK").is_ok() {
|
||||||
.custom_flags(libc::O_NONBLOCK)
|
opts.custom_flags(libc::O_NONBLOCK);
|
||||||
.open(path)
|
}
|
||||||
{
|
match opts.open(path) {
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
eprintln!("[lesavka-uvc] opened {path} (attempt {attempt})");
|
eprintln!("[lesavka-uvc] opened {path} (attempt {attempt})");
|
||||||
return Ok(f);
|
return Ok(f);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user