Check the inner IO errors

This commit is contained in:
QuantumEntangledAndy committed 2023-10-02 08:55:10 +07:00
1 parent 8bdb8ef1bd
commit f13887a369
4 files changed
+32 -9

No files matched your search

+2 -2
View File
@@ -199,7 +199,7 @@ Neolink will publish these messages:
Messages that are prefixed with `neolink/`
- `/status` Tracks the connection of neolink, `online` for ready `offline`
- `/status` Tracks the connection of neolink, `connected` for ready `offline`
for not ready this is a LastWill message
- `/config` The configuration file used to start neolink, you can publish to
this to **temporarily** alter the live configuration
@@ -396,7 +396,7 @@ username = "admin"
password = "password"
uid = "ABCDEF0123456789"
idle_disconnect = true
[cameras.pause]
[cameras.pause]
on_client = true # Should pause when no rtsp client
timeout = 2.1 # How long to wait after motion stops before pausing
```
@@ -460,7 +460,9 @@ impl Discoverer {
lookup: &UidLookupResults,
) -> Result<RegisterResult> {
let tid = generate_tid();
let local_addr = SocketAddr::new(get_local_ip()?, self.local_addr().port());
let local_ip = get_local_ip()?;
let local_addr = SocketAddr::new(local_ip, self.local_addr().port());
log::debug!("Registering {:?} to reolink", local_addr);
let local_ip = local_addr.ip();
let local_port = local_addr.port();
let local_family = if local_addr.ip().is_ipv4() { 4 } else { 6 };
+26 -5
View File
@@ -5,7 +5,8 @@
//! The camera watch is used as an event to be triggered
//! whenever the camera is lost/updated
use anyhow::anyhow;
use std::sync::Weak;
use futures::TryFutureExt;
use std::sync::{Arc, Weak};
use tokio::sync::{
mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::Receiver as WatchReceiver,
};
@@ -98,11 +99,11 @@ impl NeoInstance {
_ = self.cancel.cancelled() => {
Some(Err(anyhow!("Camera is disconnecting")))
}
v = camera_watch.changed() => {
v = camera_watch.wait_for(|new_cam| !Weak::ptr_eq(new_cam, &camera.as_ref().map(Arc::downgrade).unwrap_or_else(Weak::new))).map_ok(|new_cam| new_cam.upgrade()) => {
// Camera value has changed!
// update and try again
if v.is_ok() {
camera = camera_watch.borrow_and_update().upgrade();
if let Ok(new_cam) = v {
camera = new_cam;
None
} else {
Some(Err(anyhow!("Camera is disconnecting")))
@@ -128,7 +129,27 @@ impl NeoInstance {
None
},
Ok(e) => Some(Err(e.into())),
Err(e) => Some(Err(e)),
Err(e) => {
// Check if it is an io error
match e.downcast::<std::io::Error>() {
Ok(e) => {
// Check if the inner error is the Other type and then the discomnect
let is_dropped = e.get_ref().is_some_and(|e|
matches!(e.downcast_ref::<neolink_core::Error>(),
Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected)
)
);
if is_dropped {
// Retry is a None
camera = None;
None
} else {
Some(Err(e.into()))
}
},
Err(e) =>Some(Err(e))
}
},
}
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize, Serializer};
pub(crate) enum Discoveries {
#[serde(alias = "floodlight", alias = "light")]
Floodlight,
#[serde(alias = "camera")]
#[serde(alias = "camera", alias = "preview", alias = "Preview")]
Camera,
#[serde(alias = "motion", alias = "md", alias = "pir")]
Motion,