server fix

This commit is contained in:
Brad Stein 2025-06-17 23:13:13 -05:00
parent a5a44befe2
commit 7ac8b3f71b

View File

@ -2,7 +2,7 @@
// sever/src/main.rs
#![forbid(unsafe_code)]
use std::{pin::Pin, sync::Arc, panic::AssertUnwindSafe};
use std::{io::ErrorKind, pin::Pin, sync::Arc, panic::AssertUnwindSafe};
use tokio::{fs::{File, OpenOptions}, io::AsyncWriteExt, sync::Mutex};
use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
use tonic::{transport::Server, Request, Response, Status};
@ -54,8 +54,18 @@ impl Relay for Handler {
tokio::spawn(async move {
let mut s = req.into_inner();
while let Some(pkt) = s.next().await.transpose()? {
ms.lock().await.write_all(&pkt.data).await?;
tx.send(Ok(pkt)).await;//.ok();
loop {
match ms.lock().await.write_all(&pkt.data).await {
Ok(()) => break,
Err(e) if e.kind() == ErrorKind::WouldBlock => {
// gadget FIFO full give it a breath
tokio::time::sleep(std::time::Duration::from_micros(500)).await;
continue;
}
Err(e) => return Err(Status::internal(format!("hidg1: {e}"))),
}
}
let _ = tx.send(Ok(pkt)).await;
}
Ok::<(), Status>(())
});
@ -88,14 +98,14 @@ async fn main() -> anyhow::Result<()> {
let kb = OpenOptions::new()
.write(true)
// .read(true)
.custom_flags(libc::O_NONBLOCK)
// .custom_flags(libc::O_NONBLOCK)
.open("/dev/hidg0")
.await?;
let ms = OpenOptions::new()
.write(true)
// .read(true)
.custom_flags(libc::O_NONBLOCK)
// .custom_flags(libc::O_NONBLOCK)
.open("/dev/hidg1")
.await?;