Signals & threads - low level C API [Newbie question]
hp at redhat.com
Fri Jan 26 11:44:17 PST 2007
Krishna R wrote:
> Do i still need the main loop you are talking about in the above simple
The problem is that there's a lock on the socket. When
read_write_dispatch() blocks, it will hold this lock. That means
dbus_connection_flush() can't acquire it in order to flush.
You can imagine various libdbus fixes to make it smarter about this
situation, but if you don't want to hack on libdbus you probably have to
only call read_write_dispatch() when you know it won't block, which is
normally done with a main loop as Thiago suggests. As a hack you could
also just call dbus_connection_get_socket() and poll()/select() on it
manually in a simple loop.
An even worse hack would be to try and wake up the poll by creating an
EINTR (raise some bogus signal), but I don't know if that will work and
it probably isn't that portable across unix flavors if it does.
Another bad hack would be to put a short timeout on the
read_write_dispatch so it never blocks too long.
More information about the dbus