server fix

This commit is contained in:
Brad Stein 2025-06-23 21:52:57 -05:00
parent a23081a070
commit a70f5aea5a

View File

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