mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
rpc/jsonrpc: Implement requests over Unix sockets.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::net::{TcpStream, ToSocketAddrs};
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::str;
|
||||
|
||||
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])?;
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user