Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching status #565

Merged
merged 19 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix MatchingListener drop
OlivierHecart committed Oct 13, 2023
commit 5d2ee158f6329f0d44c78706022da9f28f8af8be
20 changes: 16 additions & 4 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
@@ -1088,6 +1088,16 @@ pub(crate) struct MatchingListenerState {
pub(crate) callback: Callback<'static, MatchingStatus>,
}

#[zenoh_macros::unstable]
impl std::fmt::Debug for MatchingListenerState {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("MatchingListener")
.field("id", &self.id)
.field("key_expr", &self.key_expr)
.finish()
}
}

#[zenoh_macros::unstable]
pub(crate) struct MatchingListenerInner<'a> {
pub(crate) publisher: PublisherRef<'a, 'a>,
@@ -1199,7 +1209,7 @@ impl SyncResolve for MatchingListenerUndeclaration<'_> {
self.subscriber
.publisher
.session
.matches_unsubscribe(self.subscriber.state.id)
.undeclare_matches_listener_inner(self.subscriber.state.id)
}
}

@@ -1215,9 +1225,11 @@ impl AsyncResolve for MatchingListenerUndeclaration<'_> {
#[zenoh_macros::unstable]
impl Drop for MatchingListenerInner<'_> {
fn drop(&mut self) {
self.alive = false;
if let Err(e) = self.publisher.session.matches_unsubscribe(self.state.id) {
log::error!("Failed to undeclare MatchingListener: {e}");
if self.alive {
let _ = self
.publisher
.session
.undeclare_matches_listener_inner(self.state.id);
}
}
}
10 changes: 5 additions & 5 deletions zenoh/src/session.rs
Original file line number Diff line number Diff line change
@@ -1577,14 +1577,14 @@ impl Session {
}

#[zenoh_macros::unstable]
pub(crate) fn matches_unsubscribe(&self, sid: usize) -> ZResult<()> {
pub(crate) fn undeclare_matches_listener_inner(&self, sid: usize) -> ZResult<()> {
let mut state = zwrite!(self.state);
if state.matching_listeners.remove(&sid).is_some() {
trace!("matches_unsubscribe({sid})");
if let Some(state) = state.matching_listeners.remove(&sid) {
trace!("undeclare_matches_listener_inner({:?})", state);
Ok(())
} else {
bail!("Failed to unsubscribe matching status: unknown id: {sid}")
Err(zerror!("Unable to find MatchingListener").into())
}
Ok(())
}

pub(crate) fn handle_data(
Loading