Query on operation of dbus_connection_dispatch() and method call

Havoc Pennington havoc.pennington at gmail.com
Mon Mar 23 21:48:41 PDT 2009


Hi,

On Mon, Mar 23, 2009 at 11:44 PM, Soh Kam Yung <sohkamyung at gmail.com> wrote:
> Is it possible for my handler to return DBUS_HANDLER_RESULT_HANDLED to
> the dispatcher, then craft a method reply in a separate thread (to
> allow my mainloop to continue handling more incoming messages)?
>
> I would like to do this:
> 1) dispatcher calls my handler
> 2) handler passes the incoming method call to a separate thread for
> processing and to generate the method reply (which may be slow)
> 3) handler returns DBUS_HANDLER_RESULT_HANDLED to dispatcher
> 4) dispatcher continues handling other incoming mesages

Yes, this should work fine.

Some caveats:

* there are various issues with the thread support in dbus. You might
consider using DBusConnection from just one thread; have your thread
return the reply message to your main loop thread, and then only use
the connection from the main thread.

(Though, I think if someone really just sat down and figured out the
thread issues, they probably aren't that big of a deal to fix.
http://bugs.freedesktop.org/show_bug.cgi?id=857 and other bugs
document some of them.)
(Also, a nonblocking dbus_connection_send() from another thread may
well work fine.)

* the caller or the dbus-daemon may time out the method call
eventually. The dbus-daemon config file can change the daemon timeout.
The caller can specify a timeout when it sends the call.

Havoc


More information about the dbus mailing list