Compare commits
No commits in common. "1854e849499317c293156f78f46cad0a1d218dcb" and "70107257c270895bfad34603490e5ae461758a28" have entirely different histories.
1854e84949
...
70107257c2
2 changed files with 1 additions and 53 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -20,6 +20,4 @@ Cargo.lock
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
tmp/
|
tmp/
|
||||||
|
|
||||||
.DS_Store
|
|
|
@ -1,50 +0,0 @@
|
||||||
use std::path::Path;
|
|
||||||
use tokio::{io::Interest, net::UnixStream};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
error::Error,
|
|
||||||
ipc::message::{Request, Response, ResponseContent},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn request<T, U>(path: T, request: U) -> Result<ResponseContent, Error>
|
|
||||||
where
|
|
||||||
T: AsRef<Path>,
|
|
||||||
U: Into<Request>
|
|
||||||
{
|
|
||||||
let stream = UnixStream::connect(path).await?;
|
|
||||||
let ready = stream.ready(Interest::WRITABLE).await?;
|
|
||||||
let request: Request = request.into();
|
|
||||||
let mut response_buf = Vec::new();
|
|
||||||
if let Err(e) = ciborium::into_writer(&request, &mut response_buf) {
|
|
||||||
todo!();
|
|
||||||
};
|
|
||||||
match stream.try_write(&response_buf) {
|
|
||||||
Ok(x) => {
|
|
||||||
println!("write {} bytes", x)
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Err(e.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loop {
|
|
||||||
let ready_write = stream.ready(Interest::READABLE).await?;
|
|
||||||
let mut read_buf : Vec<u8> = Vec::new();
|
|
||||||
match stream.try_read_buf(&mut read_buf) {
|
|
||||||
Ok(x) => {
|
|
||||||
println!("read {} bytes", x)
|
|
||||||
}
|
|
||||||
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Err(e.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut buf : Vec<u8> = Vec::new();
|
|
||||||
let response: Response = ciborium::from_reader_with_buffer(read_buf.as_slice(), &mut buf)?;
|
|
||||||
if response.id == request.id {
|
|
||||||
return Ok(response.content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue