server fix
This commit is contained in:
parent
a5a44befe2
commit
7ac8b3f71b
@ -2,7 +2,7 @@
|
|||||||
// sever/src/main.rs
|
// sever/src/main.rs
|
||||||
#![forbid(unsafe_code)]
|
#![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::{fs::{File, OpenOptions}, io::AsyncWriteExt, sync::Mutex};
|
||||||
use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
|
use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
|
||||||
use tonic::{transport::Server, Request, Response, Status};
|
use tonic::{transport::Server, Request, Response, Status};
|
||||||
@ -54,8 +54,18 @@ impl Relay for Handler {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut s = req.into_inner();
|
let mut s = req.into_inner();
|
||||||
while let Some(pkt) = s.next().await.transpose()? {
|
while let Some(pkt) = s.next().await.transpose()? {
|
||||||
ms.lock().await.write_all(&pkt.data).await?;
|
loop {
|
||||||
tx.send(Ok(pkt)).await;//.ok();
|
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>(())
|
Ok::<(), Status>(())
|
||||||
});
|
});
|
||||||
@ -88,14 +98,14 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let kb = OpenOptions::new()
|
let kb = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
// .read(true)
|
// .read(true)
|
||||||
.custom_flags(libc::O_NONBLOCK)
|
// .custom_flags(libc::O_NONBLOCK)
|
||||||
.open("/dev/hidg0")
|
.open("/dev/hidg0")
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let ms = OpenOptions::new()
|
let ms = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
// .read(true)
|
// .read(true)
|
||||||
.custom_flags(libc::O_NONBLOCK)
|
// .custom_flags(libc::O_NONBLOCK)
|
||||||
.open("/dev/hidg1")
|
.open("/dev/hidg1")
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user