Running dbus_connection_read_write_dispatch in a separate thread

Alexandru Sorodoc ealex95 at gmail.com
Tue Jun 16 15:06:34 UTC 2020


Hello,

I'm trying to write a daemon that uses libdbus. I create a private 
connection, register a bus and an object path, and then start a thread 
that calls dbus_connection_read_write_dispatch(c, -1) in a loop (as 
described in the documentation).

All works fine, but when I want to shutdown the daemon I call 
dbus_connection_close from the main thread but 
dbus_connection_read_write_dispatch (running in the other thread) never 
returns unless it receives a dbus message.

Is this the expected behaviour? I did disable exiting on disconnect:

     dbus_connection_set_exit_on_disconnect(c, false)

But I expected that dbus_connection_close would close the underlying 
socket and would cause the read_write_dispatch call to return.

The documentation says:
 > The loop terminates when the last message from the connection (the 
disconnected signal) is processed.

But also:
 > Note that, while it is blocked on I/O, it cannot be interrupted (even 
by other threads)

It's not clear to me if dbus_connection_close triggers the "disconnected 
signal" and interrupts the blocking wait or if the "disconnected signal" 
is only checked once before entering the blocking wait.

Also, I did call dbus_threads_init_default before any other libdbus call.

Thanks,
Alex

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20200616/827aedd2/attachment.htm>


More information about the dbus mailing list