tags:

views:

89

answers:

2

When I do a "dbus_connection_close", do I need to flush the message queue?

In other words, do I need to continue with "dbus_connection_read_write_dispatch" until I receive the "disconnected" indication or is it safe to stop dispatching?

Updated: I need to close the connection to DBus in a clean manner. From reading the documentation, all the clean-up must be done prior to "unreferencing" the connection and this process isn't very well documented IMO.

A: 

Looking at the documentation for dbus_connection_close(), the only thing that may be invoked is the dispatch status function to indicate that the connection has been closed.

So, ordering here is something you probably want to pay attention to .. i.e getting notified of a closed / dropped connection prior to things left in the message queue.

Looking at the source of the function, it looks like the only thing its going to do is return if fail, i.e. invalid connection / NULL pointer. Otherwise, it (seems) to just hang up.

This means yes, you probably should flush the message queue prior to hanging up.

Disclaimer: I've only had to talk to dbus a few times, I'm not by any means an authority on it.

Tim Post
My problem is actually the other way around: I need to close the connection to DBus and make sure I perform the necessary cleanup.
jldupont
@jldupont: Then yes, you should flush the message queue. I'll edit my answer to be more obvious.
Tim Post
@tinkertim: thanks for your effort.
jldupont
A: 

After some more digging, it appears that there are two types of connection: shared and private.

The shared connection mustn't be closed just unreferenced. Furthermore, it does not appear that the connection must be flushed & dispatched unless the outgoing messages must be delivered.

In my case, I just needed to end the communication over DBus as soon as possible without trying to salvage any outgoing messages.

Thus the short answer is: NO - no flushing / no dispatching needs to be done prior to dbus_connection_unref.

jldupont