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

🩹 zm: do not reply if no-reply-expected flag is set #1230

Conversation

manuelheiss-liebherr
Copy link
Contributor

@manuelheiss-liebherr manuelheiss-liebherr commented Jan 29, 2025

I am using zbus to define an inteface method, like this:

#[zbus::interface(name = "public.settings")]
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:

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:

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.

@zeenix
Copy link
Contributor

zeenix commented Jan 29, 2025

@manuelheiss-liebherr Thanks for this!

@zeenix
Copy link
Contributor

zeenix commented Jan 30, 2025

Thanks so much! However you didn't add description to the git commit still and didn't add an emoji (as per our contributing guidelines). I'll do that for you this time but please keep in mind for any future contributions. 😊

@zeenix zeenix changed the title zm: do not reply if no-reply-expected flag is set 🩹 zm: do not reply if no-reply-expected flag is set Jan 30, 2025
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.
@zeenix zeenix force-pushed the feature/consider-noreplyflag-in-interface-methods branch from 05fefb7 to 9bf9c80 Compare January 30, 2025 12:40
@zeenix zeenix enabled auto-merge January 30, 2025 12:41
@zeenix zeenix merged commit 725c403 into dbus2:main Jan 30, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants