Phase 4: hive-m1nd harness + manager nixos template; devshell sqlite
This commit is contained in:
parent
aa67e5a481
commit
17092961a2
5 changed files with 159 additions and 28 deletions
|
|
@ -1,17 +1,24 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use hive_sh4re::{AgentRequest, AgentResponse};
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
pub async fn request(socket: &Path, req: AgentRequest) -> Result<AgentResponse> {
|
||||
/// Generic JSON-line request/response over a unix socket. One request, one
|
||||
/// response, then drop. Used by both the agent and manager harnesses.
|
||||
pub async fn request<Req, Resp>(socket: &Path, req: &Req) -> Result<Resp>
|
||||
where
|
||||
Req: Serialize + ?Sized,
|
||||
Resp: DeserializeOwned,
|
||||
{
|
||||
let stream = UnixStream::connect(socket)
|
||||
.await
|
||||
.with_context(|| format!("connect to {}", socket.display()))?;
|
||||
let (read, mut write) = stream.into_split();
|
||||
|
||||
let mut payload = serde_json::to_string(&req)?;
|
||||
let mut payload = serde_json::to_string(req)?;
|
||||
payload.push('\n');
|
||||
write.write_all(payload.as_bytes()).await?;
|
||||
write.flush().await?;
|
||||
|
|
@ -22,6 +29,5 @@ pub async fn request(socket: &Path, req: AgentRequest) -> Result<AgentResponse>
|
|||
if line.is_empty() {
|
||||
bail!("server closed connection without responding");
|
||||
}
|
||||
let resp: AgentResponse = serde_json::from_str(line.trim())?;
|
||||
Ok(resp)
|
||||
Ok(serde_json::from_str(line.trim())?)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue