|
@@ -1,4 +1,5 @@
|
|
|
use std::net::{TcpStream, ToSocketAddrs};
|
|
use std::net::{TcpStream, ToSocketAddrs};
|
|
|
|
|
+use std::os::unix::net::UnixStream;
|
|
|
use std::str;
|
|
use std::str;
|
|
|
|
|
|
|
|
use async_std::io::{ReadExt, WriteExt};
|
|
use async_std::io::{ReadExt, WriteExt};
|
|
@@ -186,3 +187,16 @@ pub async fn send_raw_request(url: &str, data: Value) -> Result<JsonResult, Erro
|
|
|
let reply: JsonResult = serde_json::from_slice(&buf[0..bytes_read])?;
|
|
let reply: JsonResult = serde_json::from_slice(&buf[0..bytes_read])?;
|
|
|
Ok(reply)
|
|
Ok(reply)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+pub async fn send_unix_request(path: &str, data: Value) -> Result<JsonResult, Error> {
|
|
|
|
|
+ let mut buf = [0; 2048];
|
|
|
|
|
+ let bytes_read: usize;
|
|
|
|
|
+ let data_str = serde_json::to_string(&data)?;
|
|
|
|
|
+
|
|
|
|
|
+ let mut stream = Async::<UnixStream>::connect(path).await?;
|
|
|
|
|
+ stream.write_all(&data_str.as_bytes()).await?;
|
|
|
|
|
+ bytes_read = stream.read(&mut buf[..]).await?;
|
|
|
|
|
+
|
|
|
|
|
+ let reply: JsonResult = serde_json::from_slice(&buf[0..bytes_read])?;
|
|
|
|
|
+ Ok(reply)
|
|
|
|
|
+}
|