summaryrefslogtreecommitdiff
path: root/src/api/status.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-21 20:19:54 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-21 20:22:57 +0300
commit866aaf740e10fcfce169aaf81380ea0257fbe272 (patch)
treef815392b7c6b24a7c0de14e655bd635656383813 /src/api/status.rs
parentca579c402d5668560ca13059f82c03178be18b2a (diff)
refactor: separate server client boundaries
Diffstat (limited to 'src/api/status.rs')
-rw-r--r--src/api/status.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/api/status.rs b/src/api/status.rs
new file mode 100644
index 00000000..f58e69c0
--- /dev/null
+++ b/src/api/status.rs
@@ -0,0 +1,54 @@
+use std::io;
+use std::path::Path;
+use std::time::Duration;
+
+use crate::api::schema::{Method, Request, ResponseResult};
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct RuntimeStatus {
+ pub version: Option<String>,
+ pub protocol: Option<u32>,
+}
+
+pub fn read_runtime_status_at(
+ socket_path: &Path,
+ timeout: Duration,
+) -> io::Result<Option<RuntimeStatus>> {
+ if !socket_path.exists() {
+ return Ok(None);
+ }
+
+ let client = crate::api::client::ApiClient::for_target(
+ crate::api::client::ConnectionTarget::SocketPath(socket_path.to_path_buf()),
+ );
+ let request = Request {
+ id: "runtime:status".into(),
+ method: Method::Ping(crate::api::schema::PingParams::default()),
+ };
+ let response = client
+ .request_value_with_timeout(&request, timeout)
+ .and_then(crate::api::client::parse_response_value);
+ let response = match response {
+ Ok(response) => response,
+ Err(crate::api::client::ApiClientError::Io(err))
+ if matches!(
+ err.kind(),
+ io::ErrorKind::ConnectionRefused
+ | io::ErrorKind::NotFound
+ | io::ErrorKind::TimedOut
+ ) =>
+ {
+ return Ok(None);
+ }
+ Err(err) => return Err(io::Error::other(err)),
+ };
+ match response.result {
+ ResponseResult::Pong { version, protocol } => Ok(Some(RuntimeStatus {
+ version: Some(version),
+ protocol: Some(protocol),
+ })),
+ result => Err(io::Error::other(format!(
+ "server status request returned unexpected result: {result:?}"
+ ))),
+ }
+}