Add interval timeout to heartbeat

This commit is contained in:
Jackson Coxson
2025-01-23 09:38:43 -07:00
parent 45811dc977
commit f589ad661b
4 changed files with 12 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -424,7 +424,7 @@ dependencies = [
[[package]] [[package]]
name = "idevice" name = "idevice"
version = "0.1.6" version = "0.1.7"
dependencies = [ dependencies = [
"env_logger", "env_logger",
"log", "log",

View File

@@ -2,7 +2,7 @@
name = "idevice" name = "idevice"
description = "A Rust library to interact with services on iOS devices." description = "A Rust library to interact with services on iOS devices."
authors = ["Jackson Coxson"] authors = ["Jackson Coxson"]
version = "0.1.6" version = "0.1.7"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
documentation = "https://docs.rs/idevice" documentation = "https://docs.rs/idevice"

View File

@@ -12,8 +12,14 @@ impl HeartbeatClient {
Self { idevice } Self { idevice }
} }
pub async fn get_marco(&mut self) -> Result<u64, IdeviceError> { pub async fn get_marco(&mut self, interval: u64) -> Result<u64, IdeviceError> {
let rec = self.idevice.read_plist().await?; // Get a plist or wait for the interval
let rec = tokio::select! {
rec = self.idevice.read_plist() => rec?,
_ = tokio::time::sleep(tokio::time::Duration::from_secs(interval)) => {
return Err(IdeviceError::HeartbeatTimeout)
}
};
match rec.get("Interval") { match rec.get("Interval") {
Some(plist::Value::Integer(interval)) => { Some(plist::Value::Integer(interval)) => {
if let Some(interval) = interval.as_unsigned() { if let Some(interval) = interval.as_unsigned() {

View File

@@ -141,6 +141,8 @@ pub enum IdeviceError {
NoEstablishedConnection, NoEstablishedConnection,
#[error("device went to sleep")] #[error("device went to sleep")]
HeartbeatSleepyTime, HeartbeatSleepyTime,
#[error("heartbeat timeout")]
HeartbeatTimeout,
#[error("not found")] #[error("not found")]
NotFound, NotFound,
#[error("unknown error `{0}` returned from device")] #[error("unknown error `{0}` returned from device")]