diff --git a/server/src/main.rs b/server/src/main.rs index 0f940ac..c82a304 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -38,22 +38,39 @@ fn list_gc311_devices() -> anyhow::Result> { Ok(v) } -/// background task: whenever GC311 disappears, cycle USB port -async fn monitor_gc311_disconnect() -> anyhow::Result<()> { - let mut mon = MonitorBuilder::new()? - .match_subsystem("usb")? - .match_tag("PRODUCT", "7ca/3311/*")? // vendor: 0x07ca, device 0x3311 - .listen()?; +// /// background task: whenever GC311 disappears, cycle USB port +// async fn monitor_gc311_disconnect() -> anyhow::Result<()> { +// let mut mon = MonitorBuilder::new()? +// .match_subsystem("usb")? +// // .match_tag("PRODUCT", "7ca/3311/*")? // vendor: 0x07ca, device 0x3311 +// .listen()?; - while let Some(ev) = mon.next() { - if ev.event_type() == udev::EventType::Remove { - if let (Some(bus), Some(dev)) = (ev.attribute_value("busnum"), ev.attribute_value("devnum")) { - usb_reset::cycle_port(bus.to_str().unwrap(), dev.to_str().unwrap()); - } - } - } - Ok(()) -} +// // Blocking I/O -> move into a dedicated thread +// tokio::task::spawn_blocking(move || { +// for ev in mon { // `Socket` implements `Iterator` +// if ev.event_type() == udev::EventType::Remove { +// if let (Some(prod), Some(bus), Some(dev)) = +// (ev.attribute_value("PRODUCT"), +// ev.attribute_value("busnum"), +// ev.attribute_value("devnum")) +// { +// // 0x07ca / 0x3311 == AVerMedia GC311 +// if prod.to_str().map_or(false, |p| p.starts_with("7ca/3311/")) { +// usb_reset::cycle_port(bus.to_str().unwrap(), +// dev.to_str().unwrap()); +// } +// } +// } +// } +// }); +// // if ev.event_type() == udev::EventType::Remove { +// // if let (Some(bus), Some(dev)) = (ev.attribute_value("busnum"), ev.attribute_value("devnum")) { +// // usb_reset::cycle_port(bus.to_str().unwrap(), dev.to_str().unwrap()); +// // } +// // } +// // } +// Ok(()) +// } /*─────────────────── tonic service ─────────────────────*/ struct Handler { @@ -153,7 +170,7 @@ async fn main() -> anyhow::Result<()> { .init(); /* auto‑cycle task */ - tokio::spawn(async { monitor_gc311_disconnect().await.ok(); }); + // tokio::spawn(async { monitor_gc311_disconnect().await.ok(); }); let kb = OpenOptions::new() .write(true)