-
Notifications
You must be signed in to change notification settings - Fork 133
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
Large messages require multiple Connection::process()
calls to be received.
#364
Comments
Hmm...interesting issue. Does something like this help:
|
Connection::process()
affects message receiving.Connection::process()
calls to be received.
This fails because
I've sort of worked around this by having a global connection variable and doing static mut DBUS_CONN: Option<Connection> = None;
pub fn init_bus() {
let c = Connection::new_session().expect("Failed to get a session bus.");
let reply = c
.request_name("org.freedesktop.Notifications", false, true, false)
.expect("Failed to register name.");
// etc...
unsafe {
DBUS_CONN = Some(c);
}
}
pub fn get_conn() -> &'static Connection {
unsafe {
assert(DBUS_CONN.is_some());
DBUS_CONN.as_ref().unwrap()
}
}
// later, from thread 2
pub fn process_dbus() {
let conn = get_conn();
loop {
conn.process(Duration::from_millis(1000)).unwrap();
}
}
// later, from thread 1
pub fn send_message() {
let conn = get_conn();
conn.send(<some message>);
} |
You can do this without unsafe with Nevertheless I'm not sure whether I should try to fix this somehow (and if so I'm not sure how) or document it as part of the limitations of the libdbus api. It's definitely not something you would expect... |
It looks like
Yeah, I mentioned this previously:
I get a super obtuse Rust error when I try the above (
I can do it by putting I apologise for my ignorance here, my knowledge here is seriously lacking. |
Yep, there is no Let's try something else. What if you had:
...instead of |
Hmm...in dbus-tokio, we have some kind of strange loop which calls https://github.com/diwic/dbus-rs/blob/master/dbus-tokio/src/connection.rs#L170 |
The issue happens whether it's
The issue linked in the comment above that code (#254) looks extremely familiar to this one... so seems like it. |
So if |
I can confirm this is the case. I don't think it's a timing issue though and seems like it could be by design (though I can't see any mention on the behavior in the dbus documentation. I think loop {
dbg!("loop");
c.process(Duration::from_millis(1000)).unwrap();
if let Ok(notif) = receiver.try_recv() {
dbg!(notif);
}
std::thread::sleep(std::time::Duration::from_millis(100))
} vid.mp4(my top terminal breaks displaying the message because it is so large) |
Filed https://gitlab.freedesktop.org/dbus/dbus/-/issues/364 - let's see what they say. |
This is a really weird issue.
Using the following main loop (blocking):
For large messages (
org.freedesktop.Notifications
), this will need mulitple loops to actually receive something. If I only sleep for e.g. 1ms, then messages will be received very quickly.I'm guessing that messages are chunked in some way and
Connection::process()
needs to be called multiple times to receive the whole message. I can see that if I remove the sleep and set theprocess()
timeout to 1000ms, it runs many loops as soon as I send a message, so it seems to know that it's trying to process an incomplete message.Perhaps
Connection::process()
only processes one message "chunk" at a time? Makes sense. This behaviour would be ok if I can somehow see that messages are pending so that I can spin and process them all. I looked at theResult
ofc.process()
, but there seems to be no indication that messages are waiting. I suspect that the correct way to get this information is somehow throughChannel
, but I tried a few things and couldn't get a result.I suspect I could also solve this by just running
SyncConnection::process()
in a separate thread, but I'm not very familiar with how theSync
traits interract. Is there an equivalent for the following but using aSyncConnection
?:Here's a gist for full repro: https://gist.github.com/Toqozz/4c91deb2a38c09a7804d7c6e4c706d0a
You can test by running
notify-send "<summary>"
where<summary>
is really large (>~ 300 bytes).The text was updated successfully, but these errors were encountered: