1

Similar Question was asked at DBusWatch and DBusTimeout examples but the reason was not given?

Can anyone please explain, Why to use DBusWatch functions when dbus_connection_read_write_dispatch() can read and write ?

Community
  • 1
  • 1
enthu
  • 69
  • 11

1 Answers1

0

The DBUS documentation for "dbus_connection_read_write_dispatch()" says:

The way to think of this function is that it either makes some sort of progress, or it blocks. Note that, while it is blocked on I/O, it cannot be interrupted (even by other threads), which makes this function unsuitable for applications that do more than just react to received messages.

In a typical real application it needs to handle events from multiple sources. For example it may take keyboard input and convert the input into a database query sent over DBUS. If the program blocks on DBUS event it would not be able to take the keyboard input.

The function itself does not do the read/write, it is the main loop dispatching part of the read/write process.

minghua
  • 5,981
  • 6
  • 45
  • 71
  • If i use a thread for `dbus_connection_read_write_dispatch()`? Will it solve the problem? – abhiarora May 21 '17 at 10:16
  • Yes, but at a cost that you run it in different contexts. Usually an event driven system has one dispatch context and handlers are all in the same context. Now you have to deal the complication of locking. – minghua May 25 '17 at 08:05