Starting the kdbus discussions

David Zeuthen zeuthen at gmail.com
Mon Jan 20 13:06:53 PST 2014


Hi,

On Sun, Jan 19, 2014 at 2:54 PM, Andrew Cooks <acooks at gmail.com> wrote:
> Could you point me to an example of reasonably well designed code that
> mixes sync and async calls?

Apart from what Alexander said, another common case is when you're
implementing methods in a D-Bus service. If handling the method call
involves a lot of I/O (as they often do), it is often advantageous to
handle the method call in a worker thread so you don't block the GUI
or Network or Service thread. If you're writing a system service with
async authorization such as polkit, this is almost often the case when
you check if the caller is authorized (e.g. it may block on the human
operator authenticating.)

As a concrete example, see the method implementations in the udisks2
D-Bus interfaces

 http://cgit.freedesktop.org/udisks/tree/src
 http://udisks.freedesktop.org/docs/latest/

Note that this pattern is so common that GDBus has native support for
doing this via the HANDLE_METHOD_INVOCATIONS_IN_THREAD flag, see

 https://developer.gnome.org/gio/unstable/GDBusInterfaceSkeleton.html#GDBusInterfaceSkeletonFlags-enum

In my experience, if you're doing more than 1-2 operations,
synchronous I/O in a worker thread really is preferable to
callback-based async I/O. At least, for C-like languages.

     David


More information about the dbus mailing list