Simplest mainloop that could possibly work

Andrew Clunis andrew at
Tue Oct 30 11:44:16 PDT 2007

Hi guys,

I'm trying to put together a simple D-Bus mainloop inside a thread in a
service I'm writing, and using glib/qt isn't really an option.

I had originally intended to use dbus_connection_read_write_dispatch()
function, and have the other thread call
dbus_connection_send()/dbus_connection_flush().  Of course, that's no
good because dbus_connection_read_write_dispatch() blocks on read I/O.
Thus, rather comically, the messages for transmission get buffered and
are only sent once the service happens to *receive* a message.

So, it looks like I have to bite the bullet and write a non-toy
mainloop. I'm having a lot of trouble grokking the Watch/Timeout stuff,
though, and I haven't had much luck finding useful example code.

As far as I understand it, I'm supposed to call
dbus_connection_set_watch_functions() and
dbus_connection_set_timeout_functions().  I'm unclear as to what I
should do once I have a poll() loop running on the FDs, however.

Thanks in advance!

Andrew Clunis

More information about the dbus mailing list