Skip to content

Commit

Permalink
🩹 zm: do not reply if no-reply-expected flag is set
Browse files Browse the repository at this point in the history
I am using zbus to define an inteface method, like this:

```rust
impl SettingsInterface {
    async fn set_var(
        &self,
        originator: &str,
        object: &str,
        interface: &str,
        arguments: &str,
    ) {
        //...
    }
}
```

This method is called with with the `NoReplyExpected` flag. However zbus generates a reply, which ended up in an error shown in `dbus-monitor`:

```
Rejected send message, 0 matched rules; type="method_return", sender=":1.16" ...
```

I used `cargo expand` to see what code is generated by the interface macros and found something like this:

```rust
let reply = self.set_var(originator, object, interface, arguments).await;
let hdr = message.header();
connection.reply(&hdr, &reply).await
```

The `connection.reply()` method is called in every case. So i guess, that the flag is not evaluated yet, to handle the case where no response is expected!?

With my adjustment, the generated code looks like this:

```rust
let reply = self.set_var(originator, object, interface, arguments).await;
let hdr = message.header();
if hdr.primary().flags().contains(zbus::message::Flags::NoReplyExpected)
{
    Ok(())
} else {
    connection.reply(&hdr, &reply).await
}
```

And the error shown with `dbus-monitor` was gone.
  • Loading branch information
manuelheiss-liebherr authored and zeenix committed Jan 30, 2025
1 parent c97ddc0 commit 9bf9c80
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zbus_macros/src/iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,11 @@ pub fn expand(args: Punctuated<Meta, Token![,]>, mut input: ItemImpl) -> syn::Re
#args_from_msg
let reply = self.#ident(#args_names)#method_await;
let hdr = message.header();
#reply
if hdr.primary().flags().contains(zbus::message::Flags::NoReplyExpected) {
Ok(())
} else {
#reply
}
};
#zbus::object_server::DispatchResult::Async(::std::boxed::Box::pin(async move {
future.await
Expand Down

0 comments on commit 9bf9c80

Please sign in to comment.