DBus watches: DBusAddWatchFunction, unclear how to handle multiple watches

Wiebe Cazemier wiebe at halfgaar.net
Wed May 3 06:03:20 UTC 2023


Hi, 

I'm writing an app using libdbus. I know I'm "signing up for some pain" but it's not that bad and I have good reason for it. I'm almost done. It's fully async and integrated into my app's event loop. 

But I have some questions about 'dbus_connection_set_watch_functions()' [1]. What I find weird, is that I get *two* calls to 'DBusAddWatchFunction', for the same fd, but with different DBusWatch objects: one with flags set for reading (active) and one for flags set for writing (inactive). I'm a bit confused how I'm supposed to deal with this, especially in combination with epoll (which gives you the one fd and all the flags at once, which ever apply). 

The dbus documentation is not clear whether these flags are ever combined or not. For instance, it says: "the flags returned by dbus_watch_get_flags() will only contain DBUS_WATCH_READABLE and DBUS_WATCH_WRITABLE". It says 'and', but so far, I've never seen value 0x3. Does that happen? 

When it comes to the write watch, so far I've never actually seen it used. I expected it to, because the documentation says: "When you use dbus_connection_send() or one of its variants to send a message, the message is added to the outgoing queue. It's actually written to the network later". But that's not true. When I step through the program in a debugger and watch the dbus, the message appears immediately on calling 'dbus_connection_send_with_reply()'. I expected the write watch to be activated instead. (the line of documentation in git is from '2003-04-18' BTW). 

I'm using 1.12.20-r0. This is beyond my control. 

Thanks in advance. If I understand things better, I can make a pull request / patch for the docs. I already know of some other things I want to clarify. 

Regards, 

Wiebe 


[1] https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#gaebf031eb444b4f847606aa27daa3d8e6 



More information about the dbus mailing list