server fix
This commit is contained in:
parent
a23081a070
commit
a70f5aea5a
@ -38,22 +38,39 @@ fn list_gc311_devices() -> anyhow::Result<Vec<String>> {
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user